fix: move updating the contact to contacts controller
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user