From 90bd771583cb4aec014d04cb82a61f6c3e128930 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Feb 2021 11:30:46 +0530 Subject: [PATCH] if statements and id removal from schema --- src/api/routers/PlayerSubmission.js | 97 ++++++++++++++++------------- src/database/models/Mission.js | 1 + 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/api/routers/PlayerSubmission.js b/src/api/routers/PlayerSubmission.js index 9636a46..9be2d64 100644 --- a/src/api/routers/PlayerSubmission.js +++ b/src/api/routers/PlayerSubmission.js @@ -319,63 +319,74 @@ player.get("/mission", playerVerify, TeamenRollVerify, async (req, res) => { const teamId = req.jwt_payload.team; const team = await Team.findById(teamId); - console.log("team", team); + const arr = []; const arr2 = []; const allMissions = team.assignedMissions; const allBonus = team.assignedBonus; - for (let index = 0; index < allBonus.length; index += 1) { - const activity = await Activity.findOne({ - team: req.jwt_payload.team, - mission: allBonus[index], - }); - const missionAll = await Mission.findById(allBonus[index]); - const bonus = { - clue: missionAll.clue, - MissionName: missionAll.MissionName, - Category: missionAll.Category, - maxPoints: missionAll.maxPoints, - answer_Type: missionAll.answer_Type, - isBonus: missionAll.isBonus, - status: activity.isSubmitted, - }; - arr2.push(bonus); - if (!activity) { - await Activity.create({ + for (let index = 0; index < allBonus.length; index += 1) { + if (allBonus[index] !== null) { + const activity = await Activity.findOne({ team: req.jwt_payload.team, - isSubmitted: false, - likes: 0, mission: allBonus[index], - hintsTaken: 0, }); + const missionAll = await Mission.findById(allBonus[index]); + const bonus = { + clue: missionAll.clue, + MissionName: missionAll.MissionName, + Category: missionAll.Category, + maxPoints: missionAll.maxPoints, + answer_Type: missionAll.answer_Type, + isBonus: missionAll.isBonus, + status: activity.isSubmitted, + _id: missionAll._id, + }; + arr2.push(bonus); + + if (!activity) { + await Activity.create({ + team: req.jwt_payload.team, + isSubmitted: false, + likes: 0, + mission: allBonus[index], + hintsTaken: 0, + }); + } + } else { + arr2.push(null); } } for (let i = 0; i < allMissions.length; i += 1) { - const activity = await Activity.findOne({ - team: req.jwt_payload.team, - mission: allMissions[i], - }); - - const missionAll = await Mission.findById(allMissions[i]); - const mission = { - clue: missionAll.clue, - MissionName: missionAll.MissionName, - Category: missionAll.Category, - maxPoints: missionAll.maxPoints, - answer_Type: missionAll.answer_Type, - isBonus: missionAll.isBonus, - status: activity.isSubmitted, - }; - arr.push(mission); - if (!activity) { - await Activity.create({ + if (allMissions[i] !== null) { + const activity = await Activity.findOne({ team: req.jwt_payload.team, - isSubmitted: false, - likes: 0, mission: allMissions[i], - hintsTaken: 0, }); + + const missionAll = await Mission.findById(allMissions[i]); + const mission = { + clue: missionAll.clue, + MissionName: missionAll.MissionName, + Category: missionAll.Category, + maxPoints: missionAll.maxPoints, + answer_Type: missionAll.answer_Type, + isBonus: missionAll.isBonus, + status: activity.isSubmitted, + _id: missionAll._id, + }; + arr.push(mission); + if (!activity) { + await Activity.create({ + team: req.jwt_payload.team, + isSubmitted: false, + likes: 0, + mission: allMissions[i], + hintsTaken: 0, + }); + } + } else { + arr.push(null); } } const missions = arr.concat(arr2); diff --git a/src/database/models/Mission.js b/src/database/models/Mission.js index c08e30b..1b7c6c9 100644 --- a/src/database/models/Mission.js +++ b/src/database/models/Mission.js @@ -14,6 +14,7 @@ const MissionSchema = new Schema({ }, clue: [ { + _id: false, text: { type: String, },