-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
50 lines (46 loc) · 1.1 KB
/
utils.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
const CONSTANTS = require("./constants");
const cleanObject = (obj, blank = false) => {
for (let key in obj) {
if (obj.hasOwnProperty(key))
if (
obj[key] === null ||
obj[key] === undefined ||
obj[key] === "undefined" ||
(blank && obj[key] === "")
) {
delete obj[key];
}
}
return obj;
};
const removeNull = (obj, exception) => {
for (let key in obj) {
if (!exception.includes(key) && obj[key] === null) {
obj[key] = "";
}
}
return obj;
};
const getShipmentStatusFromCode = (code) => {
switch (code) {
case "NF":
return CONSTANTS.SHIPMENT_STATUS.NO_INFO;
case "IT":
return CONSTANTS.SHIPMENT_STATUS.IN_TRANSIT;
case "UD":
return CONSTANTS.SHIPMENT_STATUS.UNDELIVERED;
case "DL":
return CONSTANTS.SHIPMENT_STATUS.DELIVERED;
case "RL":
return CONSTANTS.SHIPMENT_STATUS.REDIRECTED;
case "RT":
return CONSTANTS.SHIPMENT_STATUS.RTO;
default:
return CONSTANTS.SHIPMENT_STATUS.NO_INFO;
}
};
module.exports = {
removeNull,
cleanObject,
getShipmentStatusFromCode,
};