permit and processed collection updates
This commit is contained in:
@@ -10,15 +10,10 @@ import {
|
||||
} from "./permit.controller";
|
||||
import { $permit } from "./permit.schema";
|
||||
import { hideFields } from "../auth";
|
||||
import {
|
||||
createNoteHandler,
|
||||
deleteNoteHandler,
|
||||
listNotesHandler,
|
||||
} from "../note/note.controller";
|
||||
import { noteRoutes } from "../note/note.route";
|
||||
|
||||
export async function permitRoutes(fastify: FastifyInstance) {
|
||||
fastify.post(
|
||||
/* fastify.post(
|
||||
"/",
|
||||
{
|
||||
schema: {
|
||||
@@ -28,7 +23,7 @@ export async function permitRoutes(fastify: FastifyInstance) {
|
||||
preHandler: [fastify.authorize],
|
||||
},
|
||||
createPermitHandler
|
||||
);
|
||||
); */
|
||||
|
||||
fastify.get(
|
||||
"/:permitId",
|
||||
|
||||
@@ -133,7 +133,10 @@ const updatePermitInput = z.object({
|
||||
.enum(["Ready To Issue", "Issued", "Invoiced", "Paid", "Closed"])
|
||||
.nullable()
|
||||
.optional(),
|
||||
utility: z.string().optional(),
|
||||
utility: z
|
||||
.enum(["Submitted", "Pending", "Applied", "Rejected", "Paid"])
|
||||
.nullable()
|
||||
.optional(),
|
||||
assignedTo: z.string().optional(),
|
||||
newPayment: z.array(z.any()).optional(),
|
||||
});
|
||||
|
||||
@@ -4,8 +4,9 @@ import {
|
||||
getProcessedPermit,
|
||||
getUniqueValuesProcessed,
|
||||
listProcessedPermits,
|
||||
updateProcessed,
|
||||
} from "./processed.service";
|
||||
import { $processed } from "./processed.schema";
|
||||
import { $processed, UpdateProcessedInput } from "./processed.schema";
|
||||
|
||||
export async function processedRoutes(fastify: FastifyInstance) {
|
||||
fastify.get(
|
||||
@@ -74,6 +75,32 @@ export async function processedRoutes(fastify: FastifyInstance) {
|
||||
}
|
||||
);
|
||||
|
||||
fastify.patch(
|
||||
"/:permitId",
|
||||
{
|
||||
schema: {
|
||||
params: {
|
||||
type: "object",
|
||||
properties: { permitId: { type: "string" } },
|
||||
},
|
||||
body: $processed("updateProcessedInput"),
|
||||
},
|
||||
config: { requiredClaims: ["permit:write"] },
|
||||
preHandler: [fastify.authorize],
|
||||
},
|
||||
async (req: FastifyRequest, res: FastifyReply) => {
|
||||
const { permitId } = req.params as { permitId: string };
|
||||
const input = req.body as UpdateProcessedInput;
|
||||
|
||||
try {
|
||||
const permit = await updateProcessed(input, permitId, req.user);
|
||||
return res.code(200).send(permit);
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
"/fields/:field",
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import z from "zod";
|
||||
import mongoose from "mongoose";
|
||||
import { pageQueryParams } from "../pagination";
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
@@ -74,9 +75,23 @@ export const processedModel = mongoose.model(
|
||||
"processed"
|
||||
);
|
||||
|
||||
const updateProcessedInput = z.object({
|
||||
manualStatus: z
|
||||
.enum(["Ready To Issue", "Issued", "Invoiced", "Paid", "Closed"])
|
||||
.nullable()
|
||||
.optional(),
|
||||
utility: z
|
||||
.enum(["Submitted", "Pending", "Applied", "Rejected", "Paid"])
|
||||
.nullable()
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type UpdateProcessedInput = z.infer<typeof updateProcessedInput>;
|
||||
|
||||
export const { schemas: processedSchemas, $ref: $processed } = buildJsonSchemas(
|
||||
{
|
||||
pageQueryParams,
|
||||
updateProcessedInput,
|
||||
},
|
||||
{ $id: "processed" }
|
||||
);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { AuthenticatedUser } from "../auth";
|
||||
import { orgModel } from "../organization/organization.schema";
|
||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||
import { userModel } from "../user/user.schema";
|
||||
import { processedFields, processedModel } from "./processed.schema";
|
||||
import {
|
||||
processedFields,
|
||||
processedModel,
|
||||
UpdateProcessedInput,
|
||||
} from "./processed.schema";
|
||||
|
||||
export async function getProcessedPermit(permitId: String, tenantId: String) {
|
||||
return await processedModel.findOne({
|
||||
@@ -9,6 +14,25 @@ export async function getProcessedPermit(permitId: String, tenantId: String) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateProcessed(
|
||||
input: UpdateProcessedInput,
|
||||
permitId: string,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
return await processedModel
|
||||
.findOneAndUpdate(
|
||||
{
|
||||
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
||||
},
|
||||
{ ...input, lastUpdateDate: new Date() },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
}
|
||||
|
||||
export async function listProcessedPermits(
|
||||
params: PageQueryParams,
|
||||
tenantId: string
|
||||
|
||||
@@ -48,6 +48,7 @@ export const rules: Record<
|
||||
"user:write",
|
||||
"org:read",
|
||||
"permit:read",
|
||||
"permit:write",
|
||||
"file:upload",
|
||||
"file:download",
|
||||
"file:delete",
|
||||
@@ -78,6 +79,7 @@ export const rules: Record<
|
||||
claims: [
|
||||
"org:read",
|
||||
"permit:read",
|
||||
"permit:write",
|
||||
"file:upload",
|
||||
"file:download",
|
||||
"rts:read",
|
||||
|
||||
Reference in New Issue
Block a user