Friday, 7 April 2017

mongoose syntax with user.id connecting to a form

Hi I am new to mongoose and with angular through ionic. I am trying to build an app and having problem with it. I have no Idea if this syntax mongoose is right because it still is not working in my front end where the user picks and answer and it saves it to the database

Heres my mongoose question.js

var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Question = require('../models/Question.js');
var app = express();




 // GET questions listing. questions/yourroute
 router.get('/', function(req, res, next) { 
 Question.find(function(err, questions){
 if(err) return next(err);

 res.json(questions);

 });
 });

 router.post('/saved-questions', function(req, res){

 var now = Date()
 User.findById(user.id, function(err, user){

var newanswer1 = {
    question: '58ccb991caf9756f8e1d8a6c',
    answer_text: req.body.Q1,
    postdate: now
 }



 });


 user.users_answers.push(newanswer1);

 //repeat for Q 2 and 3, push each time

 User.save()

  });
  module.exports = router;

And this is the form in ionic.. I don't know why its not working, maybe its how im putting it in the ionic form. There suppose to be slides of questions in ionic and each possible answer is in the ion check box

 <div id="questions" ng-controller="QCntrl">

 <ion-content>
 <ion-slide-box>
 <ion-slide>
 <div class="intro" ng-controller="PopupCtrl">
    <h1 class="hidden">Intro Question</h1>
    <h3>Just need to ask some questions to make this app personalized for you</h3>
    <button class="button" value="next" ng-click="nextSlide()">OKAY</button>
     <button class="button2 button-positive" ng-click="PopAlert()">
  Why?
     </button>

   </div>

  </ion-slide>




  <ion-slide>
  <div id="Q1box">
  <h2></h2>
 <ul>
 <li data-ng-repeat="answer in answers1">
 <ion-checkbox id="Q1" ng-model="filter.users_answers"></ion-    checkbox>
</li>
</ul>
<a href="#" ng-click="next()">Next Question</a>
</div>
</ion-slide> 



via panchita911