@checkstack/maintenance-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_daffy_madelyne_pryor.sql +9 -0
- package/drizzle/meta/0002_snapshot.json +272 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +18 -18
- package/src/router.ts +28 -0
- package/src/schema.ts +14 -0
- package/src/service.ts +47 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# @checkstack/maintenance-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/maintenance-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/maintenance-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 "maintenance_links" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"maintenance_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 "maintenance_links" ADD CONSTRAINT "maintenance_links_maintenance_id_maintenances_id_fk" FOREIGN KEY ("maintenance_id") REFERENCES "maintenances"("id") ON DELETE cascade ON UPDATE no action;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "cf6882ac-18e6-4e98-9119-ae0343e8c1a8",
|
|
3
|
+
"prevId": "d0a42a3a-4685-408b-8ad9-e2c0ac19e8a2",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"public.maintenance_links": {
|
|
8
|
+
"name": "maintenance_links",
|
|
9
|
+
"schema": "",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "text",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
"maintenance_id": {
|
|
18
|
+
"name": "maintenance_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
|
+
"maintenance_links_maintenance_id_maintenances_id_fk": {
|
|
46
|
+
"name": "maintenance_links_maintenance_id_maintenances_id_fk",
|
|
47
|
+
"tableFrom": "maintenance_links",
|
|
48
|
+
"tableTo": "maintenances",
|
|
49
|
+
"columnsFrom": [
|
|
50
|
+
"maintenance_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.maintenance_systems": {
|
|
66
|
+
"name": "maintenance_systems",
|
|
67
|
+
"schema": "",
|
|
68
|
+
"columns": {
|
|
69
|
+
"maintenance_id": {
|
|
70
|
+
"name": "maintenance_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
|
+
"maintenance_systems_maintenance_id_maintenances_id_fk": {
|
|
85
|
+
"name": "maintenance_systems_maintenance_id_maintenances_id_fk",
|
|
86
|
+
"tableFrom": "maintenance_systems",
|
|
87
|
+
"tableTo": "maintenances",
|
|
88
|
+
"columnsFrom": [
|
|
89
|
+
"maintenance_id"
|
|
90
|
+
],
|
|
91
|
+
"columnsTo": [
|
|
92
|
+
"id"
|
|
93
|
+
],
|
|
94
|
+
"onDelete": "cascade",
|
|
95
|
+
"onUpdate": "no action"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"compositePrimaryKeys": {
|
|
99
|
+
"maintenance_systems_maintenance_id_system_id_pk": {
|
|
100
|
+
"name": "maintenance_systems_maintenance_id_system_id_pk",
|
|
101
|
+
"columns": [
|
|
102
|
+
"maintenance_id",
|
|
103
|
+
"system_id"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"uniqueConstraints": {},
|
|
108
|
+
"policies": {},
|
|
109
|
+
"checkConstraints": {},
|
|
110
|
+
"isRLSEnabled": false
|
|
111
|
+
},
|
|
112
|
+
"public.maintenance_updates": {
|
|
113
|
+
"name": "maintenance_updates",
|
|
114
|
+
"schema": "",
|
|
115
|
+
"columns": {
|
|
116
|
+
"id": {
|
|
117
|
+
"name": "id",
|
|
118
|
+
"type": "text",
|
|
119
|
+
"primaryKey": true,
|
|
120
|
+
"notNull": true
|
|
121
|
+
},
|
|
122
|
+
"maintenance_id": {
|
|
123
|
+
"name": "maintenance_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": "maintenance_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
|
+
"maintenance_updates_maintenance_id_maintenances_id_fk": {
|
|
158
|
+
"name": "maintenance_updates_maintenance_id_maintenances_id_fk",
|
|
159
|
+
"tableFrom": "maintenance_updates",
|
|
160
|
+
"tableTo": "maintenances",
|
|
161
|
+
"columnsFrom": [
|
|
162
|
+
"maintenance_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.maintenances": {
|
|
178
|
+
"name": "maintenances",
|
|
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
|
+
"suppress_notifications": {
|
|
200
|
+
"name": "suppress_notifications",
|
|
201
|
+
"type": "boolean",
|
|
202
|
+
"primaryKey": false,
|
|
203
|
+
"notNull": true,
|
|
204
|
+
"default": false
|
|
205
|
+
},
|
|
206
|
+
"status": {
|
|
207
|
+
"name": "status",
|
|
208
|
+
"type": "maintenance_status",
|
|
209
|
+
"typeSchema": "public",
|
|
210
|
+
"primaryKey": false,
|
|
211
|
+
"notNull": true,
|
|
212
|
+
"default": "'scheduled'"
|
|
213
|
+
},
|
|
214
|
+
"start_at": {
|
|
215
|
+
"name": "start_at",
|
|
216
|
+
"type": "timestamp",
|
|
217
|
+
"primaryKey": false,
|
|
218
|
+
"notNull": true
|
|
219
|
+
},
|
|
220
|
+
"end_at": {
|
|
221
|
+
"name": "end_at",
|
|
222
|
+
"type": "timestamp",
|
|
223
|
+
"primaryKey": false,
|
|
224
|
+
"notNull": true
|
|
225
|
+
},
|
|
226
|
+
"created_at": {
|
|
227
|
+
"name": "created_at",
|
|
228
|
+
"type": "timestamp",
|
|
229
|
+
"primaryKey": false,
|
|
230
|
+
"notNull": true,
|
|
231
|
+
"default": "now()"
|
|
232
|
+
},
|
|
233
|
+
"updated_at": {
|
|
234
|
+
"name": "updated_at",
|
|
235
|
+
"type": "timestamp",
|
|
236
|
+
"primaryKey": false,
|
|
237
|
+
"notNull": true,
|
|
238
|
+
"default": "now()"
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
"indexes": {},
|
|
242
|
+
"foreignKeys": {},
|
|
243
|
+
"compositePrimaryKeys": {},
|
|
244
|
+
"uniqueConstraints": {},
|
|
245
|
+
"policies": {},
|
|
246
|
+
"checkConstraints": {},
|
|
247
|
+
"isRLSEnabled": false
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
"enums": {
|
|
251
|
+
"public.maintenance_status": {
|
|
252
|
+
"name": "maintenance_status",
|
|
253
|
+
"schema": "public",
|
|
254
|
+
"values": [
|
|
255
|
+
"scheduled",
|
|
256
|
+
"in_progress",
|
|
257
|
+
"completed",
|
|
258
|
+
"cancelled"
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"schemas": {},
|
|
263
|
+
"sequences": {},
|
|
264
|
+
"roles": {},
|
|
265
|
+
"policies": {},
|
|
266
|
+
"views": {},
|
|
267
|
+
"_meta": {
|
|
268
|
+
"columns": {},
|
|
269
|
+
"schemas": {},
|
|
270
|
+
"tables": {}
|
|
271
|
+
}
|
|
272
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/maintenance-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/maintenance-common": "1.
|
|
21
|
-
"@checkstack/notification-common": "1.0.
|
|
22
|
-
"@checkstack/catalog-common": "2.
|
|
23
|
-
"@checkstack/catalog-backend": "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.
|
|
17
|
+
"@checkstack/backend-api": "0.15.1",
|
|
18
|
+
"@checkstack/cache-api": "0.3.0",
|
|
19
|
+
"@checkstack/cache-utils": "0.2.5",
|
|
20
|
+
"@checkstack/maintenance-common": "1.1.0",
|
|
21
|
+
"@checkstack/notification-common": "1.0.2",
|
|
22
|
+
"@checkstack/catalog-common": "2.1.0",
|
|
23
|
+
"@checkstack/catalog-backend": "1.1.0",
|
|
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
29
|
"drizzle-orm": "^0.45.0",
|
|
30
30
|
"zod": "^4.2.1",
|
|
31
|
-
"@checkstack/common": "0.
|
|
31
|
+
"@checkstack/common": "0.9.0",
|
|
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
|
@@ -377,5 +377,33 @@ export function createRouter(
|
|
|
377
377
|
);
|
|
378
378
|
return { suppressed };
|
|
379
379
|
}),
|
|
380
|
+
|
|
381
|
+
addLink: os.addLink.handler(async ({ input }) => {
|
|
382
|
+
const maintenance = await service.getMaintenance(input.maintenanceId);
|
|
383
|
+
if (!maintenance) {
|
|
384
|
+
throw new ORPCError("NOT_FOUND", { message: "Maintenance not found" });
|
|
385
|
+
}
|
|
386
|
+
const link = await service.addLink(input);
|
|
387
|
+
await cache.invalidateForMutation({
|
|
388
|
+
maintenanceId: maintenance.id,
|
|
389
|
+
systemIds: maintenance.systemIds,
|
|
390
|
+
});
|
|
391
|
+
return link;
|
|
392
|
+
}),
|
|
393
|
+
|
|
394
|
+
removeLink: os.removeLink.handler(async ({ input }) => {
|
|
395
|
+
const maintenanceId = await service.removeLink(input.id);
|
|
396
|
+
if (!maintenanceId) {
|
|
397
|
+
return { success: false };
|
|
398
|
+
}
|
|
399
|
+
const maintenance = await service.getMaintenance(maintenanceId);
|
|
400
|
+
if (maintenance) {
|
|
401
|
+
await cache.invalidateForMutation({
|
|
402
|
+
maintenanceId,
|
|
403
|
+
systemIds: maintenance.systemIds,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
return { success: true };
|
|
407
|
+
}),
|
|
380
408
|
});
|
|
381
409
|
}
|
package/src/schema.ts
CHANGED
|
@@ -63,3 +63,17 @@ export const maintenanceUpdates = pgTable("maintenance_updates", {
|
|
|
63
63
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
64
64
|
createdBy: text("created_by"),
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Hotlinks attached to a maintenance — e.g. a change ticket, runbook, or
|
|
69
|
+
* chat thread. Free-form URL + optional human label.
|
|
70
|
+
*/
|
|
71
|
+
export const maintenanceLinks = pgTable("maintenance_links", {
|
|
72
|
+
id: text("id").primaryKey(),
|
|
73
|
+
maintenanceId: text("maintenance_id")
|
|
74
|
+
.notNull()
|
|
75
|
+
.references(() => maintenances.id, { onDelete: "cascade" }),
|
|
76
|
+
label: text("label"),
|
|
77
|
+
url: text("url").notNull(),
|
|
78
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
79
|
+
});
|
package/src/service.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { eq, and, or, inArray } from "drizzle-orm";
|
|
2
2
|
import type { SafeDatabase } from "@checkstack/backend-api";
|
|
3
3
|
import * as schema from "./schema";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
maintenances,
|
|
6
|
+
maintenanceSystems,
|
|
7
|
+
maintenanceUpdates,
|
|
8
|
+
maintenanceLinks,
|
|
9
|
+
} from "./schema";
|
|
5
10
|
import type {
|
|
6
11
|
MaintenanceWithSystems,
|
|
7
12
|
MaintenanceDetail,
|
|
8
13
|
MaintenanceUpdate,
|
|
14
|
+
MaintenanceLink,
|
|
15
|
+
AddMaintenanceLinkInput,
|
|
9
16
|
CreateMaintenanceInput,
|
|
10
17
|
UpdateMaintenanceInput,
|
|
11
18
|
AddMaintenanceUpdateInput,
|
|
@@ -99,6 +106,11 @@ export class MaintenanceService {
|
|
|
99
106
|
.from(maintenanceUpdates)
|
|
100
107
|
.where(eq(maintenanceUpdates.maintenanceId, id));
|
|
101
108
|
|
|
109
|
+
const links = await this.db
|
|
110
|
+
.select()
|
|
111
|
+
.from(maintenanceLinks)
|
|
112
|
+
.where(eq(maintenanceLinks.maintenanceId, id));
|
|
113
|
+
|
|
102
114
|
return {
|
|
103
115
|
...maintenance,
|
|
104
116
|
description: maintenance.description ?? undefined,
|
|
@@ -108,6 +120,7 @@ export class MaintenanceService {
|
|
|
108
120
|
statusChange: u.statusChange ?? undefined,
|
|
109
121
|
createdBy: u.createdBy ?? undefined,
|
|
110
122
|
})),
|
|
123
|
+
links,
|
|
111
124
|
};
|
|
112
125
|
}
|
|
113
126
|
|
|
@@ -321,6 +334,39 @@ export class MaintenanceService {
|
|
|
321
334
|
return true;
|
|
322
335
|
}
|
|
323
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Add a hotlink to a maintenance.
|
|
339
|
+
*/
|
|
340
|
+
async addLink(input: AddMaintenanceLinkInput): Promise<MaintenanceLink> {
|
|
341
|
+
const id = generateId();
|
|
342
|
+
await this.db.insert(maintenanceLinks).values({
|
|
343
|
+
id,
|
|
344
|
+
maintenanceId: input.maintenanceId,
|
|
345
|
+
label: input.label,
|
|
346
|
+
url: input.url,
|
|
347
|
+
});
|
|
348
|
+
const [row] = await this.db
|
|
349
|
+
.select()
|
|
350
|
+
.from(maintenanceLinks)
|
|
351
|
+
.where(eq(maintenanceLinks.id, id));
|
|
352
|
+
return row;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Remove a hotlink. Returns the parent maintenanceId so the caller can
|
|
357
|
+
* invalidate the right cache entry, or undefined if the link did not
|
|
358
|
+
* exist.
|
|
359
|
+
*/
|
|
360
|
+
async removeLink(id: string): Promise<string | undefined> {
|
|
361
|
+
const [existing] = await this.db
|
|
362
|
+
.select()
|
|
363
|
+
.from(maintenanceLinks)
|
|
364
|
+
.where(eq(maintenanceLinks.id, id));
|
|
365
|
+
if (!existing) return undefined;
|
|
366
|
+
await this.db.delete(maintenanceLinks).where(eq(maintenanceLinks.id, id));
|
|
367
|
+
return existing.maintenanceId;
|
|
368
|
+
}
|
|
369
|
+
|
|
324
370
|
/**
|
|
325
371
|
* Get unique subscriber user IDs for a maintenance's systems
|
|
326
372
|
* Uses the notification system to get subscribers and deduplicate
|