mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
chore: revert changes based on feedback
This commit is contained in:
@ -7,7 +7,6 @@ import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-reques
|
||||
import type { CreateDocumentAuditLogDataResponse } from '@documenso/lib/utils/document-audit-logs';
|
||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import type { Attachment } from '@documenso/prisma/generated/zod/modelSchema/AttachmentSchema';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
||||
@ -25,7 +24,6 @@ export type UpdateDocumentOptions = {
|
||||
globalAccessAuth?: TDocumentAccessAuthTypes[];
|
||||
globalActionAuth?: TDocumentActionAuthTypes[];
|
||||
useLegacyFieldInsertion?: boolean;
|
||||
attachments?: Pick<Attachment, 'id' | 'label' | 'url'>[];
|
||||
};
|
||||
requestMetadata: ApiRequestMetadata;
|
||||
};
|
||||
@ -55,7 +53,6 @@ export const updateDocument = async ({
|
||||
},
|
||||
},
|
||||
},
|
||||
attachments: true,
|
||||
},
|
||||
});
|
||||
|
||||
@ -136,8 +133,6 @@ export const updateDocument = async ({
|
||||
documentGlobalActionAuth === undefined || documentGlobalActionAuth === newGlobalActionAuth;
|
||||
const isDocumentVisibilitySame =
|
||||
data.visibility === undefined || data.visibility === document.visibility;
|
||||
const isAttachmentsSame =
|
||||
data.attachments === undefined || data.attachments === document.attachments;
|
||||
|
||||
const auditLogs: CreateDocumentAuditLogDataResponse[] = [];
|
||||
|
||||
@ -217,20 +212,6 @@ export const updateDocument = async ({
|
||||
);
|
||||
}
|
||||
|
||||
if (!isAttachmentsSame) {
|
||||
auditLogs.push(
|
||||
createDocumentAuditLogData({
|
||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ATTACHMENTS_UPDATED,
|
||||
documentId,
|
||||
metadata: requestMetadata,
|
||||
data: {
|
||||
from: document.attachments,
|
||||
to: data.attachments ?? [],
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// Early return if nothing is required.
|
||||
if (auditLogs.length === 0 && data.useLegacyFieldInsertion === undefined) {
|
||||
return document;
|
||||
@ -255,39 +236,6 @@ export const updateDocument = async ({
|
||||
},
|
||||
});
|
||||
|
||||
if (data.attachments) {
|
||||
await tx.attachment.deleteMany({
|
||||
where: {
|
||||
documentId,
|
||||
id: {
|
||||
notIn: data.attachments.map((a) => a.id),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
data.attachments.map(
|
||||
async (attachment) =>
|
||||
await tx.attachment.upsert({
|
||||
where: {
|
||||
id: attachment.id,
|
||||
documentId,
|
||||
},
|
||||
update: {
|
||||
label: attachment.label,
|
||||
url: attachment.url,
|
||||
},
|
||||
create: {
|
||||
id: attachment.id,
|
||||
label: attachment.label,
|
||||
url: attachment.url,
|
||||
documentId,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await tx.documentAuditLog.createMany({
|
||||
data: auditLogs,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user