Doppia modalità di Registrazione con lista extra utenti
This commit is contained in:
@@ -22,12 +22,12 @@ const { ObjectID } = require('mongodb');
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
|
||||
var body = _.pick(req.body, tools.allfieldTodoWithId());
|
||||
tools.mylogshow('INPUT', body);
|
||||
// tools.mylogshow('INPUT', body);
|
||||
var todo = new Todo(body);
|
||||
|
||||
// todo.expiring_at = new Date(todo.expiring_at);
|
||||
|
||||
tools.mylog('ID :', todo._id, todo.descr, todo.userId, req.user._id);
|
||||
// tools.mylog('ID :', todo._id, todo.descr, todo.userId, req.user._id);
|
||||
|
||||
if (!('descr' in req.body)) {
|
||||
return res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
|
||||
@@ -39,7 +39,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
tools.mylog('TODO POST :', todo.descr, todo._id);
|
||||
// tools.mylog('TODO POST :', todo.descr, todo._id);
|
||||
|
||||
todo.modified = false;
|
||||
if (!todo.descr) {
|
||||
@@ -50,7 +50,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
let idobj = writeresult._id;
|
||||
Todo.findById(idobj)
|
||||
.then(record => {
|
||||
tools.mylog('REC SAVED :', record.descr);
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
|
||||
tools.sendNotificationToUser(todo.userId, 'Todo: ' + record.descr, record.descr, '/todo/' + todo.category, 'todo')
|
||||
.then(ris => {
|
||||
@@ -72,7 +72,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
var body = _.pick(req.body, tools.allfieldTodo());
|
||||
|
||||
tools.mylogshow('PATCH TODO: ', id);
|
||||
// tools.mylogshow('PATCH TODO: ', id);
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
tools.mylog('ERROR: id not VALID', id);
|
||||
@@ -90,7 +90,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
let level = 0;
|
||||
return Todo.calculateTreeTodo(todo.phase, todo.userId, todo.category, true, todo.category, false)
|
||||
.then(objdatacalc => {
|
||||
tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||
// tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||
|
||||
if (todo.userId !== String(req.user._id)) {
|
||||
// I'm trying to write something not mine!
|
||||
@@ -99,7 +99,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
|
||||
todo.modified = false;
|
||||
|
||||
tools.mylog('PATCH ', todo.descr, todo._id);
|
||||
// tools.mylog('PATCH ', todo.descr, todo._id);
|
||||
|
||||
res.send({ todo, objdatacalc });
|
||||
});
|
||||
@@ -115,7 +115,7 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
var userId = req.params.userId;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET TODOS : ', req.params);
|
||||
// tools.mylog('GET TODOS : ', req.params);
|
||||
|
||||
if (!ObjectID.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
@@ -129,8 +129,8 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
// Extract all the todos of the userId only
|
||||
Todo.getAllTodo(userId).then((objtodos) => {
|
||||
if (!!objtodos.arrtodos) {
|
||||
tools.mylog('todos', objtodos.arrtodos.length);
|
||||
tools.mylog('categories', objtodos.arrcategories.length);
|
||||
// tools.mylog('todos', objtodos.arrtodos.length);
|
||||
// tools.mylog('categories', objtodos.arrcategories.length);
|
||||
}
|
||||
|
||||
res.send({ todos: objtodos.arrtodos, categories: objtodos.arrcategories });
|
||||
@@ -141,16 +141,46 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/test', (req, res) => {
|
||||
|
||||
const todo = {
|
||||
_id: new ObjectID(),
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
descr: "Primo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: null,
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 1,
|
||||
priority: 1,
|
||||
progress: 0,
|
||||
userId: users[0]._id
|
||||
};
|
||||
|
||||
const TodoOne = new Todo(todo).save().then((err, ris) => {
|
||||
console.log('Err:', err);
|
||||
console.log('Ris:', ris);
|
||||
|
||||
});
|
||||
|
||||
res.send({ });
|
||||
|
||||
});
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET ALL TODOS ');
|
||||
// tools.mylog('GET ALL TODOS ');
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
Todo.getAllTodo('').then((objtodos) => {
|
||||
if (!!objtodos.arrtodos) {
|
||||
tools.mylog('todos', objtodos.arrtodos.length);
|
||||
tools.mylog('categories', objtodos.arrcategories.length);
|
||||
// tools.mylog('todos', objtodos.arrtodos.length);
|
||||
// tools.mylog('categories', objtodos.arrcategories.length);
|
||||
}
|
||||
|
||||
res.send({ todos: objtodos.arrtodos, categories: objtodos.arrcategories });
|
||||
@@ -173,7 +203,7 @@ router.delete('/:id', authenticate, (req, res) => {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
tools.mylog('DELETED ', todo.descr, todo._id);
|
||||
// tools.mylog('DELETED ', todo.descr, todo._id);
|
||||
|
||||
res.send({ todo });
|
||||
}).catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user