Skip to content

Commit

Permalink
🚧 begin building out statistical section of application serializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
klondikemarlen committed Aug 8, 2023
1 parent bd454b7 commit 51152ea
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/api/models/language.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// TODO: question whether this should be in the database at all.
// And if so, why is it its own table?
enum Languages {
ENGLISH = 1,
FRENCH = 2,
}

export default class Language {
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 = Languages
}
4 changes: 4 additions & 0 deletions src/api/models/person.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Language from "@/models/language"
import PersonAddress from "@/models/person-address"
import Sex from "@/models/sex"

export default interface Person {
id: number
Expand All @@ -17,4 +19,6 @@ export default interface Person {
telephone?: string
email?: string
addresses?: PersonAddress[]
language?: Language
sex?: Sex
}
31 changes: 31 additions & 0 deletions src/api/models/sex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// TODO: question whether this should be in the database at all.
// And if so, why is it its own table?
enum Sexes {
UNKNOWN = -1,
PREFER_NOT_TO_SAY = 0,
MALE = 1,
FEMALE = 2,
}

export default class Sex {
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 = Sexes
}
17 changes: 15 additions & 2 deletions src/api/serializers/applications-serializer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { compact, isArray, sumBy, uniq } from "lodash"

import { NON_EXISTANT_ID } from "@/utils/constants"

import AddressType from "@/models/address-type"
import Application from "@/models/application"
import CsfaAmounts from "@/models/csfa-amount"
import FundingRequest from "@/models/funding-request"
import FundingSource from "@/models/funding-source"
import Institution from "@/models/institution"
import Language from "@/models/language"
import Person from "@/models/person"
import PersonAddress from "@/models/person-address"

import { NON_EXISTANT_ID } from "@/utils/constants"

export default class ApplicationsSerializer {
#applications: Application[] = []
#application: Application = {} as Application
Expand Down Expand Up @@ -55,6 +56,7 @@ export default class ApplicationsSerializer {
this.#application.primaryAddressId || NON_EXISTANT_ID,
this.#application.student?.person?.addresses || ([] as PersonAddress[])
),
statistical: this.#statisticalSection(this.#application.student?.person || ({} as Person)),
}
}

Expand Down Expand Up @@ -157,4 +159,15 @@ export default class ApplicationsSerializer {
homeAddress2Id: secondaryAddress.id,
}
}

#statisticalSection(person: Person) {
// TODO: replace with real data
return {
language: person.language?.description,
gender: person.sex?.description,
disability: "Permanent",
maritalStatus: 1,
citizenship: 2,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ export default class StudentApplicationStudentsService {
t2Email: "person.email",
t2Telephone: "person.telephone",
t2BirthDate: "person.birthDate",
t3Id: "language.id",
t3Description: "language.description",
t4Id: "sex.id",
t4Description: "sex.description",
})
.from("student")
.innerJoin("person", "person.id", "student.personId")
.innerJoin("language", "language.id", "person.languageId")
.innerJoin("sex", "sex.id", "person.sexId")
.where({ ["student.id"]: this.#studentId })
.first()
.then((result) => {
Expand All @@ -34,6 +40,14 @@ export default class StudentApplicationStudentsService {
email: result.t2Email,
telephone: result.t2Telephone,
birthDate: result.t2BirthDate,
language: {
id: result.t3Id,
description: result.t3Description,
},
sex: {
id: result.t4Id,
description: result.t4Description,
},
},
}
})
Expand Down

0 comments on commit 51152ea

Please sign in to comment.