From f4a6aaab46675fe3084ffd45e594277b7a549fbb Mon Sep 17 00:00:00 2001 From: Akhil Reddy Date: Thu, 6 Feb 2025 15:33:47 +0530 Subject: [PATCH] bug fixes, schema updates --- src/permit/permit.schema.ts | 20 +++++---- src/permit/permit.service.ts | 6 ++- src/rts/rts.schema.ts | 36 +++++++++++++---- src/task/task.schema.ts | 47 +++++++++++++++++++++- src/task/task.service.ts | 4 +- src/utils/pipeline.ts | 78 +++++++++++++++++++++++++++++++++++- 6 files changed, 166 insertions(+), 25 deletions(-) diff --git a/src/permit/permit.schema.ts b/src/permit/permit.schema.ts index 669ca0d..e0be88c 100644 --- a/src/permit/permit.schema.ts +++ b/src/permit/permit.schema.ts @@ -125,17 +125,15 @@ const updatePermitInput = z.object({ permitDate: z.date().optional(), stage: z .object({ - pipeline: z - .array( - z.object({ - name: z.string(), - date: z.date().nullable().optional(), - description: z.string().optional(), - comment: z.string().optional(), - }) - ) - .optional(), - currentStage: z.number().optional(), + pipeline: z.array( + z.object({ + name: z.string(), + date: z.date().nullable().optional(), + description: z.string().optional(), + comment: z.string().optional(), + }) + ), + currentStage: z.number(), }) .optional(), status: z.string().optional(), diff --git a/src/permit/permit.service.ts b/src/permit/permit.service.ts index 9056a92..bc628bf 100644 --- a/src/permit/permit.service.ts +++ b/src/permit/permit.service.ts @@ -9,7 +9,7 @@ import { UpdatePermitInput, } from "./permit.schema"; import { ChangeEvent, dbEvents } from "../realtime"; -import { pipeline } from "../utils/pipeline"; +import { permitPipeline } from "../utils/pipeline"; import { AuthenticatedUser } from "../auth"; export async function createPermit( @@ -18,7 +18,7 @@ export async function createPermit( ) { if (!input.stage) { input.stage = { - pipeline: pipeline, + pipeline: permitPipeline, currentStage: 0, }; } @@ -297,6 +297,8 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) { permitDate: 1, stage: 1, status: 1, + address: 1, + description: 1, county: { $let: { vars: { county: { $arrayElemAt: ["$countyRec", 0] } }, diff --git a/src/rts/rts.schema.ts b/src/rts/rts.schema.ts index e201fa5..9404a9d 100644 --- a/src/rts/rts.schema.ts +++ b/src/rts/rts.schema.ts @@ -33,16 +33,10 @@ const rtsSchema = new mongoose.Schema({ type: mongoose.Types.ObjectId, ref: "organization", }, - statusPipeline: new mongoose.Schema( + stage: new mongoose.Schema( { + pipeline: Array, currentStage: Number, - stages: [ - { - name: String, - date: Date, - description: String, - }, - ], }, { _id: false } ), @@ -63,11 +57,37 @@ const rtsCreateInput = z.object({ county: z.string(), client: z.string().optional(), files: z.array(files).optional(), + stage: z + .object({ + pipeline: z.array( + z.object({ + name: z.string(), + date: z.date().nullable().optional(), + description: z.string().optional(), + comment: z.string().optional(), + }) + ), + currentStage: z.number(), + }) + .optional(), }); const rtsUpdateInput = z.object({ county: z.string().optional(), client: z.string().optional(), + stage: z + .object({ + pipeline: z.array( + z.object({ + name: z.string(), + date: z.date().nullable().optional(), + description: z.string().optional(), + comment: z.string().optional(), + }) + ), + currentStage: z.number(), + }) + .optional(), }); const rtsNewUpload = z.object({ diff --git a/src/task/task.schema.ts b/src/task/task.schema.ts index 7023112..e075518 100644 --- a/src/task/task.schema.ts +++ b/src/task/task.schema.ts @@ -9,7 +9,26 @@ const taskSchema = new mongoose.Schema({ pid: { type: String, required: true, unique: true }, title: String, dueDate: Date, - files: Object, + documents: [ + new mongoose.Schema( + { + files: Array, + createdAt: Date, + createdBy: { + type: mongoose.Types.ObjectId, + ref: "user", + }, + }, + { _id: false } + ), + ], + stage: new mongoose.Schema( + { + pipeline: Array, + currentStage: Number, + }, + { _id: false } + ), createdAt: Date, createdBy: { type: mongoose.Types.ObjectId, @@ -32,6 +51,19 @@ const createTaskInput = z.object({ dueDate: z.date().optional(), files: z.array(files).optional(), assignedTo: z.string().optional(), + stage: z + .object({ + pipeline: z.array( + z.object({ + name: z.string(), + date: z.date().nullable().optional(), + description: z.string().optional(), + comment: z.string().optional(), + }) + ), + currentStage: z.number(), + }) + .optional(), }); const updateTaskInput = z.object({ @@ -39,6 +71,19 @@ const updateTaskInput = z.object({ dueDate: z.date().optional(), files: z.array(files).optional(), assignedTo: z.string().optional(), + stage: z + .object({ + pipeline: z.array( + z.object({ + name: z.string(), + date: z.date().nullable().optional(), + description: z.string().optional(), + comment: z.string().optional(), + }) + ), + currentStage: z.number(), + }) + .optional(), }); export type CreateTaskInput = z.infer; diff --git a/src/task/task.service.ts b/src/task/task.service.ts index 1dcaaee..be1cf86 100644 --- a/src/task/task.service.ts +++ b/src/task/task.service.ts @@ -87,6 +87,8 @@ export async function listTasks(params: PageQueryParams, tenantId: string) { $project: { _id: 1, pid: 1, + title: 1, + dueDate: 1, createdAt: 1, createdBy: { $let: { @@ -98,7 +100,7 @@ export async function listTasks(params: PageQueryParams, tenantId: string) { }, }, }, - client: { + assignedTo: { $let: { vars: { assignedTo: { $arrayElemAt: ["$assignedTo", 0] } }, in: { diff --git a/src/utils/pipeline.ts b/src/utils/pipeline.ts index 546a677..8bf663b 100644 --- a/src/utils/pipeline.ts +++ b/src/utils/pipeline.ts @@ -1,9 +1,11 @@ -export const pipeline: { +type Pipeline = { name: string; date?: Date; description?: string; comment?: string; -}[] = [ +}[]; + +export const permitPipeline: Pipeline = [ { name: "Ready to submit", date: null, @@ -101,3 +103,75 @@ export const pipeline: { comment: "", }, ]; + +export const rtsPipeline: Pipeline = [ + { + name: "Received", + date: null, + description: "", + comment: "", + }, + { + name: "Review", + date: null, + description: "", + comment: "", + }, + { + name: "On Hold", + date: null, + description: "", + comment: "", + }, + { + name: "Submitted", + date: null, + description: "", + comment: "", + }, +]; + +export const taskPipeline: Pipeline = [ + { + name: "To Do", + date: null, + description: "", + comment: "", + }, + { + name: "In Progress", + date: null, + description: "", + comment: "", + }, + { + name: "Awaiting Feedback", + date: null, + description: "", + comment: "", + }, + { + name: "Updates", + date: null, + description: "", + comment: "", + }, + { + name: "Completed", + date: null, + description: "", + comment: "", + }, + { + name: "Parked", + date: null, + description: "", + comment: "", + }, + { + name: "Canceled", + date: null, + description: "", + comment: "", + }, +];