-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
160 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
const Config = require("../dist/core/Config"); | ||
const Sequelize = require("sequelize") | ||
const Sequelize = require("sequelize"); | ||
const dayjs = require("dayjs"); | ||
|
||
/** | ||
* This script periodically checks, if a user has an endorsement bound to a solo, whilst the solo has already passed | ||
* Once every 24 Hours. | ||
*/ | ||
const newConf = {...Config.SequelizeConfig, logging: (message) => {console.log(message)}} | ||
const newConf = { | ||
...Config.SequelizeConfig, | ||
logging: message => { | ||
console.log(message); | ||
}, | ||
}; | ||
const seq = new Sequelize(newConf); | ||
seq.authenticate() | ||
.catch(() => { | ||
console.log("[SEQ] Failed to authenticate..."); | ||
}); | ||
seq.authenticate().catch(() => { | ||
console.log("[SEQ] Failed to authenticate..."); | ||
}); | ||
|
||
seq.query("SELECT endorsement_groups_belong_to_users.id, endorsement_groups_belong_to_users.user_id, endorsement_groups_belong_to_users.solo_id, user_solos.current_solo_start, user_solos.current_solo_end FROM endorsement_groups_belong_to_users JOIN user_solos ON user_solos.id = endorsement_groups_belong_to_users.solo_id", { | ||
type: Sequelize.QueryTypes.SELECT | ||
}) | ||
.then((res) => { | ||
res.forEach(async (solo) => { | ||
if (dayjs.utc(solo.current_solo_end).isBefore(dayjs.utc())) { | ||
console.log(`Solo ID ${solo.solo_id} has expired. Removing Endorsement Group...`); | ||
} else { | ||
console.log(`Solo ID ${solo.solo_id} is expiring on ${dayjs.utc(solo.current_solo_end)} (${Math.abs(dayjs.utc(solo.current_solo_end).diff(dayjs.utc()))} Day(s) remaining).`) | ||
} | ||
seq.query( | ||
"SELECT endorsement_groups_belong_to_users.id, endorsement_groups_belong_to_users.user_id, endorsement_groups_belong_to_users.solo_id, user_solos.current_solo_start, user_solos.current_solo_end FROM endorsement_groups_belong_to_users JOIN user_solos ON user_solos.id = endorsement_groups_belong_to_users.solo_id", | ||
{ | ||
type: Sequelize.QueryTypes.SELECT, | ||
} | ||
) | ||
.then(res => { | ||
res.forEach(async solo => { | ||
if (dayjs.utc(solo.current_solo_end).isBefore(dayjs.utc())) { | ||
console.log(`Solo ID ${solo.solo_id} has expired. Removing Endorsement Group...`); | ||
} else { | ||
console.log( | ||
`Solo ID ${solo.solo_id} is expiring on ${dayjs.utc(solo.current_solo_end)} (${Math.abs( | ||
dayjs.utc(solo.current_solo_end).diff(dayjs.utc(), "day") | ||
)} Day(s) remaining).` | ||
); | ||
} | ||
|
||
await seq.query("DELETE FROM endorsement_groups_belong_to_users WHERE ID = ?", {replacements: [solo.id], type: Sequelize.QueryTypes.DELETE}) | ||
await seq.query("DELETE FROM endorsement_groups_belong_to_users WHERE ID = ?", { replacements: [solo.id], type: Sequelize.QueryTypes.DELETE }); | ||
}); | ||
}) | ||
.finally(async () => { | ||
await seq.close(); | ||
}); | ||
}) | ||
.finally(async() => { | ||
await seq.close() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* * * * * cd /opt/trainingcenter_backend && node /opt/trainingcenter_backend/misc/CheckEndorsements.js >> /var/log/check_endorsement.log | ||
0 1 * * * cd /opt/trainingcenter_backend && node /opt/trainingcenter_backend/misc/CheckEndorsements.js >> /var/log/check_endorsement.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { MentorGroup } from "../MentorGroup"; | ||
import { EndorsementGroup } from "../EndorsementGroup"; | ||
|
||
/** | ||
* Gets all the endorsement groups associated to this | ||
*/ | ||
async function getEndorsementGroups(this: MentorGroup): Promise<EndorsementGroup[]> { | ||
const m = await MentorGroup.findOne({ | ||
where: { | ||
id: this.id, | ||
}, | ||
include: [ | ||
{ | ||
association: MentorGroup.associations.endorsement_groups, | ||
through: { | ||
attributes: [], | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
return m?.endorsement_groups ?? []; | ||
} | ||
|
||
export default { | ||
getEndorsementGroups, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters