Skip to content

Commit

Permalink
Merge branch 'prod' of gitlab.com:iecse-manipal/board-20/prometheus-2…
Browse files Browse the repository at this point in the history
…1/hawkeye-2021 into prod
  • Loading branch information
Akhil Kala committed Jun 19, 2021
2 parents f8accdf + 771e2ea commit 4ca0f91
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/src/controllers/hawksNestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ErrorResponse from '../utils/ErrorResponse';
import { compareAnswers, unlockRegion } from '../utils/helperFunctions';
import UnlockedHawksNestHint from '../models/HawksNestHintUnlocked';
import HawksNestHint from '../models/HawksNestHint';
import AttemptTime from '../models/AttemptTime';

export const addHawksNestQuestion = async (
req: Request,
Expand Down Expand Up @@ -202,6 +203,12 @@ export const submitHawksNestQuestion = async (
}
}

let timest = await AttemptTime.findOneAndUpdate(
{ user: user._id, question: question._id },
{ attempt: req.body.attempt, time: new Date(Date.now()) },
{ new: true, upsert: true }
);

if (index == -1) {
user.nestAttempts.push({
question: question._id,
Expand Down
9 changes: 9 additions & 0 deletions api/src/controllers/questionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { compareAnswers, unlockRegion } from '../utils/helperFunctions';
import Region from '../models/Region';
import UnlockedHint from '../models/unlockedHint';
import Hint, { HintDoc } from '../models/Hint';
import AttemptTime from '../models/AttemptTime';

export const getQuestionByRegionId = async (
req: Request,
Expand Down Expand Up @@ -190,6 +191,14 @@ export const submitQuestion = async (
}
}

let timest = await AttemptTime.findOneAndUpdate(
{ user: user._id, question: question._id },
{ attempt: req.body.attempt, time: new Date(Date.now()) },
{ new: true, upsert: true }
);

console.log(timest);

if (index == -1) {
user.attempts.push({
question: question._id,
Expand Down
29 changes: 29 additions & 0 deletions api/src/models/AttemptTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import mongoose from 'mongoose';

export interface AttemptTimeDoc extends mongoose.Document {
user: mongoose.Schema.Types.ObjectId;
question: mongoose.Schema.Types.ObjectId;
attempt: string;
time: Date;
}

const AttemptTimeSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true,
},
question: {
type: mongoose.Schema.Types.ObjectId,
required: true,
},
attempt: {
type: String,
},
time: {
type: Date,
defualt: Date.now,
},
});

export default mongoose.model<AttemptTimeDoc>('AttemptTime', AttemptTimeSchema);

0 comments on commit 4ca0f91

Please sign in to comment.