Skip to content

Commit

Permalink
cli reclaimer
Browse files Browse the repository at this point in the history
  • Loading branch information
mluukkai committed Feb 2, 2024
1 parent fdb09e9 commit f55762d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class User extends Model {
return Math.floor(credits)
}

async checkEligibility() {
async checkEligibility(inBeta = false) {
const settings = await ServiceStatus.getObject()
const studyrights = await this.getStudyRights()
const semesterEnrollments = await this.getSemesterEnrollments()
Expand All @@ -188,7 +188,7 @@ class User extends Model {
enrollment.semester_code === settings.currentSemester && enrollment.semester_enrollment_type_code === 1))

// Magic number for limit of extended delivery
const notTooOld = new Date(firstStartDate).getFullYear() >= 2019
const notTooOld = inBeta && new Date(firstStartDate).getFullYear() >= 2019

return {
eligible: (!hasPreviousStudyright && hasNewStudyright && isPresent && hasValidBachelorsStudyright),
Expand Down Expand Up @@ -242,11 +242,11 @@ class User extends Model {
}
}

async checkAndUpdateEligibility() {
async checkAndUpdateEligibility(inBeta = false) {
try {
const settings = await ServiceStatus.getObject()

const { eligible, eligibilityReasons, extendedEligible } = await this.checkEligibility()
const { eligible, eligibilityReasons, extendedEligible } = await this.checkEligibility(inBeta)

if (eligible) {
await this.createUserStudyprograms()
Expand Down
6 changes: 6 additions & 0 deletions server/services/updaterService.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ const reclaimYear = async (signup_year) => {
// logger.info(`Checking reclaim status for ${deviceHolders.length} students, year ${currentYear}`)
}

const reclaimForYear = async (year) => {
console.log('reclaiming', year)
await reclaimYear(year)
}

const runReclaimStatusUpdater = async () => {
/*
const deviceHolders = await User.findAll({
Expand Down Expand Up @@ -345,4 +350,5 @@ module.exports = {
runAutumnReclaimStatusUpdater,
runSpringReclaimStatusUpdater,
runReclaimStatusUpdater,
reclaimForYear,
}
15 changes: 14 additions & 1 deletion server/util/studentUpdaterCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
})
const { checkStudentEligibilities, updateStudentEligibility, updateEligibleStudentStatuses } = require('../services/updaterService')
const {
checkStudentEligibilities, updateStudentEligibility, updateEligibleStudentStatuses, reclaimForYear,
} = require('../services/updaterService')

const commands = {
0: {
Expand Down Expand Up @@ -33,6 +35,17 @@ const commands = {
await updateEligibleStudentStatuses()
},
},
4: {
info: 'Reclaim a year',
exec: () => new Promise((res) => {
rl.question('Year: ', async (yearStr) => {
const year = Number(yearStr)
console.log('yes, running', year)
await reclaimForYear(year)
res()
})
}),
},
}

const printInsturctions = () => {
Expand Down

0 comments on commit f55762d

Please sign in to comment.