Skip to content

Commit

Permalink
[Updater] Replace country_fi, country_sv, and country_en with `…
Browse files Browse the repository at this point in the history
…citizenships` array
  • Loading branch information
valtterikantanen committed Dec 10, 2024
1 parent 597f1f0 commit 3934010
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
11 changes: 3 additions & 8 deletions services/backend/src/models/student.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InferAttributes } from 'sequelize'
import { Column, CreatedAt, DataType, HasMany, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript'

import { Name } from '../shared/types'
import { GenderCode } from '../types'
import { Credit, Enrollment, SISStudyRight, Studyplan } from '.'

Expand Down Expand Up @@ -56,14 +57,8 @@ export class Student extends Model<InferAttributes<Student>> {
@Column(DataType.STRING)
phone_number!: string

@Column(DataType.STRING)
country_fi!: string

@Column(DataType.STRING)
country_sv!: string

@Column(DataType.STRING)
country_en!: string
@Column(DataType.JSONB)
citizenships!: Name[]

@Column(DataType.STRING)
home_country_fi!: string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { STRING } = require('sequelize')

module.exports = {
up: async queryInterface => {
await queryInterface.removeColumn('student', 'country_fi')
await queryInterface.removeColumn('student', 'country_sv')
await queryInterface.removeColumn('student', 'country_en')
},
down: async queryInterface => {
await queryInterface.addColumn('student', 'country_fi', {
type: STRING,
})
await queryInterface.addColumn('student', 'country_sv', {
type: STRING,
})
await queryInterface.addColumn('student', 'country_en', {
type: STRING,
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { JSONB } = require('sequelize')

module.exports = {
up: async queryInterface => {
await queryInterface.addColumn('student', 'citizenships', {
type: JSONB,
defaultValue: [],
})
},
down: async queryInterface => {
await queryInterface.removeColumn('student', 'citizenships')
},
}
6 changes: 2 additions & 4 deletions updater/sis-updater-worker/src/db/models/student.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Model, DATE, INTEGER, STRING, BOOLEAN } = require('sequelize')
const { Model, DATE, INTEGER, STRING, BOOLEAN, JSONB } = require('sequelize')

const { dbConnections } = require('../connection')

Expand All @@ -20,9 +20,7 @@ Student.init(
phone_number: { type: STRING },
secondary_email: { type: STRING },
national_student_number: { type: STRING },
country_fi: { type: STRING },
country_sv: { type: STRING },
country_en: { type: STRING },
citizenships: { type: JSONB },
home_country_fi: { type: STRING },
home_country_sv: { type: STRING },
home_country_en: { type: STRING },
Expand Down
8 changes: 2 additions & 6 deletions updater/sis-updater-worker/src/updater/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ const studentMapper = (attainments, studyRights, attainmentsToBeExluced) => stud

const gender_code = parseGender(gender_urn)

// Country logic should be fixed, see issue:
// https://github.com/UniversityOfHelsinkiCS/oodikone/issues/2958
const country = getCountry(student.country_urn)
const citizenships = (student.citizenships ?? []).map(countryUrn => getCountry(countryUrn).name)
const home_country = student.citizenships ? getCountry(student.citizenships[0]) : null

const studyRightsOfStudent = studyRights.filter(SR => SR.person_id === id)
Expand Down Expand Up @@ -121,9 +119,7 @@ const studentMapper = (attainments, studyRights, attainmentsToBeExluced) => stud
birthdate: date_of_birth,
creditcount: calculateTotalCreditsFromAttainments(attainmentsOfStudent),
dateofuniversityenrollment,
country_fi: country ? country.name.fi : null,
country_sv: country ? country.name.sv : null,
country_en: country ? country.name.en : null,
citizenships,
home_country_fi: home_country ? home_country.name.fi : null,
home_country_sv: home_country ? home_country.name.sv : null,
home_country_en: home_country ? home_country.name.en : null,
Expand Down

0 comments on commit 3934010

Please sign in to comment.