permit and processed collection updates
This commit is contained in:
@@ -10,15 +10,10 @@ import {
|
|||||||
} from "./permit.controller";
|
} from "./permit.controller";
|
||||||
import { $permit } from "./permit.schema";
|
import { $permit } from "./permit.schema";
|
||||||
import { hideFields } from "../auth";
|
import { hideFields } from "../auth";
|
||||||
import {
|
|
||||||
createNoteHandler,
|
|
||||||
deleteNoteHandler,
|
|
||||||
listNotesHandler,
|
|
||||||
} from "../note/note.controller";
|
|
||||||
import { noteRoutes } from "../note/note.route";
|
import { noteRoutes } from "../note/note.route";
|
||||||
|
|
||||||
export async function permitRoutes(fastify: FastifyInstance) {
|
export async function permitRoutes(fastify: FastifyInstance) {
|
||||||
fastify.post(
|
/* fastify.post(
|
||||||
"/",
|
"/",
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
@@ -28,7 +23,7 @@ export async function permitRoutes(fastify: FastifyInstance) {
|
|||||||
preHandler: [fastify.authorize],
|
preHandler: [fastify.authorize],
|
||||||
},
|
},
|
||||||
createPermitHandler
|
createPermitHandler
|
||||||
);
|
); */
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/:permitId",
|
"/:permitId",
|
||||||
|
|||||||
@@ -133,7 +133,10 @@ const updatePermitInput = z.object({
|
|||||||
.enum(["Ready To Issue", "Issued", "Invoiced", "Paid", "Closed"])
|
.enum(["Ready To Issue", "Issued", "Invoiced", "Paid", "Closed"])
|
||||||
.nullable()
|
.nullable()
|
||||||
.optional(),
|
.optional(),
|
||||||
utility: z.string().optional(),
|
utility: z
|
||||||
|
.enum(["Submitted", "Pending", "Applied", "Rejected", "Paid"])
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
assignedTo: z.string().optional(),
|
assignedTo: z.string().optional(),
|
||||||
newPayment: z.array(z.any()).optional(),
|
newPayment: z.array(z.any()).optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import {
|
|||||||
getProcessedPermit,
|
getProcessedPermit,
|
||||||
getUniqueValuesProcessed,
|
getUniqueValuesProcessed,
|
||||||
listProcessedPermits,
|
listProcessedPermits,
|
||||||
|
updateProcessed,
|
||||||
} from "./processed.service";
|
} from "./processed.service";
|
||||||
import { $processed } from "./processed.schema";
|
import { $processed, UpdateProcessedInput } from "./processed.schema";
|
||||||
|
|
||||||
export async function processedRoutes(fastify: FastifyInstance) {
|
export async function processedRoutes(fastify: FastifyInstance) {
|
||||||
fastify.get(
|
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(
|
fastify.get(
|
||||||
"/fields/:field",
|
"/fields/:field",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import z from "zod";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { pageQueryParams } from "../pagination";
|
import { pageQueryParams } from "../pagination";
|
||||||
import { buildJsonSchemas } from "fastify-zod";
|
import { buildJsonSchemas } from "fastify-zod";
|
||||||
@@ -74,9 +75,23 @@ export const processedModel = mongoose.model(
|
|||||||
"processed"
|
"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(
|
export const { schemas: processedSchemas, $ref: $processed } = buildJsonSchemas(
|
||||||
{
|
{
|
||||||
pageQueryParams,
|
pageQueryParams,
|
||||||
|
updateProcessedInput,
|
||||||
},
|
},
|
||||||
{ $id: "processed" }
|
{ $id: "processed" }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
|
import { AuthenticatedUser } from "../auth";
|
||||||
import { orgModel } from "../organization/organization.schema";
|
import { orgModel } from "../organization/organization.schema";
|
||||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||||
import { userModel } from "../user/user.schema";
|
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) {
|
export async function getProcessedPermit(permitId: String, tenantId: String) {
|
||||||
return await processedModel.findOne({
|
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(
|
export async function listProcessedPermits(
|
||||||
params: PageQueryParams,
|
params: PageQueryParams,
|
||||||
tenantId: string
|
tenantId: string
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export const rules: Record<
|
|||||||
"user:write",
|
"user:write",
|
||||||
"org:read",
|
"org:read",
|
||||||
"permit:read",
|
"permit:read",
|
||||||
|
"permit:write",
|
||||||
"file:upload",
|
"file:upload",
|
||||||
"file:download",
|
"file:download",
|
||||||
"file:delete",
|
"file:delete",
|
||||||
@@ -78,6 +79,7 @@ export const rules: Record<
|
|||||||
claims: [
|
claims: [
|
||||||
"org:read",
|
"org:read",
|
||||||
"permit:read",
|
"permit:read",
|
||||||
|
"permit:write",
|
||||||
"file:upload",
|
"file:upload",
|
||||||
"file:download",
|
"file:download",
|
||||||
"rts:read",
|
"rts:read",
|
||||||
|
|||||||
Reference in New Issue
Block a user