From 2ece68ddda72a7dac3c0f4b3f5ecb8f3bf3a93be Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Wed, 13 Nov 2024 17:11:16 -0700 Subject: [PATCH] Uploads from portal for submitted apps --- src/api/routes/portal/application-router.ts | 44 +++++++++++++++++++- src/api/routes/portal/reference-router.ts | 4 ++ src/api/services/portal/reference-service.ts | 8 ++++ src/api/services/shared/document-service.ts | 1 + 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/api/routes/portal/application-router.ts b/src/api/routes/portal/application-router.ts index 0ced0a49..f0b653e8 100644 --- a/src/api/routes/portal/application-router.ts +++ b/src/api/routes/portal/application-router.ts @@ -1,7 +1,7 @@ import express, { Request, Response } from "express"; import { PortalApplicationService, PortalStudentService } from "../../services/portal"; import StudentApplicationsService from "@/services/portal/students/student-applications-service"; -import { DocumentService, DocumentationService } from "../../services/shared"; +import { DocumentService, DocumentStatus, DocumentationService } from "../../services/shared"; import { isArray } from "lodash"; import { ReferenceService } from "@/services/portal/reference-service"; @@ -146,6 +146,48 @@ portalApplicationRouter.post("/:sub/:draftId/upload", async (req: Request, res: res.json({ error: "No files included in request" }); }); +//uploads a document to an application +portalApplicationRouter.post("/:sub/application/:applicationId/upload", async (req: Request, res: Response) => { + const { sub, applicationId } = req.params; + const { requirement_type_id, disability_requirement_id, person_id, dependent_id, mimetype, comment } = req.body; + let student = await studentService.getBySub(sub); + + if (student) { + let applications = await applicationService.getApplicationsForStudent(student.id); + let appIds = applications.map((a) => a.id); + + if (appIds.includes(parseInt(applicationId))) { + let email = student.email; + + console.log("req.files", req.files); + + if (req.files) { + let file = isArray(req.files.file) ? req.files.file[0] : req.files.file; + file.mimetype = mimetype; + + await documentService.uploadApplicationDocument({ + email, + student_id: student.id, + application_id: parseInt(applicationId), + file, + requirement_type_id, + disability_requirement_id, + person_id, + dependent_id, + source: "Portal", + comment, + status: DocumentStatus.REVIEW, + visible_in_portal: true, + }); + + return res.json({ message: "success" }); + } + } + } + + res.json({ error: "No files included in request" }); +}); + // downloads a document portalApplicationRouter.get("/:sub/:draftId/files/:key", async (req: Request, res: Response) => { const { sub, draftId, key } = req.params; diff --git a/src/api/routes/portal/reference-router.ts b/src/api/routes/portal/reference-router.ts index a5723394..73f9d769 100644 --- a/src/api/routes/portal/reference-router.ts +++ b/src/api/routes/portal/reference-router.ts @@ -77,3 +77,7 @@ portalReferenceRouter.get("/expense-category", async (req: Request, res: Respons portalReferenceRouter.get("/academic-year", async (req: Request, res: Response) => { res.json({ data: await db.getAcademicYears() }); }); + +portalReferenceRouter.get("/requirement_type", async (req: Request, res: Response) => { + res.json({ data: await db.getRequirementTypes() }); +}); \ No newline at end of file diff --git a/src/api/services/portal/reference-service.ts b/src/api/services/portal/reference-service.ts index 406079e0..7c4f8567 100644 --- a/src/api/services/portal/reference-service.ts +++ b/src/api/services/portal/reference-service.ts @@ -148,4 +148,12 @@ export class ReferenceService { .where({ status: "Open", is_open_in_portal: true }) .select(["id", "start_date", "end_date"]); } + + async getRequirementTypes(): Promise { + return db("requirement_type") + .withSchema(schema) + .where({ is_active: 1, show_online: 1 }) + .select(["id", "description"]) + .orderBy("description"); + } } diff --git a/src/api/services/shared/document-service.ts b/src/api/services/shared/document-service.ts index 10d37a99..bc5dd0e7 100644 --- a/src/api/services/shared/document-service.ts +++ b/src/api/services/shared/document-service.ts @@ -349,6 +349,7 @@ export enum DocumentStatus { APPROVED = 2, REJECTED = 3, REPLACED = 4, + REVIEW = 5, } export enum DocumentSource {