Files
permit-api/src/notification/notification.schema.ts

79 lines
2.0 KiB
TypeScript

import { buildJsonSchemas } from "fastify-zod";
import mongoose, { Schema } from "mongoose";
import { z } from "zod";
import { pageQueryParams } from "../pagination";
const notificationSchema = new mongoose.Schema({
pid: {
type: String,
unique: true,
},
permitId: String,
tenantId: String,
permitNumber: String,
link: String,
status: String,
permitType: String,
accelaStatus: String,
changes: Object,
county: {
id: mongoose.Types.ObjectId,
pid: String,
name: String,
avatar: String,
},
client: { type: mongoose.Types.ObjectId, ref: "organization" },
clientData: Object,
createdAt: Date,
updatedAt: Date,
assignedTo: {
type: [Schema.Types.ObjectId],
ref: "user",
},
assignedToOrg: String,
taggedUsers: Array,
taggedOrgs: Array,
});
export const notificationFields = Object.keys(notificationSchema.paths).filter(
(path) => path !== "__v",
);
export const notificationModel = mongoose.model(
"notification",
notificationSchema,
);
const createNotificationInput = z.object({
permitId: z.string(),
permitNumber: z.string(),
link: z.string(),
status: z.string(),
accelaStatus: z.string(),
changes: z.object({}).passthrough(),
county: z.object({}).passthrough(),
client: z.string(),
clientData: z.object({}).passthrough(),
assignedTo: z.array(z.string()).optional(),
assignedToOrg: z.enum(["client", "agent"]).nullable().optional(),
});
const updateNotificationInput = z.object({
status: z.string().optional(),
assignedTo: z.array(z.string()).optional(),
assignedToOrg: z.enum(["client", "agent"]).nullable().optional(),
});
export type CreateNotificationInput = z.infer<typeof createNotificationInput>;
export type UpdateNotificationInput = z.infer<typeof updateNotificationInput>;
export const { schemas: notificationSchemas, $ref: $notification } =
buildJsonSchemas(
{
createNotificationInput,
updateNotificationInput,
pageQueryParams,
},
{ $id: "notification" },
);