Doing some work on a small server that is trying to add information from google calendar. At the moment I'm just removing all the data and replacing every time the database is updated but it seems to just end with everything removed.
I'm using statics in the model to add and remove data like so:
DataSchema.statics.saveData = function(data) {
var newData = new d(data);
newData.save();
};
DataSchema.statics.removeAllData = function () {
d.remove({building : "Centre"});
};
Which are being called like this:
console.log('Upcoming events:');
Data.removeAllData();
for (let i = 0; i < events.length; i++) {
const event = events[i];
const start = event.start.dateTime;
const end = event.end.dateTime;
const temp = 21;
const bName = "Centre";
const roomNum = "1";
console.log('%s - %s - %s', start, event.summary, event.end.dateTime);
const newEvent = {start: start, finish: end, building: bName, room: roomNum, requestedTemperature: temp};
//console.log(Data.findIfPresent(roomNum, start, end));
Data.saveData(newEvent);
I'm not primarily a JS programmer but to my understanding could this be to do with some async computation where the data I need is added and then the removal actually happens afterwards? If I've not provided enough information please let me know and any help would be appreciated, Thanks!
via Bort
No comments:
Post a Comment