Reportistica Ore 2
This commit is contained in:
@@ -21,7 +21,7 @@ const _ = require('lodash');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
router.post('/', authenticate, async (req, res) => {
|
||||
|
||||
var body = _.pick(req.body, tools.allfieldTodoWithId());
|
||||
// tools.mylogshow('INPUT', body);
|
||||
@@ -48,25 +48,44 @@ router.post('/', authenticate, (req, res) => {
|
||||
console.log('RECORD NON VALIDO !?', req.body)
|
||||
}
|
||||
|
||||
todo.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
Todo.findById(idobj)
|
||||
.then(record => {
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
let prevrec = null;
|
||||
if (!!todo && todo._id)
|
||||
prevrec = await Todo.findById(todo._id);
|
||||
|
||||
tools.sendNotificationToUser(todo.userId, 'Todo: ' + record.descr, record.descr, '/todo/' + todo.category, '', 'todo', [])
|
||||
.then(ris => {
|
||||
if (ris) {
|
||||
res.send({ record });
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
return todo.save()
|
||||
.then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
return Todo.findById(idobj)
|
||||
.then(record => {
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
|
||||
let aggiorna = false;
|
||||
let titolo = '';
|
||||
|
||||
if (prevrec) {
|
||||
if (todo.completed_at !== prevrec.completed_at) {
|
||||
aggiorna = true;
|
||||
titolo = 'Attività Completata!'
|
||||
}
|
||||
})
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.log('ERRORE in TODO POST', e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
} else {
|
||||
aggiorna = true;
|
||||
}
|
||||
|
||||
if (aggiorna) {
|
||||
tools.sendNotificationToUser(todo.userId, titolo + ' ' + record.descr, record.descr, '/todo/' + todo.category, '', 'todo', [])
|
||||
.then(ris => {
|
||||
if (ris) {
|
||||
return res.send({ record });
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.log('ERRORE in TODO POST', e.message);
|
||||
return res.status(400).send(e);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -101,7 +120,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
.then(objdatacalc => {
|
||||
// tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||
|
||||
if (todo.userId !== String(req.user._id) && project.privacywrite === server_constants.Privacy.onlyme) {
|
||||
if (todo.userId !== String(req.user._id) && todo.privacywrite === server_constants.Privacy.onlyme) {
|
||||
// I'm trying to write something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user