mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
Compare commits
1 Commits
b3ed80d721
...
fix/duplic
| Author | SHA1 | Date | |
|---|---|---|---|
| 913a59ec23 |
@ -35,6 +35,7 @@ export const duplicateDocument = async ({
|
|||||||
select: {
|
select: {
|
||||||
title: true,
|
title: true,
|
||||||
userId: true,
|
userId: true,
|
||||||
|
teamId: true,
|
||||||
documentData: {
|
documentData: {
|
||||||
select: {
|
select: {
|
||||||
data: true,
|
data: true,
|
||||||
@ -57,12 +58,19 @@ export const duplicateDocument = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const currentUser = await prisma.user.findFirstOrThrow({
|
||||||
|
where: { id: userId },
|
||||||
|
select: { email: true },
|
||||||
|
});
|
||||||
|
|
||||||
if (!document) {
|
if (!document) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Document not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isDocumentOwner = userId === document.userId || teamId === document.teamId;
|
||||||
|
|
||||||
const documentData = await prisma.documentData.create({
|
const documentData = await prisma.documentData.create({
|
||||||
data: {
|
data: {
|
||||||
type: document.documentData.type,
|
type: document.documentData.type,
|
||||||
@ -100,30 +108,38 @@ export const duplicateDocument = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const recipientsToCreate = document.recipients.map((recipient) => ({
|
const recipientsToCreate = document.recipients
|
||||||
documentId: createdDocument.id,
|
.filter((recipient) => {
|
||||||
email: recipient.email,
|
if (isDocumentOwner) {
|
||||||
name: recipient.name,
|
return true;
|
||||||
role: recipient.role,
|
}
|
||||||
signingOrder: recipient.signingOrder,
|
|
||||||
token: nanoid(),
|
return recipient.email === currentUser.email;
|
||||||
fields: {
|
})
|
||||||
createMany: {
|
.map((recipient) => ({
|
||||||
data: recipient.fields.map((field) => ({
|
documentId: createdDocument.id,
|
||||||
documentId: createdDocument.id,
|
email: recipient.email,
|
||||||
type: field.type,
|
name: recipient.name,
|
||||||
page: field.page,
|
role: recipient.role,
|
||||||
positionX: field.positionX,
|
signingOrder: recipient.signingOrder,
|
||||||
positionY: field.positionY,
|
token: nanoid(),
|
||||||
width: field.width,
|
fields: {
|
||||||
height: field.height,
|
createMany: {
|
||||||
customText: '',
|
data: recipient.fields.map((field) => ({
|
||||||
inserted: false,
|
documentId: createdDocument.id,
|
||||||
fieldMeta: field.fieldMeta as PrismaJson.FieldMeta,
|
type: field.type,
|
||||||
})),
|
page: field.page,
|
||||||
|
positionX: field.positionX,
|
||||||
|
positionY: field.positionY,
|
||||||
|
width: field.width,
|
||||||
|
height: field.height,
|
||||||
|
customText: '',
|
||||||
|
inserted: false,
|
||||||
|
fieldMeta: field.fieldMeta as PrismaJson.FieldMeta,
|
||||||
|
})),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
}));
|
||||||
}));
|
|
||||||
|
|
||||||
const recipients: Recipient[] = [];
|
const recipients: Recipient[] = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user