Skip to content

Instantly share code, notes, and snippets.

@atakangah
Created July 12, 2020 11:23
Show Gist options
  • Save atakangah/71b4b470f2a7b120bb75a91a3b57f1a0 to your computer and use it in GitHub Desktop.
Save atakangah/71b4b470f2a7b120bb75a91a3b57f1a0 to your computer and use it in GitHub Desktop.
async function updateCompletedStudents(courseId, student, res) {
/*
* Substract -1 from @continuingStudents on system
*/
try {
//Get current system data
let system = await System.find({ 'systemId': SYSTEM_ID }).exec();
//Substract -1 from continuingStudents
system[0].continuingStudents -=1;
try {
//Update new system status
await System.updateOne({ 'systemId': SYSTEM_ID }, system[0], { upsert: true }).exec();
} catch (error) {
console.log(error);
res.status(Errors.DATABASE.DOC_UPDATE_OP_FAILED.CODE).send({
detail: Errors.FATAL_ERROR_MESSAGE
});
}
} catch (error) {
res.status(Errors.DATABASE.DOC_READ_OP_FAILED.CODE).send({
detail: Errors.FATAL_ERROR_MESSAGE
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment