Merge pull request #1 from himanshu-ntml/codex/find-and-fix-a-bug-in-codebase

Fix contact update response
This commit is contained in:
Himanshu Ahuja
2025-06-03 18:16:55 -04:00
committed by GitHub
+9 -10
View File
@@ -248,12 +248,17 @@ export class Contacts {
const { id, email, subscribed, data } = 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");
}
const updateData: Record<string, unknown> = {
email,
subscribed: subscribed ?? contact.subscribed,
};
if (data) {
const givenUserData = Object.entries(data);
const dataToUpdate = JSON.parse(contact.data ?? "{}");
@@ -266,18 +271,12 @@ export class Contacts {
}
});
await prisma.contact.update({
where: { id: contact.id },
data: { data: JSON.stringify(dataToUpdate) },
});
updateData.data = JSON.stringify(dataToUpdate);
}
await prisma.contact.update({
contact = await prisma.contact.update({
where: { id: contact.id },
data: {
email,
subscribed: subscribed ?? contact.subscribed,
},
data: updateData,
});
await redis.del(Keys.Project.contacts(project.id));