Skip to content

Commit

Permalink
✨ Add funding sources (funding_requests) serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
klondikemarlen committed Aug 7, 2023
1 parent 7c549c5 commit d607e73
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/api/serializers/applications-serializer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { isArray } from "lodash"
import { compact, isArray, uniq } from "lodash"

import Application from "@/models/application"
import Institution from "@/models/institution"
import Program from "@/models/program"
import FundingRequest from "@/models/funding-request"

export default class ApplicationsSerializer {
#applications: Application[] = []
#application: Application = {} as Application

constructor(applicationOrApplications: Application[] | Application) {
if (isArray(applicationOrApplications)) {
this.#applications = applicationOrApplications || [] as Application[]
this.#applications = applicationOrApplications || ([] as Application[])
} else {
this.#application = applicationOrApplications || {} as Application
this.#application = applicationOrApplications || ({} as Application)
}
}

Expand All @@ -36,16 +36,21 @@ export default class ApplicationsSerializer {
asDetailedView() {
return {
termsAgree: true,
programDetails: this.#programDetailsField(this.#application),
programDetails: this.#programDetailsSection(this.#application),
fundingSources: this.#fundingRequestsAssocation(
this.#application.fundingRequests || ([] as FundingRequest[])
),
}
}

#programDetailsField(application: Application) {
#programDetailsSection(application: Application) {
return {
attendance: application.attendance?.description,
durationOfProgram: application.programYearTotal, // duplicate of programDuration
endDateOfClasses: application.classesEndDate,
institution: this.#institutionAssociation(this.#application.institution || {} as Institution),
institution: this.#institutionAssociation(
this.#application.institution || ({} as Institution)
),
institutionId: application.institutionCampusId,
program: application.programId,
programDuration: application.programYearTotal, // duplicate of durationOfProgram
Expand All @@ -63,4 +68,14 @@ export default class ApplicationsSerializer {
name: institution.name,
}
}

#fundingRequestsAssocation(fundingRequests: FundingRequest[]) {
const sources = uniq(
compact(fundingRequests.map((fundingRequest) => fundingRequest.requestType?.description))
)
return {
sources,
csfaAmounts: "TODO",
}
}
}

0 comments on commit d607e73

Please sign in to comment.