add notification create route, update permit update rotue

This commit is contained in:
2025-03-27 11:08:49 +05:30
parent 300e67bcb7
commit 3e68d594d2
7 changed files with 70 additions and 4 deletions

View File

@@ -1,7 +1,28 @@
import { FastifyRequest, FastifyReply } from "fastify";
import { PageQueryParams } from "../pagination";
import { listNotifications, updateNotification } from "./notification.service";
import { UpdateNotificationInput } from "./notification.schema";
import {
createNotification,
listNotifications,
updateNotification,
} from "./notification.service";
import {
CreateNotificationInput,
UpdateNotificationInput,
} from "./notification.schema";
export async function createNotificationHandler(
req: FastifyRequest,
res: FastifyReply
) {
const input = req.body as CreateNotificationInput;
try {
const notification = await createNotification(input, req.user.tenantId);
return res.code(201).send(notification);
} catch (err) {
return err;
}
}
export async function listNotificationsHandler(
req: FastifyRequest,

View File

@@ -1,11 +1,24 @@
import { FastifyInstance } from "fastify";
import { $notification } from "./notification.schema";
import {
createNotificationHandler,
listNotificationsHandler,
updateNotificationHandler,
} from "./notification.controller";
export async function notificationRoutes(fastify: FastifyInstance) {
fastify.post(
"/",
{
schema: {
body: $notification("createNotificationInput"),
},
config: { requiredClaims: ["notification:write"] },
preHandler: [fastify.authorize],
},
createNotificationHandler
);
fastify.get(
"/",
{

View File

@@ -1,6 +1,6 @@
import { buildJsonSchemas } from "fastify-zod";
import mongoose from "mongoose";
import { z } from "zod";
import { TypeOf, z } from "zod";
import { pageQueryParams } from "../pagination";
const notificationSchema = new mongoose.Schema({
@@ -31,15 +31,29 @@ export const notificationModel = mongoose.model(
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(),
});
const updateNotificationInput = z.object({
status: z.string(),
});
export type CreateNotificationInput = z.infer<typeof createNotificationInput>;
export type UpdateNotificationInput = z.infer<typeof updateNotificationInput>;
export const { schemas: notificationSchemas, $ref: $notification } =
buildJsonSchemas(
{
createNotificationInput,
updateNotificationInput,
pageQueryParams,
},

View File

@@ -1,10 +1,24 @@
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
import { generateId } from "../utils/id";
import {
CreateNotificationInput,
notificationFields,
notificationModel,
UpdateNotificationInput,
} from "./notification.schema";
export async function createNotification(
input: CreateNotificationInput,
tenantId: string
) {
return await notificationModel.create({
...input,
pid: generateId(),
tenantId: tenantId,
createdAt: new Date(),
});
}
export async function updateNotification(
notifId: string,
input: UpdateNotificationInput,

View File

@@ -133,6 +133,7 @@ const updatePermitInput = z.object({
.nullable()
.optional(),
assignedTo: z.string().optional(),
newPayment: z.array(z.any()),
});
export type CreatePermitInput = z.infer<typeof createPermitInput>;

View File

@@ -156,7 +156,7 @@ export async function updatePermit(
{
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
},
{ ...input, updatedAt: new Date() },
{ ...input, lastUpdateDate: new Date() },
{ new: true }
)
.populate({ path: "county", select: "pid name avatar" })

View File

@@ -31,6 +31,9 @@ export const rules: Record<
"view:read",
"view:write",
"view:delete",
"token:read",
"token:write",
"token:delete",
],
hiddenFields: {
orgs: ["__v"],