Merge pull request #1 from himanshu-ntml/codex/find-and-fix-a-bug-in-codebase
Fix contact update response
This commit is contained in:
@@ -248,12 +248,17 @@ export class Contacts {
|
|||||||
|
|
||||||
const { id, email, subscribed, data } = ContactSchemas.manage.parse(req.body);
|
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) {
|
if (!contact || contact.projectId !== project.id) {
|
||||||
throw new NotFound("contact");
|
throw new NotFound("contact");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateData: Record<string, unknown> = {
|
||||||
|
email,
|
||||||
|
subscribed: subscribed ?? contact.subscribed,
|
||||||
|
};
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
const givenUserData = Object.entries(data);
|
const givenUserData = Object.entries(data);
|
||||||
const dataToUpdate = JSON.parse(contact.data ?? "{}");
|
const dataToUpdate = JSON.parse(contact.data ?? "{}");
|
||||||
@@ -266,18 +271,12 @@ export class Contacts {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.contact.update({
|
updateData.data = JSON.stringify(dataToUpdate);
|
||||||
where: { id: contact.id },
|
|
||||||
data: { data: JSON.stringify(dataToUpdate) },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.contact.update({
|
contact = await prisma.contact.update({
|
||||||
where: { id: contact.id },
|
where: { id: contact.id },
|
||||||
data: {
|
data: updateData,
|
||||||
email,
|
|
||||||
subscribed: subscribed ?? contact.subscribed,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await redis.del(Keys.Project.contacts(project.id));
|
await redis.del(Keys.Project.contacts(project.id));
|
||||||
|
|||||||
Reference in New Issue
Block a user