mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 19:21:39 +10:00
chore: make duplicate recipients work for remplates
This commit is contained in:
@ -101,13 +101,15 @@ export const setTemplateRecipients = async ({
|
||||
},
|
||||
});
|
||||
|
||||
const removedRecipients = existingRecipients.filter(
|
||||
(existingRecipient) =>
|
||||
!normalizedRecipients.find(
|
||||
(recipient) =>
|
||||
recipient.id === existingRecipient.id || recipient.email === existingRecipient.email,
|
||||
),
|
||||
);
|
||||
const removedRecipients = existingRecipients.filter((existingRecipient) => {
|
||||
// Keep direct template recipients from being removed
|
||||
if (template.directLink?.directTemplateRecipientId === existingRecipient.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if this recipient still exists in the normalized recipients
|
||||
return !normalizedRecipients.some((recipient) => recipient.id === existingRecipient.id);
|
||||
});
|
||||
|
||||
if (template.directLink !== null) {
|
||||
const updatedDirectRecipient = recipients.find(
|
||||
@ -132,15 +134,24 @@ export const setTemplateRecipients = async ({
|
||||
}
|
||||
|
||||
const linkedRecipients = normalizedRecipients.map((recipient) => {
|
||||
const existing = existingRecipients.find(
|
||||
(existingRecipient) =>
|
||||
existingRecipient.id === recipient.id || existingRecipient.email === recipient.email,
|
||||
);
|
||||
// For direct template recipients, match by ID only
|
||||
if (template.directLink?.directTemplateRecipientId === recipient.id) {
|
||||
const existing = existingRecipients.find(
|
||||
(existingRecipient) => existingRecipient.id === recipient.id,
|
||||
);
|
||||
return { ...recipient, _persisted: existing };
|
||||
}
|
||||
|
||||
return {
|
||||
...recipient,
|
||||
_persisted: existing,
|
||||
};
|
||||
// For other recipients, match by ID if it exists
|
||||
if (recipient.id) {
|
||||
const existing = existingRecipients.find(
|
||||
(existingRecipient) => existingRecipient.id === recipient.id,
|
||||
);
|
||||
return { ...recipient, _persisted: existing };
|
||||
}
|
||||
|
||||
// For new recipients, create a new entry
|
||||
return { ...recipient, _persisted: undefined };
|
||||
});
|
||||
|
||||
const persistedRecipients = await prisma.$transaction(async (tx) => {
|
||||
|
||||
Reference in New Issue
Block a user