- Update the way to use the data records on Vuex with Getters!

- Fix: mongodb call passing array todos and categiroes already splitted
This commit is contained in:
Paolo Arena
2019-02-27 02:59:02 +01:00
parent d78de1a25c
commit 8f1ee2a7da
5 changed files with 107 additions and 16 deletions

View File

@@ -7,6 +7,8 @@ var Url = require('url-parse');
const mongoose = require('mongoose');
const Subscription = mongoose.model('subscribers');
const server_constants = require('../tools/server_constants');
// SETTINGS WebPush Configuration
const webpush = require('web-push');
@@ -48,7 +50,7 @@ module.exports = {
allfieldTodo: function () {
return ['userId', 'pos', 'category', 'descr', 'priority', 'completed', 'created_at', 'modify_at',
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'id_next', 'progress', 'modified']
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'progress', 'modified']
},
allfieldTodoWithId: function () {
@@ -60,10 +62,10 @@ module.exports = {
console.log('sendBackNotif:', subscription, payload);
// Pass object into sendNotification
webpush.sendNotification(subscription, JSON.stringify(payload)).catch(err => console.error(err))
.catch(err => {
.catch(err => {
if (err.statusCode === 410) {
// Gone: is not valid anymore (Expired probably!), so I have to delete from my db
return Subscription.findOneAndRemove( { _id:subscription._id } )
return Subscription.findOneAndRemove({ _id: subscription._id })
} else {
console.log('Subscription is no longer valid: ', err);
}
@@ -132,7 +134,7 @@ module.exports = {
console.log('************ INVIO WEBPUSH.SENDNOTIFICATION N° ', conta, '/', trovati, 'A', subscription.browser);
console.log('vapidDetails', pushOptions.vapidDetails);
payload.title = process.env.URLBASE_APP1 + ' Msg n° ' + conta +'/' + trovati;
payload.title = process.env.URLBASE_APP1 + ' Msg n° ' + conta + '/' + trovati;
// payload.message += subscription.browser ;
const pushPayload = JSON.stringify(payload);
@@ -172,8 +174,43 @@ module.exports = {
}
});
},
// **********************
// SORT WITH PREV_ID
// **********************
mapSort: function (linkedList) {
var sortedList = [];
var map = new Map();
var currentId = null;
// console.log('linkedList', linkedList);
// index the linked list by previous_item_id
for (var i = 0; i < linkedList.length; i++) {
var item = linkedList[i];
if (item.id_prev === server_constants.LIST_START) {
// first item
currentId = String(item._id);
// console.log('currentId', currentId);
sortedList.push(item);
} else {
map.set(item.id_prev, i);
}
}
while (sortedList.length < linkedList.length) {
// get the item with a previous item ID referencing the current item
var nextItem = linkedList[map.get(currentId)];
if (nextItem === undefined)
break;
sortedList.push(nextItem);
currentId = String(nextItem._id);
}
// console.log('DOPO sortedList', sortedList);
return sortedList;
}
// Test
};