From 3f70be95dde80c04611089f66b1fcaa8eb30655e Mon Sep 17 00:00:00 2001 From: Nik Lampe Date: Mon, 9 Sep 2024 08:57:26 +0200 Subject: [PATCH 1/3] fix: refetch contact after awaiting triggers --- packages/api/src/services/ActionService.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/api/src/services/ActionService.ts b/packages/api/src/services/ActionService.ts index 26a88fa..fe485c6 100644 --- a/packages/api/src/services/ActionService.ts +++ b/packages/api/src/services/ActionService.ts @@ -71,6 +71,13 @@ export class ActionService { const triggers = await ContactService.triggers(contact.id); + // Refetch the contact, as it may have subscribed now + contact = await prisma.contact.findUniqueOrThrow({ + where: { + id: contact.id, + }, + }); + for (const action of actions) { const hasTriggeredAction = !!triggers.find((t) => t.actionId === action.id); From 7c8d3bb050fb0c35e0296eeb71d516f0c37329a2 Mon Sep 17 00:00:00 2001 From: Nik Lampe Date: Mon, 9 Sep 2024 16:44:58 +0200 Subject: [PATCH 2/3] fix: move updating the contact to contacts controller --- packages/api/src/controllers/v1/Contacts.ts | 8 ++++---- packages/api/src/services/ActionService.ts | 7 ------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/api/src/controllers/v1/Contacts.ts b/packages/api/src/controllers/v1/Contacts.ts index 76a124a..7389975 100644 --- a/packages/api/src/controllers/v1/Contacts.ts +++ b/packages/api/src/controllers/v1/Contacts.ts @@ -103,13 +103,13 @@ export class Contacts { const { id, email } = ContactSchemas.manage.parse(req.body); - const contact = id ? await ContactService.id(id) : await ContactService.email(project.id, email as string); + let contact = id ? await ContactService.id(id) : await ContactService.email(project.id, email as string); if (!contact || contact.projectId !== project.id) { throw new NotFound("contact"); } - await prisma.contact.update({ + contact = await prisma.contact.update({ where: { id: contact.id }, data: { subscribed: false }, }); @@ -154,13 +154,13 @@ export class Contacts { const { id, email } = ContactSchemas.manage.parse(req.body); - const contact = id ? await ContactService.id(id) : await ContactService.email(project.id, email as string); + let contact = id ? await ContactService.id(id) : await ContactService.email(project.id, email as string); if (!contact || contact.projectId !== project.id) { throw new NotFound("contact"); } - await prisma.contact.update({ + contact = await prisma.contact.update({ where: { id: contact.id }, data: { subscribed: true }, }); diff --git a/packages/api/src/services/ActionService.ts b/packages/api/src/services/ActionService.ts index fe485c6..26a88fa 100644 --- a/packages/api/src/services/ActionService.ts +++ b/packages/api/src/services/ActionService.ts @@ -71,13 +71,6 @@ export class ActionService { const triggers = await ContactService.triggers(contact.id); - // Refetch the contact, as it may have subscribed now - contact = await prisma.contact.findUniqueOrThrow({ - where: { - id: contact.id, - }, - }); - for (const action of actions) { const hasTriggeredAction = !!triggers.find((t) => t.actionId === action.id); From 29590f359a99bf80c6a57b25a946ed5c0bde58e8 Mon Sep 17 00:00:00 2001 From: Nik Lampe Date: Tue, 10 Sep 2024 11:33:12 +0200 Subject: [PATCH 3/3] chore: bump dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c539f87..d3bc611 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plunk", - "version": "1.0.4", + "version": "1.0.5", "private": true, "license": "agpl-3.0", "workspaces": {