-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
33 lines (30 loc) · 1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const CronJob = require('cron').CronJob;
const db = require('./models');
const moment = require('moment');
function replaceAt(string, index, replacement) {
return string.substring(0, index ) +replacement + string.substring(index + replacement.length);
}
function incrementValueFromCSVLine(string, index, val) {
return replaceAt(string, index, (parseInt(string.charAt(index)) + val).toString());
}
const laundrydata = db.Level.findByPk(8);
const day = moment().format('ddd').toLowerCase();
const hour = parseInt(moment().format('HH'));
let dailyData;
laundrydata.then(x => {
dailyData = x.getDataValue(day);
console.log(`${day}-${hour}:${dailyData}`);
dailyData = incrementValueFromCSVLine(dailyData, hour * 2, 3);
console.log(`${day}-${hour}:${dailyData}`);
return [x, dailyData];
})
.then(res =>{
let query = {};
query[day] = res;
db.Level.update(query, {
where: {
level: 8
}
}).then(result => console.log(result));
}
).catch(err => console.log(err));