@checkstack/incident-backend 1.0.2 → 1.1.1
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/CHANGELOG.md +70 -0
- package/drizzle/0002_brown_thena.sql +9 -0
- package/drizzle/meta/0002_snapshot.json +278 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +18 -18
- package/src/router.ts +29 -0
- package/src/schema.ts +14 -0
- package/src/service.ts +47 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# @checkstack/incident-backend
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9016526]
|
|
8
|
+
- @checkstack/common@0.10.0
|
|
9
|
+
- @checkstack/auth-common@0.7.0
|
|
10
|
+
- @checkstack/catalog-common@2.2.0
|
|
11
|
+
- @checkstack/incident-common@1.2.0
|
|
12
|
+
- @checkstack/notification-common@1.1.0
|
|
13
|
+
- @checkstack/integration-common@0.4.0
|
|
14
|
+
- @checkstack/backend-api@0.15.2
|
|
15
|
+
- @checkstack/catalog-backend@1.1.1
|
|
16
|
+
- @checkstack/command-backend@0.1.26
|
|
17
|
+
- @checkstack/integration-backend@0.1.26
|
|
18
|
+
- @checkstack/signal-common@0.2.3
|
|
19
|
+
- @checkstack/cache-api@0.3.1
|
|
20
|
+
- @checkstack/cache-utils@0.2.6
|
|
21
|
+
|
|
22
|
+
## 1.1.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- 1ef2e79: feat: hotlinks on incidents/maintenances and additional links on systems
|
|
27
|
+
|
|
28
|
+
Users with `manage` access on an incident, maintenance, or system can now
|
|
29
|
+
attach free-form URL "hotlinks" — Jira tickets, runbooks, dashboards, ticket
|
|
30
|
+
tools, etc. — alongside the existing fields.
|
|
31
|
+
|
|
32
|
+
- **Incidents** & **maintenances**: links live on the entity itself and are
|
|
33
|
+
surfaced both in the editor dialog and on the public detail page. Two new
|
|
34
|
+
RPC procedures per plugin (`addLink`, `removeLink`) gated behind the
|
|
35
|
+
existing `manage` access rule. Links are returned as part of
|
|
36
|
+
`getIncident` / `getMaintenance` and cache-invalidated on every link
|
|
37
|
+
mutation.
|
|
38
|
+
- **Systems**: a parallel `system_links` table with `getSystemLinks`,
|
|
39
|
+
`addSystemLink`, `removeSystemLink` procedures. Surfaced inside the
|
|
40
|
+
system editor (next to contacts) and on the read-only system detail
|
|
41
|
+
sidebar. Cache-scoped per-system so list endpoints remain hot.
|
|
42
|
+
- **Shared UI**: a `LinksEditor` component in `@checkstack/ui` does the
|
|
43
|
+
presentation; the three plugins each own their own RPC wiring.
|
|
44
|
+
|
|
45
|
+
Database changes ship as additive migrations (new `incident_links`,
|
|
46
|
+
`maintenance_links`, `system_links` tables, all FK-cascaded on parent
|
|
47
|
+
delete). No existing columns or rows are touched.
|
|
48
|
+
|
|
49
|
+
The system incident and maintenance history pages now sort by relevance:
|
|
50
|
+
active entries (non-`resolved` incidents, `scheduled` or `in_progress`
|
|
51
|
+
maintenances) appear at the top, with creation date descending as the
|
|
52
|
+
tiebreaker.
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- Updated dependencies [42abfff]
|
|
57
|
+
- Updated dependencies [1ef2e79]
|
|
58
|
+
- Updated dependencies [aa89bc5]
|
|
59
|
+
- @checkstack/common@0.9.0
|
|
60
|
+
- @checkstack/incident-common@1.1.0
|
|
61
|
+
- @checkstack/catalog-common@2.1.0
|
|
62
|
+
- @checkstack/catalog-backend@1.1.0
|
|
63
|
+
- @checkstack/cache-api@0.3.0
|
|
64
|
+
- @checkstack/auth-common@0.6.6
|
|
65
|
+
- @checkstack/backend-api@0.15.1
|
|
66
|
+
- @checkstack/command-backend@0.1.25
|
|
67
|
+
- @checkstack/integration-backend@0.1.25
|
|
68
|
+
- @checkstack/integration-common@0.3.2
|
|
69
|
+
- @checkstack/notification-common@1.0.2
|
|
70
|
+
- @checkstack/signal-common@0.2.2
|
|
71
|
+
- @checkstack/cache-utils@0.2.5
|
|
72
|
+
|
|
3
73
|
## 1.0.2
|
|
4
74
|
|
|
5
75
|
### Patch Changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CREATE TABLE "incident_links" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"incident_id" text NOT NULL,
|
|
4
|
+
"label" text,
|
|
5
|
+
"url" text NOT NULL,
|
|
6
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
7
|
+
);
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "incident_links" ADD CONSTRAINT "incident_links_incident_id_incidents_id_fk" FOREIGN KEY ("incident_id") REFERENCES "incidents"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "0c166fdf-4881-4230-a0b3-50b6c4b89e16",
|
|
3
|
+
"prevId": "e53ec0d1-e4c4-45cb-b45d-7ac3c1317744",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"public.incident_links": {
|
|
8
|
+
"name": "incident_links",
|
|
9
|
+
"schema": "",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "text",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
"incident_id": {
|
|
18
|
+
"name": "incident_id",
|
|
19
|
+
"type": "text",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": true
|
|
22
|
+
},
|
|
23
|
+
"label": {
|
|
24
|
+
"name": "label",
|
|
25
|
+
"type": "text",
|
|
26
|
+
"primaryKey": false,
|
|
27
|
+
"notNull": false
|
|
28
|
+
},
|
|
29
|
+
"url": {
|
|
30
|
+
"name": "url",
|
|
31
|
+
"type": "text",
|
|
32
|
+
"primaryKey": false,
|
|
33
|
+
"notNull": true
|
|
34
|
+
},
|
|
35
|
+
"created_at": {
|
|
36
|
+
"name": "created_at",
|
|
37
|
+
"type": "timestamp",
|
|
38
|
+
"primaryKey": false,
|
|
39
|
+
"notNull": true,
|
|
40
|
+
"default": "now()"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"indexes": {},
|
|
44
|
+
"foreignKeys": {
|
|
45
|
+
"incident_links_incident_id_incidents_id_fk": {
|
|
46
|
+
"name": "incident_links_incident_id_incidents_id_fk",
|
|
47
|
+
"tableFrom": "incident_links",
|
|
48
|
+
"tableTo": "incidents",
|
|
49
|
+
"columnsFrom": [
|
|
50
|
+
"incident_id"
|
|
51
|
+
],
|
|
52
|
+
"columnsTo": [
|
|
53
|
+
"id"
|
|
54
|
+
],
|
|
55
|
+
"onDelete": "cascade",
|
|
56
|
+
"onUpdate": "no action"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"compositePrimaryKeys": {},
|
|
60
|
+
"uniqueConstraints": {},
|
|
61
|
+
"policies": {},
|
|
62
|
+
"checkConstraints": {},
|
|
63
|
+
"isRLSEnabled": false
|
|
64
|
+
},
|
|
65
|
+
"public.incident_systems": {
|
|
66
|
+
"name": "incident_systems",
|
|
67
|
+
"schema": "",
|
|
68
|
+
"columns": {
|
|
69
|
+
"incident_id": {
|
|
70
|
+
"name": "incident_id",
|
|
71
|
+
"type": "text",
|
|
72
|
+
"primaryKey": false,
|
|
73
|
+
"notNull": true
|
|
74
|
+
},
|
|
75
|
+
"system_id": {
|
|
76
|
+
"name": "system_id",
|
|
77
|
+
"type": "text",
|
|
78
|
+
"primaryKey": false,
|
|
79
|
+
"notNull": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"indexes": {},
|
|
83
|
+
"foreignKeys": {
|
|
84
|
+
"incident_systems_incident_id_incidents_id_fk": {
|
|
85
|
+
"name": "incident_systems_incident_id_incidents_id_fk",
|
|
86
|
+
"tableFrom": "incident_systems",
|
|
87
|
+
"tableTo": "incidents",
|
|
88
|
+
"columnsFrom": [
|
|
89
|
+
"incident_id"
|
|
90
|
+
],
|
|
91
|
+
"columnsTo": [
|
|
92
|
+
"id"
|
|
93
|
+
],
|
|
94
|
+
"onDelete": "cascade",
|
|
95
|
+
"onUpdate": "no action"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"compositePrimaryKeys": {
|
|
99
|
+
"incident_systems_incident_id_system_id_pk": {
|
|
100
|
+
"name": "incident_systems_incident_id_system_id_pk",
|
|
101
|
+
"columns": [
|
|
102
|
+
"incident_id",
|
|
103
|
+
"system_id"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"uniqueConstraints": {},
|
|
108
|
+
"policies": {},
|
|
109
|
+
"checkConstraints": {},
|
|
110
|
+
"isRLSEnabled": false
|
|
111
|
+
},
|
|
112
|
+
"public.incident_updates": {
|
|
113
|
+
"name": "incident_updates",
|
|
114
|
+
"schema": "",
|
|
115
|
+
"columns": {
|
|
116
|
+
"id": {
|
|
117
|
+
"name": "id",
|
|
118
|
+
"type": "text",
|
|
119
|
+
"primaryKey": true,
|
|
120
|
+
"notNull": true
|
|
121
|
+
},
|
|
122
|
+
"incident_id": {
|
|
123
|
+
"name": "incident_id",
|
|
124
|
+
"type": "text",
|
|
125
|
+
"primaryKey": false,
|
|
126
|
+
"notNull": true
|
|
127
|
+
},
|
|
128
|
+
"message": {
|
|
129
|
+
"name": "message",
|
|
130
|
+
"type": "text",
|
|
131
|
+
"primaryKey": false,
|
|
132
|
+
"notNull": true
|
|
133
|
+
},
|
|
134
|
+
"status_change": {
|
|
135
|
+
"name": "status_change",
|
|
136
|
+
"type": "incident_status",
|
|
137
|
+
"typeSchema": "public",
|
|
138
|
+
"primaryKey": false,
|
|
139
|
+
"notNull": false
|
|
140
|
+
},
|
|
141
|
+
"created_at": {
|
|
142
|
+
"name": "created_at",
|
|
143
|
+
"type": "timestamp",
|
|
144
|
+
"primaryKey": false,
|
|
145
|
+
"notNull": true,
|
|
146
|
+
"default": "now()"
|
|
147
|
+
},
|
|
148
|
+
"created_by": {
|
|
149
|
+
"name": "created_by",
|
|
150
|
+
"type": "text",
|
|
151
|
+
"primaryKey": false,
|
|
152
|
+
"notNull": false
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"indexes": {},
|
|
156
|
+
"foreignKeys": {
|
|
157
|
+
"incident_updates_incident_id_incidents_id_fk": {
|
|
158
|
+
"name": "incident_updates_incident_id_incidents_id_fk",
|
|
159
|
+
"tableFrom": "incident_updates",
|
|
160
|
+
"tableTo": "incidents",
|
|
161
|
+
"columnsFrom": [
|
|
162
|
+
"incident_id"
|
|
163
|
+
],
|
|
164
|
+
"columnsTo": [
|
|
165
|
+
"id"
|
|
166
|
+
],
|
|
167
|
+
"onDelete": "cascade",
|
|
168
|
+
"onUpdate": "no action"
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"compositePrimaryKeys": {},
|
|
172
|
+
"uniqueConstraints": {},
|
|
173
|
+
"policies": {},
|
|
174
|
+
"checkConstraints": {},
|
|
175
|
+
"isRLSEnabled": false
|
|
176
|
+
},
|
|
177
|
+
"public.incidents": {
|
|
178
|
+
"name": "incidents",
|
|
179
|
+
"schema": "",
|
|
180
|
+
"columns": {
|
|
181
|
+
"id": {
|
|
182
|
+
"name": "id",
|
|
183
|
+
"type": "text",
|
|
184
|
+
"primaryKey": true,
|
|
185
|
+
"notNull": true
|
|
186
|
+
},
|
|
187
|
+
"title": {
|
|
188
|
+
"name": "title",
|
|
189
|
+
"type": "text",
|
|
190
|
+
"primaryKey": false,
|
|
191
|
+
"notNull": true
|
|
192
|
+
},
|
|
193
|
+
"description": {
|
|
194
|
+
"name": "description",
|
|
195
|
+
"type": "text",
|
|
196
|
+
"primaryKey": false,
|
|
197
|
+
"notNull": false
|
|
198
|
+
},
|
|
199
|
+
"status": {
|
|
200
|
+
"name": "status",
|
|
201
|
+
"type": "incident_status",
|
|
202
|
+
"typeSchema": "public",
|
|
203
|
+
"primaryKey": false,
|
|
204
|
+
"notNull": true,
|
|
205
|
+
"default": "'investigating'"
|
|
206
|
+
},
|
|
207
|
+
"severity": {
|
|
208
|
+
"name": "severity",
|
|
209
|
+
"type": "incident_severity",
|
|
210
|
+
"typeSchema": "public",
|
|
211
|
+
"primaryKey": false,
|
|
212
|
+
"notNull": true,
|
|
213
|
+
"default": "'major'"
|
|
214
|
+
},
|
|
215
|
+
"suppress_notifications": {
|
|
216
|
+
"name": "suppress_notifications",
|
|
217
|
+
"type": "boolean",
|
|
218
|
+
"primaryKey": false,
|
|
219
|
+
"notNull": true,
|
|
220
|
+
"default": false
|
|
221
|
+
},
|
|
222
|
+
"created_at": {
|
|
223
|
+
"name": "created_at",
|
|
224
|
+
"type": "timestamp",
|
|
225
|
+
"primaryKey": false,
|
|
226
|
+
"notNull": true,
|
|
227
|
+
"default": "now()"
|
|
228
|
+
},
|
|
229
|
+
"updated_at": {
|
|
230
|
+
"name": "updated_at",
|
|
231
|
+
"type": "timestamp",
|
|
232
|
+
"primaryKey": false,
|
|
233
|
+
"notNull": true,
|
|
234
|
+
"default": "now()"
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
"indexes": {},
|
|
238
|
+
"foreignKeys": {},
|
|
239
|
+
"compositePrimaryKeys": {},
|
|
240
|
+
"uniqueConstraints": {},
|
|
241
|
+
"policies": {},
|
|
242
|
+
"checkConstraints": {},
|
|
243
|
+
"isRLSEnabled": false
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"enums": {
|
|
247
|
+
"public.incident_severity": {
|
|
248
|
+
"name": "incident_severity",
|
|
249
|
+
"schema": "public",
|
|
250
|
+
"values": [
|
|
251
|
+
"minor",
|
|
252
|
+
"major",
|
|
253
|
+
"critical"
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
"public.incident_status": {
|
|
257
|
+
"name": "incident_status",
|
|
258
|
+
"schema": "public",
|
|
259
|
+
"values": [
|
|
260
|
+
"investigating",
|
|
261
|
+
"identified",
|
|
262
|
+
"fixing",
|
|
263
|
+
"monitoring",
|
|
264
|
+
"resolved"
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
"schemas": {},
|
|
269
|
+
"sequences": {},
|
|
270
|
+
"roles": {},
|
|
271
|
+
"policies": {},
|
|
272
|
+
"views": {},
|
|
273
|
+
"_meta": {
|
|
274
|
+
"columns": {},
|
|
275
|
+
"schemas": {},
|
|
276
|
+
"tables": {}
|
|
277
|
+
}
|
|
278
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/incident-backend",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -14,28 +14,28 @@
|
|
|
14
14
|
"lint:code": "eslint . --max-warnings 0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@checkstack/backend-api": "0.
|
|
18
|
-
"@checkstack/cache-api": "0.
|
|
19
|
-
"@checkstack/cache-utils": "0.2.
|
|
20
|
-
"@checkstack/incident-common": "1.
|
|
21
|
-
"@checkstack/catalog-common": "2.
|
|
22
|
-
"@checkstack/catalog-backend": "1.0
|
|
23
|
-
"@checkstack/notification-common": "1.0.
|
|
24
|
-
"@checkstack/auth-common": "0.6.
|
|
25
|
-
"@checkstack/command-backend": "0.1.
|
|
26
|
-
"@checkstack/signal-common": "0.2.
|
|
27
|
-
"@checkstack/integration-backend": "0.1.
|
|
28
|
-
"@checkstack/integration-common": "0.3.
|
|
29
|
-
"@checkstack/common": "0.
|
|
17
|
+
"@checkstack/backend-api": "0.15.1",
|
|
18
|
+
"@checkstack/cache-api": "0.3.0",
|
|
19
|
+
"@checkstack/cache-utils": "0.2.5",
|
|
20
|
+
"@checkstack/incident-common": "1.1.0",
|
|
21
|
+
"@checkstack/catalog-common": "2.1.0",
|
|
22
|
+
"@checkstack/catalog-backend": "1.1.0",
|
|
23
|
+
"@checkstack/notification-common": "1.0.2",
|
|
24
|
+
"@checkstack/auth-common": "0.6.6",
|
|
25
|
+
"@checkstack/command-backend": "0.1.25",
|
|
26
|
+
"@checkstack/signal-common": "0.2.2",
|
|
27
|
+
"@checkstack/integration-backend": "0.1.25",
|
|
28
|
+
"@checkstack/integration-common": "0.3.2",
|
|
29
|
+
"@checkstack/common": "0.9.0",
|
|
30
30
|
"drizzle-orm": "^0.45.0",
|
|
31
31
|
"zod": "^4.2.1",
|
|
32
32
|
"@orpc/server": "^1.13.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@checkstack/drizzle-helper": "0.0.
|
|
36
|
-
"@checkstack/scripts": "0.1
|
|
37
|
-
"@checkstack/test-utils-backend": "0.1.
|
|
38
|
-
"@checkstack/tsconfig": "0.0.
|
|
35
|
+
"@checkstack/drizzle-helper": "0.0.5",
|
|
36
|
+
"@checkstack/scripts": "0.3.1",
|
|
37
|
+
"@checkstack/test-utils-backend": "0.1.25",
|
|
38
|
+
"@checkstack/tsconfig": "0.0.7",
|
|
39
39
|
"@types/bun": "^1.0.0",
|
|
40
40
|
"drizzle-kit": "^0.31.10",
|
|
41
41
|
"typescript": "^5.0.0"
|
package/src/router.ts
CHANGED
|
@@ -392,5 +392,34 @@ export function createRouter(
|
|
|
392
392
|
);
|
|
393
393
|
return { suppressed };
|
|
394
394
|
}),
|
|
395
|
+
|
|
396
|
+
addLink: os.addLink.handler(async ({ input }) => {
|
|
397
|
+
// Verify incident exists so the FK violation surfaces as NOT_FOUND.
|
|
398
|
+
const incident = await service.getIncident(input.incidentId);
|
|
399
|
+
if (!incident) {
|
|
400
|
+
throw new ORPCError("NOT_FOUND", { message: "Incident not found" });
|
|
401
|
+
}
|
|
402
|
+
const link = await service.addLink(input);
|
|
403
|
+
await cache.invalidateForMutation({
|
|
404
|
+
incidentId: incident.id,
|
|
405
|
+
systemIds: incident.systemIds,
|
|
406
|
+
});
|
|
407
|
+
return link;
|
|
408
|
+
}),
|
|
409
|
+
|
|
410
|
+
removeLink: os.removeLink.handler(async ({ input }) => {
|
|
411
|
+
const incidentId = await service.removeLink(input.id);
|
|
412
|
+
if (!incidentId) {
|
|
413
|
+
return { success: false };
|
|
414
|
+
}
|
|
415
|
+
const incident = await service.getIncident(incidentId);
|
|
416
|
+
if (incident) {
|
|
417
|
+
await cache.invalidateForMutation({
|
|
418
|
+
incidentId,
|
|
419
|
+
systemIds: incident.systemIds,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
return { success: true };
|
|
423
|
+
}),
|
|
395
424
|
});
|
|
396
425
|
}
|
package/src/schema.ts
CHANGED
|
@@ -72,3 +72,17 @@ export const incidentUpdates = pgTable("incident_updates", {
|
|
|
72
72
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
73
73
|
createdBy: text("created_by"),
|
|
74
74
|
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Hotlinks attached to an incident — e.g. a Jira ticket, runbook, or chat
|
|
78
|
+
* thread. Free-form URL + optional human label.
|
|
79
|
+
*/
|
|
80
|
+
export const incidentLinks = pgTable("incident_links", {
|
|
81
|
+
id: text("id").primaryKey(),
|
|
82
|
+
incidentId: text("incident_id")
|
|
83
|
+
.notNull()
|
|
84
|
+
.references(() => incidents.id, { onDelete: "cascade" }),
|
|
85
|
+
label: text("label"),
|
|
86
|
+
url: text("url").notNull(),
|
|
87
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
88
|
+
});
|
package/src/service.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { eq, and, inArray, ne } from "drizzle-orm";
|
|
2
2
|
import type { SafeDatabase } from "@checkstack/backend-api";
|
|
3
3
|
import * as schema from "./schema";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
incidents,
|
|
6
|
+
incidentSystems,
|
|
7
|
+
incidentUpdates,
|
|
8
|
+
incidentLinks,
|
|
9
|
+
} from "./schema";
|
|
5
10
|
import type {
|
|
6
11
|
IncidentWithSystems,
|
|
7
12
|
IncidentDetail,
|
|
8
13
|
IncidentUpdate,
|
|
14
|
+
IncidentLink,
|
|
15
|
+
AddIncidentLinkInput,
|
|
9
16
|
CreateIncidentInput,
|
|
10
17
|
UpdateIncidentInput,
|
|
11
18
|
AddIncidentUpdateInput,
|
|
@@ -100,6 +107,11 @@ export class IncidentService {
|
|
|
100
107
|
.from(incidentUpdates)
|
|
101
108
|
.where(eq(incidentUpdates.incidentId, id));
|
|
102
109
|
|
|
110
|
+
const links = await this.db
|
|
111
|
+
.select()
|
|
112
|
+
.from(incidentLinks)
|
|
113
|
+
.where(eq(incidentLinks.incidentId, id));
|
|
114
|
+
|
|
103
115
|
return {
|
|
104
116
|
...incident,
|
|
105
117
|
description: incident.description ?? undefined,
|
|
@@ -109,6 +121,7 @@ export class IncidentService {
|
|
|
109
121
|
statusChange: u.statusChange ?? undefined,
|
|
110
122
|
createdBy: u.createdBy ?? undefined,
|
|
111
123
|
})),
|
|
124
|
+
links,
|
|
112
125
|
};
|
|
113
126
|
}
|
|
114
127
|
|
|
@@ -332,6 +345,39 @@ export class IncidentService {
|
|
|
332
345
|
.where(eq(incidentSystems.systemId, systemId));
|
|
333
346
|
}
|
|
334
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Add a hotlink to an incident.
|
|
350
|
+
*/
|
|
351
|
+
async addLink(input: AddIncidentLinkInput): Promise<IncidentLink> {
|
|
352
|
+
const id = generateId();
|
|
353
|
+
await this.db.insert(incidentLinks).values({
|
|
354
|
+
id,
|
|
355
|
+
incidentId: input.incidentId,
|
|
356
|
+
label: input.label,
|
|
357
|
+
url: input.url,
|
|
358
|
+
});
|
|
359
|
+
const [row] = await this.db
|
|
360
|
+
.select()
|
|
361
|
+
.from(incidentLinks)
|
|
362
|
+
.where(eq(incidentLinks.id, id));
|
|
363
|
+
return row;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Remove a hotlink. Returns the parent incidentId so the caller can
|
|
368
|
+
* invalidate the right cache entry, or undefined if the link did not
|
|
369
|
+
* exist.
|
|
370
|
+
*/
|
|
371
|
+
async removeLink(id: string): Promise<string | undefined> {
|
|
372
|
+
const [existing] = await this.db
|
|
373
|
+
.select()
|
|
374
|
+
.from(incidentLinks)
|
|
375
|
+
.where(eq(incidentLinks.id, id));
|
|
376
|
+
if (!existing) return undefined;
|
|
377
|
+
await this.db.delete(incidentLinks).where(eq(incidentLinks.id, id));
|
|
378
|
+
return existing.incidentId;
|
|
379
|
+
}
|
|
380
|
+
|
|
335
381
|
/**
|
|
336
382
|
* Check if a system has an active incident with notification suppression enabled.
|
|
337
383
|
* An incident is considered "active" if its status is NOT "resolved".
|