import { z } from "zod"; import mongoose from "mongoose"; import { buildJsonSchemas } from "fastify-zod"; import { pageQueryParams } from "../pagination"; export const alertsModel = mongoose.model( "alert", new mongoose.Schema({ tenantId: String, pid: { type: String, unique: true }, title: { type: String, required: true }, referenceId: String, referenceCollection: String, recipientType: { type: String, required: true, enum: ["user", "team"], }, recipientId: { type: mongoose.Types.ObjectId, required: true }, createdAt: { type: Date, default: Date.now }, readBy: { type: [String], default: [], }, }) ); const alertResponse = z.object({ pid: z.string(), title: z.string(), read: z.boolean(), referenceId: z.string().optional(), referenceCollection: z.string().optional(), recipientType: z.enum(["user", "team"]), createdAt: z.date(), }); const listAlertResponse = z.object({ alerts: z.array(alertResponse), metadata: z.object({ count: z.number(), page: z.number(), pageSize: z.number(), }), }); export const { schemas: alertSchemas, $ref: $alert } = buildJsonSchemas( { alertResponse, listAlertResponse, pageQueryParams, }, { $id: "alert" } );