Skip to content

Commit

Permalink
Merge pull request #99 from gokul-00/newBackend
Browse files Browse the repository at this point in the history
New backend
  • Loading branch information
Mansibisen authored Jan 21, 2021
2 parents b26c3b4 + 9c9cb4c commit 00994f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/api/routers/AdminRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ Router.post("/accept", AcceptValidator, adminVerify, async (req, res) => {
}
const mission = await Mission.findById(activity.mission);
const team = await Team.findById(activity.team._id);
console.log();

if (isAccepted == "true") {
if (isAccepted) {
if (activity.isSubmitted && !activity.status) {
console.log(mission.maxPoints, " - ", activity.hintsTaken);
team.points += mission.maxPoints - activity.hintsTaken * 20;
activity.status = true;
activity.Date = Date.now();
await team.save();
await activity.save();
} else {
Expand All @@ -134,8 +133,8 @@ Router.post("/accept", AcceptValidator, adminVerify, async (req, res) => {
}
} else {
activity.isSubmitted = false;
activity.Date = Date.now();
await activity.save();
// await activity.deleteOne({ id: activityfeedId });
}
return res
.status(200)
Expand Down
7 changes: 5 additions & 2 deletions src/api/routers/PlayerSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ player.post(
{
Answer: answer,
category: Category,
status: "Accepted",
status: true,
ShouldBeShown: visibility,
isSubmitted: true,
}
);
// team
} else {
return res.status(200).json({ message: "Your answer is wrong" });
}
Expand All @@ -124,11 +125,12 @@ player.post(
{
Answer: answer,
category: Category,
status: "Accepted",
status: true,
ShouldBeShown: visibility,
isSubmitted: true,
}
);
//team
} else {
result = await Activity.updateOne(
{ team, mission, isSubmitted: false },
Expand All @@ -140,6 +142,7 @@ player.post(
isSubmitted: true,
}
);
//admin
}
if (result.nModified === 1) {
return res.status(200).json({ message: "Successfully submitted" });
Expand Down
21 changes: 16 additions & 5 deletions src/api/routers/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ const Mission = require("../../database/models/Mission");

Router.get("/feed", async (req, res) => {
try {
const feeds = await Feed.find({ status: "accepted" });
const feeds = await Feed.find({ status: true })
.populate("team")
.populate("mission")
.exec();

const feedToBeShown = [];
const details = {};
for (let index = 0; index < feeds.length; index++) {
const { mission } = feeds[index];
const missionStatement = await Mission.findById(mission);
if (missionStatement.Feed) {
feedToBeShown.push(feeds[index]);
details.MissionName = feeds[index].mission.MissionName;
details.TeamName = feeds[index].team.teamName;
details.likes = feeds[index].likes;
details._id = feeds[index]._id;
details.team_id = feeds[index].team._id;
details.Date = feeds[index].Date;

if (feeds[index].mission.Feed) {
feedToBeShown.push(details);
}
}

return res.status(200).json({ activityFeeds: feedToBeShown });
} catch (err) {
console.log(err);
Expand Down
4 changes: 4 additions & 0 deletions src/database/models/Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ const activitySchema = new mongoose.Schema({
type: Boolean,
default: false,
},
Date: {
type: Date,
default: Date.now(),
},
});
module.exports = mongoose.model("Activity", activitySchema);

0 comments on commit 00994f6

Please sign in to comment.