- fix: Date problems... (it was a bad "copy" function, the object date was not valid...)
- fix: error fetch on loading... (offline appeared)
This commit is contained in:
@@ -22,11 +22,16 @@ const { ObjectID } = require('mongodb');
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
|
||||
var body = _.pick(req.body, tools.allfieldTodoWithId());
|
||||
tools.mylogshow('INPUT', body);
|
||||
var todo = new Todo(body);
|
||||
|
||||
// tools.mylogshow('ID :', todo._id)
|
||||
// todo.expiring_at = new Date(todo.expiring_at);
|
||||
|
||||
// tools.mylogshow('userid', todo.userId, req.user._id)
|
||||
tools.mylogshow('TODO', todo);
|
||||
|
||||
tools.mylog('ID :', todo._id);
|
||||
|
||||
tools.mylog('userid', todo.userId, req.user._id);
|
||||
|
||||
if (!('descr' in req.body)){
|
||||
return res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
|
||||
@@ -38,7 +43,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
tools.mylog('POST :', todo.descr, todo._id);
|
||||
tools.mylog('TODO POST :', todo.descr, todo._id);
|
||||
|
||||
todo.modified = false;
|
||||
if (!todo.descr) {
|
||||
@@ -55,7 +60,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
res.send({record});
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
console.log('ERRORE in TODO POST', e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
});
|
||||
@@ -102,6 +107,7 @@ function sendNotificationToUser(userId, title, content, openUrl, tag) {
|
||||
TTL: payload.ttl,
|
||||
headers: {}
|
||||
};
|
||||
|
||||
webpush.sendNotification(
|
||||
pushSubscription,
|
||||
pushPayload,
|
||||
@@ -119,6 +125,9 @@ function sendNotificationToUser(userId, title, content, openUrl, tag) {
|
||||
data: err
|
||||
});
|
||||
});
|
||||
}).catch(error => {
|
||||
console.log('ERROR: sendNotificationToUser', error
|
||||
)
|
||||
});
|
||||
});
|
||||
// q.allSettled(parallelSubscriptionCalls).then((pushResults) => {
|
||||
@@ -136,6 +145,8 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
var body = _.pick(req.body, tools.allfieldTodo());
|
||||
|
||||
tools.mylogshow('PATCH TODO: ', id)
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
tools.mylog('ERROR: id not VALID', id);
|
||||
return res.status(404).send();
|
||||
@@ -143,6 +154,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
|
||||
|
||||
Todo.findByIdAndUpdate(id, {$set: body}, {new: true}).then((todo) => {
|
||||
tools.mylogshow(' TODO TO MODIFY: ', todo)
|
||||
if (!todo) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
@@ -180,8 +192,10 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
Todo.findAllByUserId(userId).then((todos) => {
|
||||
// tools.mylog('todos', todos)
|
||||
res.send({ todos });
|
||||
|
||||
tools.mylog('todos', todos);
|
||||
|
||||
res.send({ todos: todos });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
res.status(400).send(e);
|
||||
@@ -209,4 +223,5 @@ router.delete('/:id', authenticate, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user