-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
47 lines (42 loc) · 1.06 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
const stringHasValue = (str) => {
return str && str !== null && str !== undefined && str !== "";
};
const arrayHasValue = (arr) => {
return arr && arr.length > 0;
};
const booleanHasValue = (val) => {
return val === true || val === false;
};
const objectHasMethod = (obj, methodName) => {
return obj[methodName] && typeof obj[methodName] === "function";
};
const enrichDataWithDBProps = (obj, mode = "create") => {
if (mode === "create") {
return {
...obj,
createdAt: (function () {
const d = new Date();
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
})(),
updatedAt: (function () {
const d = new Date();
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
})(),
};
}
// for updates
return {
...obj,
updatedAt: (function () {
const d = new Date();
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
})(),
};
};
module.exports = {
stringHasValue,
arrayHasValue,
booleanHasValue,
objectHasMethod,
enrichDataWithDBProps,
};