From bb5ffd4ec8b817277e4a2417e5e150b3d65bf83e Mon Sep 17 00:00:00 2001 From: qhanson55 Date: Thu, 28 Nov 2024 17:31:32 -0800 Subject: [PATCH] Created permit status view to replace the modal --- app/src/controllers/permit.ts | 14 + app/src/db/models/permit.ts | 4 +- app/src/docs/v1.api-spec.yaml | 29 + app/src/routes/v1/permit.ts | 12 + app/src/services/permit.ts | 7 +- app/src/types/Permit.ts | 2 + app/src/validators/permit.ts | 6 + frontend/src/components/common/Breadcrumb.vue | 5 +- .../housing/projects/ProjectStatus.vue | 104 ---- .../PermitEnquiryModal.vue} | 119 ++-- .../src/components/permit/PermitModal.vue | 18 +- frontend/src/router/index.ts | 10 + frontend/src/services/permitService.ts | 8 + frontend/src/utils/enums/application.ts | 1 + .../src/views/housing/project/ProjectView.vue | 124 ++--- .../src/views/permit/PermitStatusView.vue | 508 ++++++++++++++++++ 16 files changed, 713 insertions(+), 258 deletions(-) delete mode 100644 frontend/src/components/housing/projects/ProjectStatus.vue rename frontend/src/components/{housing/projects/ProjectPermitModal.vue => permit/PermitEnquiryModal.vue} (55%) create mode 100644 frontend/src/views/permit/PermitStatusView.vue diff --git a/app/src/controllers/permit.ts b/app/src/controllers/permit.ts index ca173d37..26e2b489 100644 --- a/app/src/controllers/permit.ts +++ b/app/src/controllers/permit.ts @@ -33,6 +33,20 @@ const controller = { } }, + getPermit: async (req: Request<{ permitId: string }>, res: Response, next: NextFunction) => { + try { + const response = await permitService.getPermit(req.params.permitId); + + if (!response) { + return res.status(404).json({ message: 'Permit not found' }); + } + + res.status(200).json(response); + } catch (e: unknown) { + next(e); + } + }, + getPermitTypes: async (req: Request, res: Response, next: NextFunction) => { try { const response = await permitService.getPermitTypes(); diff --git a/app/src/db/models/permit.ts b/app/src/db/models/permit.ts index b570844b..f015ed14 100644 --- a/app/src/db/models/permit.ts +++ b/app/src/db/models/permit.ts @@ -1,6 +1,7 @@ import { Prisma } from '@prisma/client'; import permit_note from './permit_note'; +import permit_type from './permit_type'; import type { Stamps } from '../stamps'; import type { Permit } from '../../types'; @@ -47,7 +48,8 @@ export default { adjudicationDate: input.adjudication_date?.toISOString() ?? null, statusLastVerified: input.status_last_verified?.toISOString() ?? null, updatedAt: input.updated_at?.toISOString() ?? null, - updatedBy: input.updated_by + updatedBy: input.updated_by, + permitType: permit_type.fromPrismaModel(input.permit_type) }; }, diff --git a/app/src/docs/v1.api-spec.yaml b/app/src/docs/v1.api-spec.yaml index 3df6f921..f9652225 100644 --- a/app/src/docs/v1.api-spec.yaml +++ b/app/src/docs/v1.api-spec.yaml @@ -491,6 +491,35 @@ paths: default: $ref: '#/components/responses/Error' /permit/{permitId}: + get: + summary: Get a permit + operationId: getPermit + tags: + - Permit + parameters: + - in: path + name: permitId + required: true + schema: + type: string + description: The ID of the permit to update + responses: + '200': + description: Permit updated successfully + content: + application/json: + schema: + $ref: '#/components/schemas/DB-Permit' + "401": + $ref: "#/components/responses/Unauthorized" + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + "422": + $ref: "#/components/responses/UnprocessableEntity" + default: + $ref: '#/components/responses/Error' put: summary: Update a permit operationId: updatePermit diff --git a/app/src/routes/v1/permit.ts b/app/src/routes/v1/permit.ts index a265c42e..2b464924 100644 --- a/app/src/routes/v1/permit.ts +++ b/app/src/routes/v1/permit.ts @@ -67,4 +67,16 @@ router.get( } ); +// This is placed at bottom as it conflicts with the /permit/types endpoint +// Permit get endpoint +router.get( + '/:permitId', + hasAuthorization(Resource.PERMIT, Action.READ), + hasAccess('permitId'), + permitValidator.getPermit, + (req: Request<{ permitId: string }>, res: Response, next: NextFunction): void => { + permitController.getPermit(req, res, next); + } +); + export default router; diff --git a/app/src/services/permit.ts b/app/src/services/permit.ts index 6c0d6612..bb33ba11 100644 --- a/app/src/services/permit.ts +++ b/app/src/services/permit.ts @@ -68,7 +68,7 @@ const service = { * @function getPermit * Get a permit * @param {string} permitId Permit ID - * @returns {Promise} The result of running the findFirst operation + * @returns {Promise} The result of running the findFirst operation */ getPermit: async (permitId: string) => { const result = await prisma.permit.findFirst({ @@ -76,11 +76,12 @@ const service = { permit_id: permitId }, include: { - permit_type: true + permit_type: true, + permit_note: { orderBy: { created_at: 'desc' } } } }); - return result ? permit.fromPrismaModel(result) : null; + return result ? permit.fromPrismaModelWithNotes(result) : null; }, /** diff --git a/app/src/types/Permit.ts b/app/src/types/Permit.ts index 667cd2ee..0867f0a1 100644 --- a/app/src/types/Permit.ts +++ b/app/src/types/Permit.ts @@ -1,5 +1,6 @@ import { IStamps } from '../interfaces/IStamps'; import { PermitNote } from './PermitNote'; +import { PermitType } from './PermitType'; export type Permit = { permitId: string; // Primary Key @@ -14,4 +15,5 @@ export type Permit = { adjudicationDate: string | null; statusLastVerified: string | null; permitNote?: Array; + permitType?: PermitType; } & Partial; diff --git a/app/src/validators/permit.ts b/app/src/validators/permit.ts index 861b0396..e87cb4d4 100644 --- a/app/src/validators/permit.ts +++ b/app/src/validators/permit.ts @@ -27,6 +27,11 @@ const schema = { permitId: uuidv4.required() }) }, + getPermit: { + params: Joi.object({ + permitId: uuidv4.required() + }) + }, listPermits: { query: Joi.object({ activityId: Joi.string().min(8).max(8).allow(null), @@ -47,6 +52,7 @@ const schema = { export default { createPermit: validate(schema.createPermit), deletePermit: validate(schema.deletePermit), + getPermit: validate(schema.getPermit), listPermits: validate(schema.listPermits), updatePermit: validate(schema.updatePermit) }; diff --git a/frontend/src/components/common/Breadcrumb.vue b/frontend/src/components/common/Breadcrumb.vue index 86f5db70..19daaad6 100644 --- a/frontend/src/components/common/Breadcrumb.vue +++ b/frontend/src/components/common/Breadcrumb.vue @@ -19,7 +19,10 @@ const { home, model } = defineProps<{