fix: move updating the contact to contacts controller

This commit is contained in:
Nik Lampe
2024-09-09 16:44:58 +02:00
parent 3f70be95dd
commit 7c8d3bb050
2 changed files with 4 additions and 11 deletions
+4 -4
View File
@@ -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 },
});
@@ -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);