add notification create route, update permit update rotue
This commit is contained in:
@@ -1,7 +1,28 @@
|
|||||||
import { FastifyRequest, FastifyReply } from "fastify";
|
import { FastifyRequest, FastifyReply } from "fastify";
|
||||||
import { PageQueryParams } from "../pagination";
|
import { PageQueryParams } from "../pagination";
|
||||||
import { listNotifications, updateNotification } from "./notification.service";
|
import {
|
||||||
import { UpdateNotificationInput } from "./notification.schema";
|
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(
|
export async function listNotificationsHandler(
|
||||||
req: FastifyRequest,
|
req: FastifyRequest,
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
import { FastifyInstance } from "fastify";
|
import { FastifyInstance } from "fastify";
|
||||||
import { $notification } from "./notification.schema";
|
import { $notification } from "./notification.schema";
|
||||||
import {
|
import {
|
||||||
|
createNotificationHandler,
|
||||||
listNotificationsHandler,
|
listNotificationsHandler,
|
||||||
updateNotificationHandler,
|
updateNotificationHandler,
|
||||||
} from "./notification.controller";
|
} from "./notification.controller";
|
||||||
|
|
||||||
export async function notificationRoutes(fastify: FastifyInstance) {
|
export async function notificationRoutes(fastify: FastifyInstance) {
|
||||||
|
fastify.post(
|
||||||
|
"/",
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
body: $notification("createNotificationInput"),
|
||||||
|
},
|
||||||
|
config: { requiredClaims: ["notification:write"] },
|
||||||
|
preHandler: [fastify.authorize],
|
||||||
|
},
|
||||||
|
createNotificationHandler
|
||||||
|
);
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/",
|
"/",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { buildJsonSchemas } from "fastify-zod";
|
import { buildJsonSchemas } from "fastify-zod";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { z } from "zod";
|
import { TypeOf, z } from "zod";
|
||||||
import { pageQueryParams } from "../pagination";
|
import { pageQueryParams } from "../pagination";
|
||||||
|
|
||||||
const notificationSchema = new mongoose.Schema({
|
const notificationSchema = new mongoose.Schema({
|
||||||
@@ -31,15 +31,29 @@ export const notificationModel = mongoose.model(
|
|||||||
notificationSchema
|
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({
|
const updateNotificationInput = z.object({
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type CreateNotificationInput = z.infer<typeof createNotificationInput>;
|
||||||
export type UpdateNotificationInput = z.infer<typeof updateNotificationInput>;
|
export type UpdateNotificationInput = z.infer<typeof updateNotificationInput>;
|
||||||
|
|
||||||
export const { schemas: notificationSchemas, $ref: $notification } =
|
export const { schemas: notificationSchemas, $ref: $notification } =
|
||||||
buildJsonSchemas(
|
buildJsonSchemas(
|
||||||
{
|
{
|
||||||
|
createNotificationInput,
|
||||||
updateNotificationInput,
|
updateNotificationInput,
|
||||||
pageQueryParams,
|
pageQueryParams,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||||
|
import { generateId } from "../utils/id";
|
||||||
import {
|
import {
|
||||||
|
CreateNotificationInput,
|
||||||
notificationFields,
|
notificationFields,
|
||||||
notificationModel,
|
notificationModel,
|
||||||
UpdateNotificationInput,
|
UpdateNotificationInput,
|
||||||
} from "./notification.schema";
|
} 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(
|
export async function updateNotification(
|
||||||
notifId: string,
|
notifId: string,
|
||||||
input: UpdateNotificationInput,
|
input: UpdateNotificationInput,
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ const updatePermitInput = z.object({
|
|||||||
.nullable()
|
.nullable()
|
||||||
.optional(),
|
.optional(),
|
||||||
assignedTo: z.string().optional(),
|
assignedTo: z.string().optional(),
|
||||||
|
newPayment: z.array(z.any()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type CreatePermitInput = z.infer<typeof createPermitInput>;
|
export type CreatePermitInput = z.infer<typeof createPermitInput>;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export async function updatePermit(
|
|||||||
{
|
{
|
||||||
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
||||||
},
|
},
|
||||||
{ ...input, updatedAt: new Date() },
|
{ ...input, lastUpdateDate: new Date() },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
)
|
)
|
||||||
.populate({ path: "county", select: "pid name avatar" })
|
.populate({ path: "county", select: "pid name avatar" })
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ export const rules: Record<
|
|||||||
"view:read",
|
"view:read",
|
||||||
"view:write",
|
"view:write",
|
||||||
"view:delete",
|
"view:delete",
|
||||||
|
"token:read",
|
||||||
|
"token:write",
|
||||||
|
"token:delete",
|
||||||
],
|
],
|
||||||
hiddenFields: {
|
hiddenFields: {
|
||||||
orgs: ["__v"],
|
orgs: ["__v"],
|
||||||
|
|||||||
Reference in New Issue
Block a user