fix(api): add needsModeration flag to user document root (#45921)

* fix(api): add needsModeration flag to user document root

* fix prettiers complaints

* Update api-server/src/common/models/user.json

Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
This commit is contained in:
Shaun Hamilton
2022-05-11 15:30:51 -05:00
committed by GitHub
co-authored by Naomi Carrigan Tom
parent 8da87f4d58
commit 2717581b2f
2 changed files with 25 additions and 1 deletions
+11
View File
@@ -120,6 +120,17 @@
"description": "Camper has signed academic honesty policy",
"default": false
},
"needsModeration": {
"type": "boolean",
"description": "Camper has challenges needing to be moderated",
"default": false,
"index": {
"mongodb": {
"unique": true,
"background": true
}
}
},
"isFrontEndCert": {
"type": "boolean",
"description": "Camper is front end certified",
+14 -1
View File
@@ -145,7 +145,11 @@ export function buildUserUpdate(
}
let finalChallenge;
const updateData = {};
const { timezone: userTimezone, completedChallenges = [] } = user;
const {
timezone: userTimezone,
completedChallenges = [],
needsModeration = false
} = user;
const oldChallenge = find(
completedChallenges,
@@ -210,6 +214,14 @@ export function buildUserUpdate(
timezone: userTimezone
};
}
if (needsModeration) {
updateData.$set = {
...updateData.$set,
needsModeration: true
};
}
return {
alreadyCompleted,
updateData,
@@ -309,6 +321,7 @@ export function modernChallengeCompleted(req, res, next) {
// if multifile cert project
if (challengeType === 14) {
completedChallenge.isManuallyApproved = false;
user.needsModeration = true;
}
// We only need to know the challenge type if it's a project. If it's a