forked from Vidhi-123/scanner-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
130 lines (95 loc) · 6.16 KB
/
timer.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//var window=require('Window');
var tmp_lib=require('./models/lib_tmp');
var lib=require('./models/library');
const date = require('date-and-time');
var time={
f2() {
//var window=global;
setInterval(function(){ // Set interval for checking
var date1 = new Date(); // Create a Date object to find out what time it is
console.log(date1.getMinutes());
//console.log(global);
if(date1.getHours() === 11 && date1.getMinutes() === 02 ){ // Check the time
tmp_lib.find(function(err,docs){
if(err)
{
console.log(err);
// res.json(err);
}
else
{
console.log(docs.length);
//res.json(docs);
var i;
var id1;
for(i=0;i<docs.length;i++)
{
id1=docs[i].user_id;
tmp_lib.find({user_id:id1},function(err,docs1){
console.log(docs);
if(err)
{
// res.json(err);
console.log(err);
}// wait ek min
else
{
//res.json(docs);
console.log(docs1[0]);
const now = new Date();
let curtime=date.format(now,'HH:mm:ss')
docs1[0].out_time=curtime;
//date:new Date(dat_obj.getFullYear(),dat_obj.getMonth(),dat_obj.getDate()+1)
docs1[0].save(function(err1,res1){
if(err1)
{
//res.json(err1);
console.log(err1);
}
else
{
//res.json(res1);
const lib1=new lib({
user_id : docs1[0].user_id,
in_time :docs1[0].in_time,
out_time:docs1[0].out_time,
date:docs1[0].date
});
console.log(lib1);
lib1.save(function(err,result){
if(err)
{
//res.json(err);
console.log(err);
}
else{
//res.json(result);
console.log(lib1.user_id);
tmp_lib.deleteOne({user_id:lib1.user_id},function(err,result){
if(err)
{
//res.json(err);
console.log(err);
}
else
{
//res.json(result);
console.log(result);
}
})
}
});
}
});
}
});
}
}
//res.redirect('/lib_tmp');
console.log("done lib");//su kravu lakh tu
});
}
}, 60000);
}
};
module.exports=time;