-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.js
108 lines (97 loc) · 3.55 KB
/
utility.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
module.exports = {
reportParamChecker : function (params) {
var isoDateRegex = /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/i;
if (!params.query.startdate) return {msg: "'startdate' is not available", valid: false}
else if (!params.query.enddate) return {msg: "'enddate' is not available", valid: false}
else if (params.query.userid && params.query.userid.length !== 24) return {msg: "'userid' is not available", valid: false}
else if (!params.query.startdate.match(isoDateRegex))
return {
msg: "startdate '"+params.query.startdate+"' is not in proper ISO date format, ex: 2016-09-19T17:59:59.000Z",
valid: false
};
else if (!params.query.enddate.match(isoDateRegex))
return {
msg: "enddate '"+params.query.enddate+"' is not in proper ISO date format, ex: 2016-09-19T17:59:59.000Z",
valid: false
};
else return {valid: true};
},
reportParamChecker : function (params) {
var isoDateRegex = /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/i;
if (!params.query.startdate) return {msg: "'startdate' is not available", valid: false}
else if (!params.query.enddate) return {msg: "'enddate' is not available", valid: false}
else if (params.query.userid && params.query.userid.length !== 24) return {msg: "'userid' is not available", valid: false}
else if (!params.query.startdate.match(isoDateRegex))
return {
msg: "startdate '"+params.query.startdate+"' is not in proper ISO date format, ex: 2016-09-19T17:59:59.000Z",
valid: false
};
else if (!params.query.enddate.match(isoDateRegex))
return {
msg: "enddate '"+params.query.enddate+"' is not in proper ISO date format, ex: 2016-09-19T17:59:59.000Z",
valid: false
};
else return {valid: true};
},
userListParamChecker: function (params) {
if (!params.query.usertype) {
return { valid : false, msg: "usertype is not available" }
}
else if (!params.query.usertype === "ENTERPRISE" || !params.query.type === "BIKE_MESSENGER") {
return { valid : false, msg: "usertype must be ENTERPRISE or BIKE_MESSENGER" }
}
return { valid : true }
},
getProductNames : function (PackageList) {
var packages = PackageList.map(function (package) {
return "Name: " + package.Item +
", Quantity :" + package.Quantity +
", Price: " + package.Price +
", Weight: " + package.Weight;
});
var package = "";
for (var i = packages.length - 1; i >= 0; i--) {
package += packages[i] + "\n";
}
return package;
},
getDeliveryPersonNames : function (Assets) {
var assetNames = "";
for (var i = Object.keys(Assets).length - 1; i >= 0; i--) {
assetNames = Assets[Object.keys(Assets)[i]].UserName;
}
return assetNames;
},
getClientType : function (client) {
if (client === "USER") {
return "B2C";
} else if (client === "ENTERPRISE") {
return "B2B";
} else if (client === "BIKE_MESSENGER") {
return "DELIVERYMAN"
} else return "UNKNOWN";
},
getJobTaskPreferenceETA : function (eta, jobTaskPreferenceETA) {
function findEta(taskETA) {
return taskETA.Type === eta;
}
return jobTaskPreferenceETA.find(findEta);
},
getTime : function (time) {
var moment = require('moment');
if (time) {
return moment(time).format('LT');
} else return "Not Mentioned";
},
getDate : function (time) {
var moment = require('moment');
if (time) {
return moment(time).format('LL')
} else return "Not Mentioned";
},
getHoursDifference: function (startTime, endTime) {
var moment = require('moment');
if (!startTime || !endTime) return "-"
return moment.duration(moment(startTime).diff(moment(endTime))).asHours();
}
}