Skip to content

Commit

Permalink
[Updater] Remove startdate, enddate and latest_instance_date from `Co…
Browse files Browse the repository at this point in the history
…urse` model
  • Loading branch information
valtterikantanen committed Oct 24, 2024
1 parent 8a7426a commit 59cb463
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 56 deletions.
9 changes: 0 additions & 9 deletions services/backend/src/models/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ export class Course extends Model<InferAttributes<Course>> {
@Column(DataType.JSONB)
name!: Name

@Column(DataType.DATE)
latest_instance_date!: Date

@Column(DataType.DATE)
startdate!: Date

@Column(DataType.DATE)
enddate!: Date

@Column(DataType.DATE)
max_attainment_date!: Date

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { DATE } = require('sequelize')

module.exports = {
up: async queryInterface => {
await queryInterface.removeColumn('course', 'startdate')
await queryInterface.removeColumn('course', 'enddate')
await queryInterface.removeColumn('course', 'latest_instance_date')
},
down: async queryInterface => {
await queryInterface.addColumn('course', 'startdate', {
type: DATE,
})
await queryInterface.addColumn('course', 'enddate', {
type: DATE,
})
await queryInterface.addColumn('course', 'latest_instance_date', {
type: DATE,
})
},
}
9 changes: 0 additions & 9 deletions updater/sis-updater-worker/src/db/models/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ Course.init(
name: {
type: JSONB,
},
latest_instance_date: {
type: DATE,
},
is_study_module: {
type: BOOLEAN,
},
coursetypecode: {
type: STRING,
},
startdate: {
type: DATE,
},
enddate: {
type: DATE,
},
max_attainment_date: {
type: DATE,
},
Expand Down
10 changes: 0 additions & 10 deletions updater/sis-updater-worker/src/updater/mapper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { sortBy, flatten, uniqBy } = require('lodash')

const { serviceProvider } = require('../config')
const { getMinMaxDate } = require('../utils')
const { logger } = require('../utils/logger')
const {
educationTypeToExtentcode,
Expand Down Expand Up @@ -251,12 +250,6 @@ const courseMapper = courseIdToAttainments => (groupedCourse, substitutions) =>
const [groupId, courses] = groupedCourse
const { code, name, study_level: coursetypecode, course_unit_type } = courses[0]

const { min: startdate, max: enddate } = getMinMaxDate(
courses,
course => course.validity_period.startDate,
course => course.validity_period.endDate
)

const { min_attainment_date, max_attainment_date } = courses.reduce(
(res, curr) => {
const courseAttainments = courseIdToAttainments[curr.id]
Expand All @@ -282,9 +275,6 @@ const courseMapper = courseIdToAttainments => (groupedCourse, substitutions) =>
coursetypecode,
min_attainment_date,
max_attainment_date,
latest_instance_date: max_attainment_date,
startdate,
enddate,
is_study_module: false, // VALIDATE THIS PLS
substitutions,
course_unit_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ const updateAttainments = async (
id: att.id,
name: att.name,
code: att.code,
latest_instance_date: att.attainment_date,
is_study_module: isModule(att.type),
coursetypecode: att.study_level_urn,
max_attainment_date: att.attainment_date,
Expand All @@ -198,7 +197,6 @@ const updateAttainments = async (
id: parsedCourseCode,
name: att.name,
code: parsedCourseCode,
latest_instance_date: att.attainment_date,
is_study_module: isModule(att.type),
coursetypecode: att.study_level_urn,
max_attainment_date: att.attainment_date,
Expand Down
26 changes: 0 additions & 26 deletions updater/sis-updater-worker/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,9 @@ const isActive = entity => {
const isBaMa = education =>
education.education_type === 'urn:code:education-type:degree-education:bachelors-and-masters-degree'

const getMinMaxDate = (arr, fMax, fMin) => {
let maxVal = null
let max = -Infinity
let minVal = null
let min = Infinity

arr.forEach(i => {
const ma = fMax(i)
const mi = fMin(i)

const maVal = new Date(ma).getTime()
const miVal = new Date(mi).getTime()
if (maVal > max) {
max = maVal
maxVal = ma
}
if (miVal < min) {
min = miVal
minVal = mi
}
})

return { max: maxVal, min: minVal }
}

module.exports = {
getLatestSnapshot,
isActive,
getMinMaxDate,
isBaMa,
getActiveSnapshot,
}

0 comments on commit 59cb463

Please sign in to comment.