forked from louislam/uptime-kuma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincident.js
More file actions
48 lines (43 loc) · 1.19 KB
/
incident.js
File metadata and controls
48 lines (43 loc) · 1.19 KB
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
const { BeanModel } = require("redbean-node/dist/bean-model");
const { R } = require("redbean-node");
const dayjs = require("dayjs");
class Incident extends BeanModel {
/**
* Resolve the incident and mark it as inactive
* @returns {Promise<void>}
*/
async resolve() {
this.active = false;
this.pin = false;
this.lastUpdatedDate = R.isoDateTime(dayjs.utc());
await R.store(this);
}
/**
* Return an object that ready to parse to JSON for public
* Only show necessary data to public
* @returns {object} Object ready to parse
*/
toPublicJSON() {
return {
id: this.id,
style: this.style,
title: this.title,
content: this.content,
pin: !!this.pin,
active: !!this.active,
createdDate: this.createdDate,
lastUpdatedDate: this.lastUpdatedDate,
};
}
/**
* Return full object for admin use
* @returns {object} Object ready to parse
*/
toJSON() {
return {
...this.toPublicJSON(),
status_page_id: this.status_page_id,
};
}
}
module.exports = Incident;