Files
twenty/packages/twenty-front/src/modules/activities/utils/getActivityAttachmentIdsToDelete.ts
T
Félix Malfait 464a480043 Continue ESLINT9 Migration (#13795)
Might already fix #13793
2025-08-10 23:25:58 +02:00

35 lines
1.1 KiB
TypeScript

import { type Attachment } from '@/activities/files/types/Attachment';
import { compareUrls } from '@/activities/utils/compareUrls';
import { getActivityAttachmentPathsAndName } from '@/activities/utils/getActivityAttachmentPathsAndName';
export const getActivityAttachmentIdsToDelete = (
newActivityBody: string,
oldActivityAttachments: Attachment[] = [],
oldActivityBody: string,
) => {
if (oldActivityAttachments.length === 0) return [];
const newActivityAttachmentPaths =
getActivityAttachmentPathsAndName(newActivityBody);
const oldActivityAttachmentPaths =
getActivityAttachmentPathsAndName(oldActivityBody);
const pathsToDelete = oldActivityAttachmentPaths
.filter(
(oldActivity) =>
!newActivityAttachmentPaths.some(
(newActivity) => newActivity.path === oldActivity.path,
),
)
.map((activity) => activity.path);
return oldActivityAttachments
.filter((attachment) =>
pathsToDelete.some((pathToDelete) =>
compareUrls(attachment.fullPath, pathToDelete),
),
)
.map((attachment) => attachment.id);
};