Skip to content

Commit

Permalink
Merge pull request #176 from icefoganalytics/test
Browse files Browse the repository at this point in the history
Portal fixes and cslpt
  • Loading branch information
datajohnson authored Oct 11, 2023
2 parents 139fa08 + af2db13 commit 24a1fdd
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app.use(
"block-all-mixed-content": [],
"font-src": ["'self'", "https:", "data:"],
"frame-ancestors": ["'self'"],
"img-src": ["'self'", "data:", "https:"],
"img-src": ["'self'", "data:", "https:", "http:"],
"object-src": ["'none'"],
"script-src": ["'self'", "'unsafe-eval'"], // added https to accomodate esri components?
"script-src-attr": ["'none'"],
Expand Down
17 changes: 11 additions & 6 deletions src/api/models/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ export function FundingFromDraft(draft: any): any[] {
if (draft.funding_sources && draft.funding_sources.sources) {
for (let source of draft.funding_sources.sources) {
let application_type_id = 1;
let csfa_amounts = draft.funding_sources.csfa_amounts || "";
let loan_amount = draft.funding_sources.csfa_loan_amount;
let yea_request_amount = draft.funding_sources.yea_amount;
let csfa_amounts = draft.funding_sources.csfa_amounts ?? "";
let loan_amount = draft.funding_sources.csfa_loan_amount ?? 0;
let yea_request_amount = draft.funding_sources.yea_amount ?? 0;

if (source == "Canada Student Financial Assistance (Full-Time)") application_type_id = 2;
else if (source == "Canada Student Financial Assistance (Part-Time)") application_type_id = 3;
Expand Down Expand Up @@ -600,7 +600,7 @@ export function FundingFromDraft(draft: any): any[] {
csl_request_amount: application_type_id == 2 ? cleanNumber(loan_amount) : 0,
is_csl_full_amount: application_type_id == 2 && csfa_amounts == "Full amount loans and grants",
is_csg_only: csfa_amounts == "Grants only",
yea_request_amount,
yea_request_amount: cleanNumber(yea_request_amount),
});
}
}
Expand Down Expand Up @@ -645,8 +645,13 @@ export function StudentFromDraft(draft: any): any {
studentUpdate.high_school_id = educations[0].school;
}

studentUpdate.high_school_left_year = parseInt(educations[0].left_high_school.split("/")[0]);
studentUpdate.high_school_left_month = parseInt(educations[0].left_high_school.split("/")[1]);
try {
studentUpdate.high_school_left_year = parseInt(educations[0].left_high_school.split("/")[0]);
studentUpdate.high_school_left_month = parseInt(educations[0].left_high_school.split("/")[1]);
} catch (err) {
console.log("ERROR PARSING educations[0].left_high_school", educations[0]);
}

studentUpdate.is_crown_ward = draft.statistical.crown_ward;

if (!isInteger(studentUpdate.high_school_id)) {
Expand Down
10 changes: 7 additions & 3 deletions src/api/routes/admin/csl-certificate-audit-report-router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express, { Request, Response } from "express";
import knex from "knex";
import { param } from "express-validator";
import { DB_CONFIG } from "../../config";
import { DB_CONFIG, FRONTEND_URL } from "../../config";
import { renderReportAsHtml, renderReportAsPdf } from "@/utils/express-handlebars-pdf-client";
import moment from "moment";

Expand All @@ -22,7 +22,7 @@ cslCertificateAuditReportRouter.get(
try {
let notSentData = await db.raw(`SELECT d.transaction_number cert_num, m.id msfaa_num, m.received_date,
CONCAT(p.first_name,' ', p.last_name) [name], rt.description request_type, d.issue_date,
d.due_date, d.disbursed_amount * 100 amount, d.csl_cert_seq_number seq
d.due_date, COALESCE(d.disbursed_amount, 0.00) * 100 amount, d.csl_cert_seq_number seq
FROM sfa.disbursement d
INNER JOIN sfa.funding_request fr ON (fr.id = d.funding_request_id)
INNER JOIN sfa.request_type rt ON (rt.id = fr.request_type_id)
Expand All @@ -38,7 +38,7 @@ cslCertificateAuditReportRouter.get(

let sentData = await db.raw(`SELECT d.transaction_number cert_num, m.id msfaa_num, m.received_date,
CONCAT(p.first_name,' ', p.last_name) [name], rt.description request_type, d.issue_date,
d.due_date, d.disbursed_amount * 100 amount, d.csl_cert_seq_number seq
d.due_date, COALESCE(d.disbursed_amount, 0.00) * 100 amount, d.csl_cert_seq_number seq
FROM sfa.disbursement d
INNER JOIN sfa.funding_request fr ON (fr.id = d.funding_request_id)
INNER JOIN sfa.request_type rt ON (rt.id = fr.request_type_id)
Expand Down Expand Up @@ -69,6 +69,10 @@ cslCertificateAuditReportRouter.get(
}

let html = await renderReportAsHtml(TEMPLATE_PATH, data);

// fix the image locations (likely just the Yukon Logo.png)
html = html.replace("http://localhost:3000", FRONTEND_URL);

res.send(html);
} catch (error: any) {
console.log(error);
Expand Down
29 changes: 20 additions & 9 deletions src/api/routes/portal/application-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ portalApplicationRouter.get("/:sub/:draftId/required-documents", async (req: Req
for (let doc of returnDocs) {
doc.meets_conditions = true;

// if (doc.condition) console.log(doc, doc.condition);
// if (doc.condition) console.log(doc, doc.condition);

switch (doc.condition) {
case "CSL Only":
Expand Down Expand Up @@ -266,17 +266,28 @@ portalApplicationRouter.put("/:sub/:draftId/submit", async (req: Request, res: R
let appIds = applications.map((a) => a.id);

if (appIds.includes(parseInt(draftId))) {
let application = await applicationService.submitDraft(student, parseInt(draftId));

if (application) {
let draftDocs = await documentService.getDocumentsForDraft(parseInt(draftId));
documentService.draftToApplication(parseInt(draftId), application.id);
await applicationService
.submitDraft(student, parseInt(draftId))
.then(async (application) => {
if (application && application.id) {
await documentService.getDocumentsForDraft(parseInt(draftId));
documentService.draftToApplication(parseInt(draftId), application?.id);

return res.json({ data: application });
} else {
console.log("Application created, but returned empty", application);
}
})
.catch((err) => {
console.log("Error Submitting Application:", err);
return res.json({ error: err });
});

return res.json({ data: application });
}
return;
}
}
res.status(404);

res.status(404).send("Not found");
});

// deletes a draft application
Expand Down
Loading

0 comments on commit 24a1fdd

Please sign in to comment.