Commit ae912610 authored by ninon's avatar ninon

Merge branch 'clement/feature/display-tree-by-date' of...

Merge branch 'clement/feature/display-tree-by-date' of https://gitlab.utc.fr/cbrizard/agoraviz into clement/feature/display-tree-by-date
parents 395a1d90 5c7be8ec
......@@ -4,5 +4,6 @@ const router = express.Router();
router.use('/debates', require('./debate'));
router.use('/contributions', require('./contribution'));
router.use('/syntheses', require('./synthese'));
module.exports = router;
......@@ -4,6 +4,7 @@ const router = express.Router();
router.use('/debates', require('./debate'));
router.use('/contributions', require('./contribution'));
router.use('/syntheses', require('./synthese'));
// Home page
router.get('/', (req, res) => {
......
const express = require('express');
const getJSON = require('get-json');
const Synthese = require('../models/synthese');
const router = express.Router();
/*
CRUD
*/
// Create a new synthese
router.post('/', (req, res) => {
var dateNewSynthese = new Date();
var jour = dateNewSynthese.getDate();
var mois = dateNewSynthese.getMonth()+1;
var annee = dateNewSynthese.getFullYear();
var heure = dateNewSynthese.getHours();
var minute = dateNewSynthese.getMinutes();
var seconde = dateNewSynthese.getSeconds();
var syntheseDateHeure =jour+'/'+mois+'/'+annee+':'+heure+'H'+minute+'min'+seconde+'s';
/*
contribsToInsert = [];
req.body.contributions.forEach(function (c){
contribsToInsert.push(ObjectId(c));
})*/
const obj = {
description: req.body.description,
contributions: req.body.contributions,
debate: req.body.debate,
auteur: req.body.auteur,
timestamp: syntheseDateHeure,
};
console.log('ajout synthese');
Synthese.new(req.db, obj, (err) => {
if (err) {
res.send('Error when trying to create a synthese');
}
res.redirect('/debates');
});
});
// Delete a synthese
router.post('/delete/:id', (req, res) => {
const id = req.params.id;
Synthese.delete(req.db, id, (err) => {
if (err) {
res.send('Error trying to delete a synthese')
}
res.redirect('/debates');
});
});
module.exports = router;
......@@ -46,10 +46,25 @@ exports.new = (db, obj, cb) => {
auteur: obj.auteur,
timestamp: obj.timestamp,
}, {}, (err, doc) => {
db.get('contribcollection').find({}).each(function (contrib) {
var synthese = db.get('synthesecollection').find({ description : obj.description});
if (obj.contributions.includes(JSON.stringify(contrib._id))) {
console.log(synthese._id);
db.get('contribcollection').update({ _id: contrib._id},{$set: {synthese: obj.description}});
}},{}, (err, doc) => {
return err ?
cb(err)
: cb(null, doc);
});
return err ?
cb(err)
: cb(null, doc);
});
};
// Delete a synthese
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment