From bbeb4767518a0e2a097f0e5ec88d93f650e3191d Mon Sep 17 00:00:00 2001 From: Sanchit Rk Date: Fri, 6 Sep 2024 18:55:59 +0530 Subject: [PATCH] fix: gitignore --- .gitignore | 3 +- docker-compose.yml | 4 +- frontend/src/db/init.ts | 0 frontend/src/db/models.ts | 185 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 frontend/src/db/init.ts create mode 100644 frontend/src/db/models.ts diff --git a/.gitignore b/.gitignore index 2442566..284cfbe 100644 --- a/.gitignore +++ b/.gitignore @@ -76,7 +76,8 @@ next-env.d.ts # Local directories and files scratch.txt secrets/ -db/ +pqdb/ redisdb/ bkps/ + .idea/ diff --git a/docker-compose.yml b/docker-compose.yml index 3a07b45..517fddb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: POSTGRES_USER: zygdev POSTGRES_PASSWORD: VeryS3cure volumes: - - db:/var/lib/postgresql/data + - pqdb:/var/lib/postgresql/data ports: - "5432:5432" @@ -21,5 +21,5 @@ services: - redisdb:/data volumes: - db: + pqdb: redisdb: diff --git a/frontend/src/db/init.ts b/frontend/src/db/init.ts new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/db/models.ts b/frontend/src/db/models.ts new file mode 100644 index 0000000..4b32417 --- /dev/null +++ b/frontend/src/db/models.ts @@ -0,0 +1,185 @@ +import { z } from "zod"; +import { + accountResponseSchema, + workspaceResponseSchema, + authMemberResponseSchema, + memberResponseSchema, + patResponseSchema, + customerResponseSchema, + labelResponseSchema, + ThreadResponse, + LabelResponse, + CustomerResponse, + MemberResponse, + PatResponse, +} from "./schema"; + +export type Account = z.infer; + +export type Workspace = z.infer; + +export type AuthMember = z.infer; + +export type Pat = z.infer; + +export type Customer = z.infer; + +export type Label = z.infer; + +export type Member = z.infer; + +export type LabelMetrics = { + labelId: string; + name: string; + icon: string; + count: number; +}; + +export type WorkspaceMetrics = { + active: number; + done: number; + snoozed: number; + assignedToMe: number; + unassigned: number; + otherAssigned: number; + labels: LabelMetrics[] | []; +}; + +export type Thread = { + threadId: string; + customerId: string; + title: string; + description: string; + sequence: number; + status: string; + read: boolean; + replied: boolean; + priority: string; + spam: boolean; + channel: string; + previewText: string; + assigneeId: string | null; + inboundFirstSeqId: string | null; + inboundLastSeqId: string | null; + inboundCustomerId: string | null; + outboundFirstSeqId: string | null; + outboundLastSeqId: string | null; + outboundMemberId: string | null; + createdAt: string; + updatedAt: string; +}; + +export type ThreadChat = { + threadId: string; + chatId: string; + body: string; + sequence: number; + customerId: string | null; + memberId: string | null; + isHead: boolean; + createdAt: string; + updatedAt: string; +}; + +export type Pk = string; + +export function threadTransformer() { + return { + normalize(thread: ThreadResponse): [Pk, Thread] { + const { + threadId, + customer, + assignee, + inboundFirstSeqId, + inboundLastSeqId, + inboundCustomer, + outboundMember, + outboundFirstSeqId, + outboundLastSeqId, + ...rest + } = thread; + const customerId = customer.customerId; + const assigneeId = assignee?.memberId || null; + const inboundCustomerId = inboundCustomer?.customerId || null; + const outboundMemberId = outboundMember?.memberId || null; + return [ + threadId, + { + threadId, + ...rest, + customerId: customerId, + assigneeId: assigneeId, + inboundFirstSeqId: inboundFirstSeqId || null, + inboundLastSeqId: inboundLastSeqId || null, + inboundCustomerId: inboundCustomerId || null, + outboundFirstSeqId: outboundFirstSeqId || null, + outboundLastSeqId: outboundLastSeqId || null, + outboundMemberId: outboundMemberId || null, + }, + ]; + }, + }; +} + +export function labelTransformer() { + return { + normalize(label: LabelResponse): [Pk, Label] { + const { labelId, name, icon, createdAt, updatedAt } = label; + return [ + labelId, + { + labelId, + name, + icon, + createdAt, + updatedAt, + }, + ]; + }, + }; +} + +export function customerTransformer() { + return { + normalize(customer: CustomerResponse): [Pk, Customer] { + const { customerId, ...rest } = customer; + return [ + customerId, + { + customerId, + ...rest, + }, + ]; + }, + }; +} + +export function memberTransformer() { + return { + normalize(member: MemberResponse): [Pk, Member] { + const { memberId, ...rest } = member; + return [ + memberId, + { + memberId, + ...rest, + }, + ]; + }, + }; +} + +export function patTransformer() { + return { + normalize(pat: PatResponse): [Pk, Pat] { + const { patId, ...rest } = pat; + return [ + patId, + { + patId, + ...rest, + }, + ]; + }, + }; +}