-
Notifications
You must be signed in to change notification settings - Fork 0
/
timetest.js
108 lines (82 loc) · 2.57 KB
/
timetest.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var mongoose = require('mongoose');
//var flash = require('connect-flash');
var Schema = mongoose.Schema;
var ObjectId = mongoose.Types.ObjectId;
mongoose.connect('mongodb://localhost/Test_Thirst_Keeper');
var db = mongoose.connection;
var axios = require('axios');
var moment = require('moment');
var now = moment();
console.log(now);
var then = moment("030000pm","hhmmssa");
console.log(now.isAfter(then));
// var offset = moment().utcOffset();
// console.log(offset);
//
// var testoffset = moment().utcOffset("+07:00");
// console.log(testoffset);
var userSchema = mongoose.Schema({
local : {
_id : Schema.ObjectId,
email : String,
password : String,
timeoffset :{ type: String, default: moment().utcOffset()},
subscribe :{ type: Boolean,default: false},
send :{ type: Boolean,default: false},
device :[]
}
});
var dataSchema = mongoose.Schema({
_creator : { type: Schema.ObjectId, ref: 'User' },
_id : Schema.ObjectId,
date : String,
value : Number
});
var User = mongoose.model('User',userSchema);
var Data = mongoose.model('Data',dataSchema);
// var newUser = new User();
//
// // set the user's local credentials
// newUser.local._id = new ObjectId();
// newUser.local.email = "[email protected]";
// newUser.local.password = "test";
//
// // save the user
// newUser.save(function(err) {
// if (err)
// throw err;
// return(newUser);
// });
//
//
// User.findOne({ 'local.email' : "[email protected]"}, function(err, data) {
// console.log(data);
// });
//
// User.findOneAndUpdate({ 'local.email' : "[email protected]"},{$addToSet: {"local.device": "22"}, $set: { 'local.subscribe': true }} ,{new:true},function(err, data) {
// console.log(err);
// console.log(data);
// });
var api_url = 'http://localhost:8000/api/adddevice:'+"testdevice"+'/subscribe:yes';
axios.put(api_url)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
db.close();
/*for(let i = 0; i<10;i++){
var newData = new Data();
newData._creator = ObjectId("594abe1d3b41fd10ea2f1b73");
newData._id = new ObjectId();
newData.date = moment().subtract(1,'days').format("YYYY-MM-DD");
newData.value = Math.floor((Math.random() * 8) + 1);
// save the data
newData.save(function(err) {
if (err)
throw err;
console.log("created new data");
db.close();
});
}*/