Skip to content

Commit

Permalink
mongodb object id used
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-Thakur committed Jan 20, 2021
1 parent 0b033ef commit 2b2b4a7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions controllers/surveyController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ const express = require('express');
const mongoose = require('mongoose');
const survey = mongoose.model('Survey');
var router = express.Router();
const {ObjectId} = require('mongodb');

router.post('/fetchMySurveys', (req,res) => {
survey.findOne( { createdBy: req.body.createdBy }, function(err, docs) {
console.log(req.body);
survey.find( { createdBy: req.body.createdBy }, function(err, docs) {
if(!err) {
console.log(docs);
res.json(docs);
} else {
console.log('Error in fetching surveys: ' + err);
Expand Down Expand Up @@ -62,7 +65,7 @@ function addSurvey(req,res) {
status: 100,
message: "Survey Created",
surveyCode: docs.id
}
}
res.json(response);
} else {
console.log('Error during Survey record insertion: ' + err);
Expand All @@ -71,7 +74,9 @@ function addSurvey(req,res) {
}

router.get('/getSurvey:surveyId', (req,res) => {
survey.findOne( {id: req.params.surveyId}, function (err, docs) {
console.log(req.params.surveyId);
var id = mongoose.Types.ObjectId(req.params.surveyId)
survey.findOne( {_id: id}, function (err, docs) {
if(!err) {
if( (docs.validTill > new Date()) && (docs.active)) {
res.json(docs);
Expand Down

0 comments on commit 2b2b4a7

Please sign in to comment.