ソースを参照

Tell a job's own screens about a conditional update that names it (#691)

Bernt Christian Egeland 2 日 前
親
コミット
7e19557074

+ 12 - 0
src/__tests__/lib/realtime/announces-writes.test.ts

@@ -236,6 +236,18 @@ describe('a bulk write', () => {
       { kind: 'serviceRecord', id: null, organizationId: 'org-1', action: 'updated' },
     ])
   })
+
+  it('announces the one record a conditional update names by id', async () => {
+    // A cancel writes only if the job is not cancelled already.
+    await write('ServiceRecord', 'updateMany', {
+      where: { id: 'sr-1', organizationId: 'org-1', status: { not: 'cancelled' } },
+      data: { status: 'cancelled' },
+    })
+
+    expect(published).toEqual([
+      { kind: 'serviceRecord', id: 'sr-1', organizationId: 'org-1', action: 'updated' },
+    ])
+  })
 })
 
 describe('what is not announced', () => {

+ 5 - 1
src/lib/realtime/prisma-realtime.server.ts

@@ -256,7 +256,11 @@ async function announce(
   if (!kind && !child) return
 
   if (kind) {
-    const id = action === 'bulk' ? null : idFrom(args, result)
+    // A bulk write that names one row by id is a write of that row: a
+    // conditional update (`updateMany` where id and status) is how a cancel
+    // or a status change refuses to undo another, and the job's screens must
+    // hear it. One that names none is the workshop's lists' to hear.
+    const id = action === 'bulk' ? stringOf(((args.where ?? {}) as Row).id) : idFrom(args, result)
     const organizationId =
       organizationFrom(args, result) ?? (id ? await organizationOf(kind, id, hooks) : null)
     if (!organizationId) return