-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
194 lines (164 loc) · 5.88 KB
/
router.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const express = require('express')
const User=require('../models/user')
const router = new express.Router()
router.post('',async(req,res)=>{
console.log('In post')
var barcode=req.body.BarcodeID
var tempFromOutside=req.body.temperature
if(barcode ===undefined && tempFromOutside===undefined)
{
return res.send("Please Provide Barcode And Temperature.")
}
try{
const user= await User.findByDetails(barcode)
console.log("Value Of user is "+user)
if(user!==null)
{
const temp = await user.givingTemperatureAndTime_Date(tempFromOutside)
res.send({user,temp})
}
else
{
console.log("Inside Else Part.")
const user=new User(req.body)
console.log("Value of User is "+user)
await user.save()
const temp = await user.givingTemperatureAndTime_Date(tempFromOutside)
await user.saveToExcel(user.Temperature)
res.send({user,temp})
}
}catch(e){
console.log(e)
res.status(400).send('Unable to Save Data')
}
})
router.get('/findAll',async (req,res)=>{
try{
const user= await User.find({})
if(user === 0)
{ throw new Error }
res.send(user)
}catch(e){
res.status(400).send('Unable to get Data...!!')
}
})
router.post('/barcode',async(req,res)=>{
const barcode = req.body.BarcodeID
if(barcode==undefined)
{res.send("Please Enter BarcodeID To Search.")}
try{
const name = await User.find({BarcodeID:barcode})
console.log(name)
res.send(name)
}catch(e)
{
res.status(400).send('Unable to get Data from barcode...!!')
}
})
router.get('/test',async(req,res)=>{
var object={first:req.body.startDate,second :req.body.endDate}
if(object.first==undefined && object.second==undefined)
{ res.send("Please Enter Dates to Search.")}
if(object.second ==undefined)
{
object.second=object.first
}
var datetime = require('node-datetime')
var dt = datetime.create(object.first)
var dates = dt.getDatesInRange(datetime.create(object.second))
const rangeOfdates=[]
const user1=dates.map((variable)=>{
var objecttoString=JSON.stringify(variable._now)
const newDateString=objecttoString.slice(1,11)
//Below is ranges of dates in form of string.
rangeOfdates.push(newDateString)
})
console.log("Total Dates in range is form of Array "+rangeOfdates)
//Above Code Gives you a Array which will contain all dates in that range of start Date and
//End date in a form of array. That all dates are in form of string in rangeOfDates Array.
var obj={}
var SimpleArray=[]
try{
var user=await User.find({})
rangeOfdates.forEach(element => {
var user11=user.map((variable)=>{
var naav=variable.name
var user2=variable.Temperature.map((variable2)=>{
if(element==variable2.date)
{
console.log(variable2.temp,variable2.time,variable2.date)
obj={Name:naav,Tempo:variable2.temp,Time:variable2.time, CuurentDate:variable2.date}
SimpleArray.push(obj)
}
})
})
})
res.send(SimpleArray)
}catch(e){
res.status(400).send('Unable to get Data...!!')
}
})
router.post('/maxtemp',async (req,res)=>{
console.log('In maxtemp')
var object={first:req.body.startDate,second :req.body.endDate}
if(object.first==undefined && object.second==undefined)
{
res.send("Please Enter Dates to Search.")
}
if(object.second ==undefined)
{
object.second=object.first
}
var datetime = require('node-datetime')
var dt = datetime.create(object.first)
var dates = dt.getDatesInRange(datetime.create(object.second))
const rangeOfdates=[]
const user1=dates.map((variable)=>{
var objecttoString=JSON.stringify(variable._now)
const newDateString=objecttoString.slice(1,11)
//Below is ranges of dates in form of string.
rangeOfdates.push(newDateString)
})
console.log("Total Dates in range is form of Array "+rangeOfdates)
var obj={}
var obj2={}
var finalobj={}
var SimpleArray=[]
var temparray=[]
var finalArray=[]
try{
var user=await User.find({})
rangeOfdates.forEach(element => {
var user11=user.map((variable)=>{
var naav=variable.name
var user2=variable.Temperature.map((variable2)=>{
if(element==variable2.date)
{
console.log(variable2.temp,variable2.time,variable2.date)
obj={Name:naav,Tempo:variable2.temp,Time:variable2.time, CuurentDate:variable2.date}
SimpleArray.push(obj)
}
})
})
console.log("Value of SimpleArray is "+SimpleArray[0])
var maxTempOfthatDay=Math.max.apply(Math,SimpleArray.map((finalVar)=>{return finalVar.Tempo}))
console.log("Inside Math MAX...!!!",maxTempOfthatDay)
var user111=SimpleArray.map((o)=>{
console.log(o+maxTempOfthatDay)
console.log(o.Tempo==maxTempOfthatDay)
if(o.Tempo==maxTempOfthatDay)
{
console.log("HEllo")
console.log(o.Name,o.Tempo)
finalobj={Name:o.name,Tempo:o.Tempo,CurrentDate:o.CuurentDate,Time:o.Time}
finalArray.push(finalobj)
}
})
})
console.log(finalArray)
res.send(finalArray)
}catch(e){
res.status(400).send('Unable to get Data...!!')
}
})
module.exports=router