-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathstorage.js
46 lines (32 loc) · 951 Bytes
/
storage.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
// storage.js
// Local storage for storing Payment Links created by the app
// ========
const getAll = () => {
return links
}
const put = (pLinkId, pReference, pUrl, pExpiresAt, pStatus, pIsReusable) => {
links.push({ id: pLinkId, reference: pReference, url:pUrl, expiresAt: formatDate(pExpiresAt),
status: pStatus, isReusable: pIsReusable })
}
const update = (pLink) => {
let indexToUpdate = links.findIndex(obj => obj.id === pLink.id);
if(indexToUpdate > -1) {
pLink.expiresAt = formatDate(pLink.expiresAt)
links[indexToUpdate] = pLink;
}
}
// format as dd-mm-yyyy hh:mi
const formatDate = (dateString) => {
const date = new Date(dateString);
const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
timeZone: 'UTC'
};
return date.toLocaleString('nl-NL', options);
}
var links = [];
module.exports = { getAll, put, update }