groupcore-utils 3.0.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +12 -12
- package/Utils.js +26 -27
- package/communication/mail.js +6 -6
- package/database/crud.js +13 -20
- package/database/init.js +2 -2
- package/package.json +1 -1
- package/rbac/index.js +1 -1
- package/rest/index.js +39 -64
- package/security/encryption.js +2 -2
- package/security/jwt.js +9 -9
- package/test-utils/mocks/response.js +4 -4
- package/timestamp/index.js +8 -8
package/.eslintrc.json
CHANGED
@@ -9,17 +9,17 @@
|
|
9
9
|
"ecmaVersion": 12
|
10
10
|
},
|
11
11
|
"rules": {
|
12
|
-
"no-underscore-dangle": "off",
|
13
|
-
"class-methods-use-this": "off",
|
14
|
-
"no-console": "off",
|
15
|
-
"jest/no-hooks": "off",
|
16
|
-
"jest/no-test-return-statement": "off",
|
17
|
-
"jest/prefer-strict-equal": "off",
|
18
|
-
"consistent-return": "off",
|
19
|
-
"array-callback-return": "off",
|
20
|
-
"no-param-reassign": "off",
|
21
|
-
"no-restricted-syntax": "off",
|
22
|
-
"prefer-destructuring": "off",
|
23
|
-
"no-case-declarations": "off"
|
12
|
+
// "no-underscore-dangle": "off",
|
13
|
+
// "class-methods-use-this": "off",
|
14
|
+
// "no-console": "off",
|
15
|
+
// "jest/no-hooks": "off",
|
16
|
+
// "jest/no-test-return-statement": "off",
|
17
|
+
// "jest/prefer-strict-equal": "off",
|
18
|
+
// "consistent-return": "off",
|
19
|
+
// "array-callback-return": "off",
|
20
|
+
// "no-param-reassign": "off",
|
21
|
+
// "no-restricted-syntax": "off",
|
22
|
+
// "prefer-destructuring": "off",
|
23
|
+
// "no-case-declarations": "off"
|
24
24
|
}
|
25
25
|
}
|
package/Utils.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
const axios = require('axios');
|
2
|
-
const
|
3
|
-
const _isUndefined = require('lodash').isUndefined;
|
2
|
+
const { isEmpty, isUndefined } = require('lodash');
|
4
3
|
|
5
4
|
class Utils {
|
6
5
|
/**
|
@@ -9,7 +8,7 @@ class Utils {
|
|
9
8
|
* @param {string} apiToken - The Core API token to authenticate and authorize access
|
10
9
|
* @param {string} apiUrl - The Core API URL provided during Core setup
|
11
10
|
*/
|
12
|
-
constructor(
|
11
|
+
constructor(projectId, apiToken, apiUrl) {
|
13
12
|
this.project = projectId;
|
14
13
|
this.token = apiToken;
|
15
14
|
this.apiUrl = apiUrl;
|
@@ -23,10 +22,10 @@ class Utils {
|
|
23
22
|
* @param {number} [leadId=null] - The lead ID, if the addLead method is called before submission
|
24
23
|
* @returns {Promise}
|
25
24
|
*/
|
26
|
-
submitForm(
|
25
|
+
submitForm(formData, formId, email, leadId = 0) {
|
27
26
|
return new Promise((resolve, reject) => {
|
28
|
-
if (
|
29
|
-
reject(
|
27
|
+
if (isEmpty(formData) || isEmpty(String(formId)) || isEmpty(email)) {
|
28
|
+
reject(new Error('Missing some required params'));
|
30
29
|
return;
|
31
30
|
}
|
32
31
|
|
@@ -47,7 +46,7 @@ class Utils {
|
|
47
46
|
resolve(response);
|
48
47
|
})
|
49
48
|
.catch(() => {
|
50
|
-
reject(
|
49
|
+
reject(new Error('API error'));
|
51
50
|
});
|
52
51
|
});
|
53
52
|
}
|
@@ -62,22 +61,22 @@ class Utils {
|
|
62
61
|
* @param {string} [attachmentUrl] - The location of the attachment. Optional if hasAttachment is false
|
63
62
|
* @returns {Promise}
|
64
63
|
*/
|
65
|
-
sendMail(
|
64
|
+
sendMail(recipientEmail, subject, htmlBody, attachmentFilename, attachmentUrl, hasAttachment = false) {
|
66
65
|
return new Promise((resolve, reject) => {
|
67
66
|
if (hasAttachment) {
|
68
|
-
if (
|
69
|
-
reject(
|
67
|
+
if (isEmpty(attachmentFilename) || isEmpty(attachmentUrl)) {
|
68
|
+
reject(new Error('Some missing params. If hasAttachment is true, both attachmentFilename and attachmentUrl are required'));
|
70
69
|
return;
|
71
70
|
}
|
72
71
|
}
|
73
72
|
|
74
73
|
if (!hasAttachment && (attachmentFilename || attachmentUrl)) {
|
75
|
-
reject(
|
74
|
+
reject(new Error('If hasAttachment is false, both attachmentFilename and attachmentUrl cannot be accepted'));
|
76
75
|
return;
|
77
76
|
}
|
78
77
|
|
79
|
-
if (
|
80
|
-
reject(
|
78
|
+
if (isEmpty(recipientEmail) || isEmpty(subject) || isEmpty(htmlBody)) {
|
79
|
+
reject(new Error('Missing some required params'));
|
81
80
|
return;
|
82
81
|
}
|
83
82
|
|
@@ -99,7 +98,7 @@ class Utils {
|
|
99
98
|
resolve(response);
|
100
99
|
})
|
101
100
|
.catch(() => {
|
102
|
-
reject(
|
101
|
+
reject(new Error('API error'));
|
103
102
|
});
|
104
103
|
});
|
105
104
|
}
|
@@ -112,10 +111,10 @@ class Utils {
|
|
112
111
|
* @param {string} email - The email address of the lead
|
113
112
|
* @returns {Promise}
|
114
113
|
*/
|
115
|
-
addLead(
|
114
|
+
addLead(firstname, lastname, email, phone) {
|
116
115
|
return new Promise((resolve, reject) => {
|
117
|
-
if (
|
118
|
-
reject(
|
116
|
+
if (isEmpty(firstname) || isEmpty(lastname) || isEmpty(email)) {
|
117
|
+
reject(new Error('Missing some required params'));
|
119
118
|
return;
|
120
119
|
}
|
121
120
|
|
@@ -127,7 +126,7 @@ class Utils {
|
|
127
126
|
firstname,
|
128
127
|
lastname,
|
129
128
|
email,
|
130
|
-
phone,
|
129
|
+
phone: phone || null,
|
131
130
|
},
|
132
131
|
headers: {
|
133
132
|
token: this.token,
|
@@ -137,7 +136,7 @@ class Utils {
|
|
137
136
|
resolve(response);
|
138
137
|
})
|
139
138
|
.catch(() => {
|
140
|
-
reject(
|
139
|
+
reject(new Error('API error'));
|
141
140
|
});
|
142
141
|
});
|
143
142
|
}
|
@@ -147,10 +146,10 @@ class Utils {
|
|
147
146
|
* @param {number} groupId - The ID of the Core inventory group
|
148
147
|
* @returns {Promise}
|
149
148
|
*/
|
150
|
-
async getGroupInventory(
|
149
|
+
async getGroupInventory(groupId) {
|
151
150
|
return new Promise((resolve, reject) => {
|
152
|
-
if (
|
153
|
-
reject(
|
151
|
+
if (isUndefined(groupId)) {
|
152
|
+
reject(new Error('Missing some required params'));
|
154
153
|
return;
|
155
154
|
}
|
156
155
|
|
@@ -165,7 +164,7 @@ class Utils {
|
|
165
164
|
resolve(response.data[0]);
|
166
165
|
})
|
167
166
|
.catch(() => {
|
168
|
-
reject(
|
167
|
+
reject(new Error('API error'));
|
169
168
|
});
|
170
169
|
});
|
171
170
|
}
|
@@ -175,10 +174,10 @@ class Utils {
|
|
175
174
|
* @param {number} groupId - The ID of the Core inventory group
|
176
175
|
* @returns {Promise}
|
177
176
|
*/
|
178
|
-
async getSectionContent(
|
177
|
+
async getSectionContent(groupId) {
|
179
178
|
return new Promise((resolve, reject) => {
|
180
|
-
if (
|
181
|
-
reject(
|
179
|
+
if (isUndefined(groupId)) {
|
180
|
+
reject(new Error('Missing some required params'));
|
182
181
|
return;
|
183
182
|
}
|
184
183
|
|
@@ -193,7 +192,7 @@ class Utils {
|
|
193
192
|
resolve(response.data);
|
194
193
|
})
|
195
194
|
.catch(() => {
|
196
|
-
reject(
|
195
|
+
reject(new Error('API error'));
|
197
196
|
});
|
198
197
|
});
|
199
198
|
}
|
package/communication/mail.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const nodemailer = require(
|
1
|
+
const nodemailer = require('nodemailer');
|
2
2
|
|
3
3
|
module.exports = class {
|
4
4
|
/**
|
@@ -8,14 +8,14 @@ module.exports = class {
|
|
8
8
|
* @param username {string} - smtp username
|
9
9
|
* @param password {password} - smtp password
|
10
10
|
*/
|
11
|
-
constructor(
|
11
|
+
constructor(hostname, port, username, password) {
|
12
12
|
this.hostname = hostname;
|
13
13
|
this.port = port;
|
14
14
|
this.username = username;
|
15
15
|
this.password = password;
|
16
16
|
}
|
17
17
|
|
18
|
-
async
|
18
|
+
async init() {
|
19
19
|
this.transporter = nodemailer.createTransport({
|
20
20
|
host: this.hostname,
|
21
21
|
port: this.port,
|
@@ -40,15 +40,15 @@ module.exports = class {
|
|
40
40
|
* @param from {string} - sender email address
|
41
41
|
* @returns {Promise<*>}
|
42
42
|
*/
|
43
|
-
async send(
|
44
|
-
await this.
|
43
|
+
async send(email, subject, message, from, attachment) {
|
44
|
+
await this.init();
|
45
45
|
|
46
46
|
return this.transporter.sendMail({
|
47
47
|
subject,
|
48
48
|
from,
|
49
49
|
to: email,
|
50
50
|
html: message,
|
51
|
-
attachments: attachment,
|
51
|
+
attachments: attachment || null,
|
52
52
|
});
|
53
53
|
}
|
54
54
|
};
|
package/database/crud.js
CHANGED
@@ -7,7 +7,7 @@ module.exports = class {
|
|
7
7
|
* @param {string} dbTable - name of the table
|
8
8
|
* @param {object} db - the initialised db instance
|
9
9
|
*/
|
10
|
-
constructor(
|
10
|
+
constructor(dbTable, db) {
|
11
11
|
this.dbTable = dbTable;
|
12
12
|
this.db = db;
|
13
13
|
}
|
@@ -16,12 +16,10 @@ module.exports = class {
|
|
16
16
|
* @method create()
|
17
17
|
* @description Insert values into db
|
18
18
|
* @param {Object} data - the key value pair of the data to be inserted into the db
|
19
|
-
* @param {Boolean} unique - if set to true, ensure no duplication of data during creation
|
20
|
-
* @param {Array} ignore - fields to ignore when checking for unique values
|
21
19
|
* @returns {Promise | string | Object} - resolves if successfully and rejects if there's an error
|
22
20
|
*/
|
23
21
|
|
24
|
-
async create(
|
22
|
+
async create(data) {
|
25
23
|
const fields = Object.keys(data).join(',');
|
26
24
|
|
27
25
|
const rawValues = [];
|
@@ -44,9 +42,9 @@ module.exports = class {
|
|
44
42
|
* @param {Array} orderBy - explicitly specify the order, either asc or desc
|
45
43
|
* @returns {Promise}
|
46
44
|
*/
|
47
|
-
read(
|
45
|
+
read(where = false, orderBy = []) {
|
48
46
|
if (where && !_.has(where, 'fields')) {
|
49
|
-
return this.readV1(
|
47
|
+
return this.readV1(where, orderBy);
|
50
48
|
}
|
51
49
|
|
52
50
|
let query;
|
@@ -79,7 +77,7 @@ module.exports = class {
|
|
79
77
|
}
|
80
78
|
|
81
79
|
// should be deprecated soon
|
82
|
-
readV1(
|
80
|
+
readV1(where = false, orderBy = false) {
|
83
81
|
let query;
|
84
82
|
|
85
83
|
if (orderBy) {
|
@@ -104,26 +102,21 @@ module.exports = class {
|
|
104
102
|
* @param {number} id - id in where clause
|
105
103
|
* @returns {Promise}
|
106
104
|
*/
|
107
|
-
update(
|
105
|
+
update(data, id) {
|
108
106
|
// variable to hold the dynamic part of the update sql query
|
109
107
|
let updateQuery = '';
|
110
108
|
|
111
109
|
// set this to be used inside the map function to check when we get to the last index key so that we dont add the comma to the last key in the generated sql query
|
112
|
-
const count = Object.keys(data).length - 1; // adding -1 because we are taking out 'id' in the filter method
|
113
110
|
Object.keys(data)
|
114
111
|
.filter((key) => key !== 'id')
|
115
|
-
.forEach((key
|
116
|
-
|
117
|
-
updateQuery += `${key} = '${escapeQuotes(data[key])}'`;
|
118
|
-
} else {
|
119
|
-
updateQuery += `${key} = '${escapeQuotes(data[key])}', `;
|
120
|
-
}
|
112
|
+
.forEach((key) => {
|
113
|
+
updateQuery += `${key} = '${escapeQuotes(data[key])}', `;
|
121
114
|
return true;
|
122
115
|
});
|
123
116
|
|
124
117
|
const query = `update ${this.dbTable} set ${updateQuery} where id = '${id}'`;
|
125
118
|
|
126
|
-
return this.db.query(query);
|
119
|
+
return this.db.query(query.replace(', where', ' where')); // using replace to remove the last comma before the where clause
|
127
120
|
}
|
128
121
|
|
129
122
|
/**
|
@@ -132,18 +125,18 @@ module.exports = class {
|
|
132
125
|
* @param {number} id - id of data to deleted
|
133
126
|
* @returns {Promise}
|
134
127
|
*/
|
135
|
-
delete(
|
128
|
+
delete(id) {
|
136
129
|
return this.db.query(`delete from ${this.dbTable} where id = '${id}'`);
|
137
130
|
}
|
138
131
|
|
139
132
|
/**
|
140
133
|
* @method query()
|
141
134
|
* @description make a custom db query
|
142
|
-
* @param {string}
|
135
|
+
* @param {string} query - SQL query
|
143
136
|
* @returns {Promise}
|
144
137
|
*/
|
145
138
|
// eslint-disable-next-line class-methods-use-this
|
146
|
-
query(
|
147
|
-
return this.db.query(
|
139
|
+
query(query) {
|
140
|
+
return this.db.query(query);
|
148
141
|
}
|
149
142
|
};
|
package/database/init.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const mysql = require(
|
1
|
+
const mysql = require('mysql');
|
2
2
|
|
3
3
|
module.exports = class {
|
4
4
|
/**
|
@@ -9,7 +9,7 @@ module.exports = class {
|
|
9
9
|
* @param {string} db - db name
|
10
10
|
* @param {string} socket - path to a unix domain socket to connect to. when used host and port are ignored
|
11
11
|
*/
|
12
|
-
constructor(
|
12
|
+
constructor(host, user, password, db, socket) {
|
13
13
|
this.host = host;
|
14
14
|
this.user = user;
|
15
15
|
this.password = password;
|
package/package.json
CHANGED
package/rbac/index.js
CHANGED
package/rest/index.js
CHANGED
@@ -6,19 +6,14 @@ module.exports = {
|
|
6
6
|
* @description send a GET request
|
7
7
|
* @param {string} url - api url
|
8
8
|
* @param {object} headers - headers to be added to request
|
9
|
-
* @returns {
|
9
|
+
* @returns {Promise<any>}
|
10
10
|
*/
|
11
|
-
async get(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
});
|
18
|
-
} catch (err) {
|
19
|
-
console.log('Axios GET Error:', err.message);
|
20
|
-
throw err;
|
21
|
-
}
|
11
|
+
async get(url, headers = []) {
|
12
|
+
return axios({
|
13
|
+
url,
|
14
|
+
headers,
|
15
|
+
method: 'get',
|
16
|
+
});
|
22
17
|
},
|
23
18
|
|
24
19
|
/**
|
@@ -27,20 +22,15 @@ module.exports = {
|
|
27
22
|
* @param {string} url - api url
|
28
23
|
* @param {object} data - payload
|
29
24
|
* @param {object} headers - headers to be added to request
|
30
|
-
* @returns {
|
25
|
+
* @returns {Promise<any>}
|
31
26
|
*/
|
32
|
-
async post(
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
});
|
40
|
-
} catch (err) {
|
41
|
-
console.log('Axios POST Error:', err.message);
|
42
|
-
throw err;
|
43
|
-
}
|
27
|
+
async post(url, data, headers = []) {
|
28
|
+
return axios({
|
29
|
+
url,
|
30
|
+
data,
|
31
|
+
headers,
|
32
|
+
method: 'post',
|
33
|
+
});
|
44
34
|
},
|
45
35
|
|
46
36
|
/**
|
@@ -49,20 +39,15 @@ module.exports = {
|
|
49
39
|
* @param {string} url - api url
|
50
40
|
* @param {object} data - payload
|
51
41
|
* @param {object} headers - headers to be added to request
|
52
|
-
* @returns {
|
42
|
+
* @returns {Promise<any>}
|
53
43
|
*/
|
54
|
-
async put(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
});
|
62
|
-
} catch (err) {
|
63
|
-
console.log('Axios PUT Error:', err.message);
|
64
|
-
throw err;
|
65
|
-
}
|
44
|
+
async put(url, data, headers = []) {
|
45
|
+
return axios({
|
46
|
+
url,
|
47
|
+
data,
|
48
|
+
headers,
|
49
|
+
method: 'put',
|
50
|
+
});
|
66
51
|
},
|
67
52
|
|
68
53
|
/**
|
@@ -71,39 +56,29 @@ module.exports = {
|
|
71
56
|
* @param {string} url - api url
|
72
57
|
* @param {object} data - payload
|
73
58
|
* @param {object} headers - headers to be added to request
|
74
|
-
* @returns {
|
59
|
+
* @returns {Promise<any>}
|
75
60
|
*/
|
76
|
-
async patch(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
});
|
84
|
-
} catch (err) {
|
85
|
-
console.log('Axios PUT Error:', err.message);
|
86
|
-
throw err;
|
87
|
-
}
|
61
|
+
async patch(url, data, headers = []) {
|
62
|
+
return axios({
|
63
|
+
url,
|
64
|
+
data,
|
65
|
+
headers,
|
66
|
+
method: 'patch',
|
67
|
+
});
|
88
68
|
},
|
89
69
|
|
90
70
|
/**
|
91
71
|
* @method delete()
|
92
72
|
* @description send DELETE request
|
93
|
-
* @param {string}
|
73
|
+
* @param {string} url - api url
|
94
74
|
* @param {object} headers - headers to be added to request
|
95
|
-
* @returns {
|
75
|
+
* @returns {Promise<any>}
|
96
76
|
*/
|
97
|
-
async delete(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
});
|
104
|
-
} catch (err) {
|
105
|
-
console.log('Axios DELETE Error:', err.message);
|
106
|
-
throw err;
|
107
|
-
}
|
77
|
+
async delete(url, headers = []) {
|
78
|
+
return axios({
|
79
|
+
url,
|
80
|
+
headers,
|
81
|
+
method: 'delete',
|
82
|
+
});
|
108
83
|
},
|
109
84
|
};
|
package/security/encryption.js
CHANGED
@@ -14,7 +14,7 @@ module.exports = class {
|
|
14
14
|
* @param {string} text - text to be hashed
|
15
15
|
* @returns {*}
|
16
16
|
*/
|
17
|
-
hash(
|
17
|
+
hash(text) {
|
18
18
|
return bcrypt.hashSync(text, bcrypt.genSaltSync(this.saltRounds));
|
19
19
|
}
|
20
20
|
|
@@ -25,7 +25,7 @@ module.exports = class {
|
|
25
25
|
* @param {string} text - the text to be compared with the hash
|
26
26
|
* @returns {*}
|
27
27
|
*/
|
28
|
-
verify(
|
28
|
+
static verify(hash, text) {
|
29
29
|
return bcrypt.compareSync(text, hash);
|
30
30
|
}
|
31
31
|
};
|
package/security/jwt.js
CHANGED
@@ -3,10 +3,10 @@ const jwt = require('jsonwebtoken');
|
|
3
3
|
module.exports = class {
|
4
4
|
/**
|
5
5
|
* @description constructor
|
6
|
-
* @param {string}
|
6
|
+
* @param {string} key - jwt key
|
7
7
|
*/
|
8
|
-
constructor(
|
9
|
-
this.
|
8
|
+
constructor(key) {
|
9
|
+
this.key = key;
|
10
10
|
}
|
11
11
|
|
12
12
|
/**
|
@@ -15,17 +15,17 @@ module.exports = class {
|
|
15
15
|
* @param {object} payload - payload to be tokenized
|
16
16
|
* @returns {*}
|
17
17
|
*/
|
18
|
-
|
19
|
-
return jwt.sign(payload, this.
|
18
|
+
sign(payload) {
|
19
|
+
return jwt.sign(payload, this.key);
|
20
20
|
}
|
21
21
|
|
22
22
|
/**
|
23
23
|
* @method jwtDecode()
|
24
24
|
* @description decode a JWT token
|
25
25
|
* @param {string} token - JWT token to be decoded
|
26
|
-
* @returns {{payload: any, signature: *, header: *}
|
26
|
+
* @returns {{payload: any, signature: *, header: *}}
|
27
27
|
*/
|
28
|
-
|
28
|
+
static decode(token) {
|
29
29
|
return jwt.decode(token);
|
30
30
|
}
|
31
31
|
|
@@ -35,7 +35,7 @@ module.exports = class {
|
|
35
35
|
* @param {string} token - token to be verified
|
36
36
|
* @returns {*}
|
37
37
|
*/
|
38
|
-
|
39
|
-
return jwt.verify(token, this.
|
38
|
+
verify(token) {
|
39
|
+
return jwt.verify(token, this.key);
|
40
40
|
}
|
41
41
|
};
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module.exports = class {
|
2
2
|
constructor() {
|
3
|
-
jest.spyOn(this,
|
4
|
-
jest.spyOn(this,
|
3
|
+
jest.spyOn(this, 'send').mockImplementation((body) => body);
|
4
|
+
jest.spyOn(this, 'status').mockImplementation(() => this);
|
5
5
|
}
|
6
6
|
|
7
|
-
send() {
|
7
|
+
static send() {
|
8
8
|
return true;
|
9
9
|
}
|
10
10
|
|
11
|
-
status() {
|
11
|
+
static status() {
|
12
12
|
return true;
|
13
13
|
}
|
14
14
|
};
|
package/timestamp/index.js
CHANGED
@@ -6,7 +6,7 @@ module.exports = class {
|
|
6
6
|
* @description returns the present unix timestamp
|
7
7
|
* @returns {number}
|
8
8
|
*/
|
9
|
-
now() {
|
9
|
+
static now() {
|
10
10
|
return moment().unix();
|
11
11
|
}
|
12
12
|
|
@@ -17,7 +17,7 @@ module.exports = class {
|
|
17
17
|
* @param {string} format - the format to use, default is 'MMMM DD, YYYY'
|
18
18
|
* @returns {string}
|
19
19
|
*/
|
20
|
-
unixToDate(
|
20
|
+
static unixToDate(unix, format) {
|
21
21
|
return moment.unix(unix).format(format);
|
22
22
|
}
|
23
23
|
|
@@ -28,7 +28,7 @@ module.exports = class {
|
|
28
28
|
* @param {string} format - the format of the date
|
29
29
|
* @returns {number}
|
30
30
|
*/
|
31
|
-
dateToUnix(
|
31
|
+
static dateToUnix(date, format) {
|
32
32
|
return moment(date, format).valueOf() / 1000;
|
33
33
|
}
|
34
34
|
|
@@ -38,7 +38,7 @@ module.exports = class {
|
|
38
38
|
* @param {string} unix - unix timestamp
|
39
39
|
* @returns {number}
|
40
40
|
*/
|
41
|
-
unixToStartOfDay(unix) {
|
41
|
+
static unixToStartOfDay(unix) {
|
42
42
|
return new Date(unix * 1000).setHours(0, 0, 0, 0) / 1000;
|
43
43
|
}
|
44
44
|
|
@@ -48,7 +48,7 @@ module.exports = class {
|
|
48
48
|
* @param {string} unix - unix timestamp
|
49
49
|
* @returns {number}
|
50
50
|
*/
|
51
|
-
unixToEndOfDay(unix) {
|
51
|
+
static unixToEndOfDay(unix) {
|
52
52
|
return new Date(unix * 1000).setHours(23, 59, 59, 999) / 1000;
|
53
53
|
}
|
54
54
|
|
@@ -58,8 +58,8 @@ module.exports = class {
|
|
58
58
|
* @param {string} time - time to be converted
|
59
59
|
* @returns {number}
|
60
60
|
*/
|
61
|
-
toSeconds(time) {
|
62
|
-
|
63
|
-
return
|
61
|
+
static toSeconds(time) {
|
62
|
+
const splitTime = time.split(':');
|
63
|
+
return splitTime[0] * 3600 + splitTime[1] * 60;
|
64
64
|
}
|
65
65
|
};
|