Skip to content

Commit

Permalink
Merge pull request #316 from icefoganalytics/test
Browse files Browse the repository at this point in the history
Uploads from portal for submitted apps
  • Loading branch information
datajohnson authored Nov 14, 2024
2 parents 904f892 + 2ece68d commit c1d2f9c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/api/routes/portal/application-router.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/api/routes/portal/reference-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
});
8 changes: 8 additions & 0 deletions src/api/services/portal/reference-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ export class ReferenceService {
.where({ status: "Open", is_open_in_portal: true })
.select(["id", "start_date", "end_date"]);
}

async getRequirementTypes(): Promise<any[]> {
return db("requirement_type")
.withSchema(schema)
.where({ is_active: 1, show_online: 1 })
.select(["id", "description"])
.orderBy("description");
}
}
1 change: 1 addition & 0 deletions src/api/services/shared/document-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export enum DocumentStatus {
APPROVED = 2,
REJECTED = 3,
REPLACED = 4,
REVIEW = 5,
}

export enum DocumentSource {
Expand Down

0 comments on commit c1d2f9c

Please sign in to comment.