Skip to content

Commit

Permalink
Merge pull request #31 from icefoganalytics/issue-30/add-student-csfa…
Browse files Browse the repository at this point in the history
…-accomodation-section-to-student-application-endpoint-response

Enhancement: Add Student CSFA Accomodation Section to Student Application Endpoint Response
  • Loading branch information
datajohnson authored Aug 16, 2023
2 parents dad3023 + 8f28861 commit dc7ca16
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/api/models/accommodation_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// TODO: question whether this should be in the database at all.
// And if so, why is it its own table?
enum AccommodationTypes {
LIVING_AT_PARENTS = 1,
LIVING_ON_OWN = 2,
BOTH = 3,
}

export default class AccommodationType {
id: number
description: string
isActive: boolean

constructor({
id,
description,
isActive,
}: {
id: number
description: string
isActive: boolean
}) {
this.id = id
this.description = description
this.isActive = isActive
}

// not in database
static readonly Types = AccommodationTypes
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class StudentApplicationsSerializer {
studentDependants: this.#studentDependantsSection(
this.#application.student?.dependents || ([] as Dependent[])
),
csfaAccommodation: this.#csfaAccomodationSection(this.#application),
}
}

Expand Down Expand Up @@ -339,4 +340,39 @@ export default class StudentApplicationsSerializer {
dependants: serializedDependents,
}
}

#csfaAccomodationSection(application: Application) {
const accommodations = []
if (!isNil(application.prestudyAccomCode)) {
accommodations.push({
living: application.prestudyAccomCode,
ownHome: application.prestudyOwnHome,
rentToParents: application.prestudyBoardAmount,
cityId: application.prestudyCityId,
city: application.prestudyCityId,
provinceId: application.prestudyProvinceId,
province: application.prestudyProvinceId,
busService: application.prestudyBus,
distanceFromSchool: application.prestudyDistance, // NOTE: spelling updated from distinct_from_school used in front-end
})
}

if (!isNil(application.studyAccomCode)) {
accommodations.push({
living: application.studyAccomCode,
ownHome: application.studyOwnHome,
rentToParents: application.studyBoardAmount,
cityId: application.studyCityId,
city: application.studyCityId,
provinceId: application.studyProvinceId,
province: application.studyProvinceId,
busService: application.studyBus,
distanceFromSchool: application.studyDistance, // NOTE: spelling updated from distinct_from_school used in front-end
})
}

return {
accommodations // NOTE: spelling updated from accomodations (one m) used in front-end
}
}
}

0 comments on commit dc7ca16

Please sign in to comment.