fix: filter folder by eq and startswith

This commit is contained in:
Marc-Roig 2023-05-17 17:31:38 +02:00
parent 1ff71db3f6
commit 008d82f8f7
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -56,16 +56,22 @@ const deleteByIds = async (ids = []) => {
// delete files
const filesToDelete = await strapi.db.query(FILE_MODEL_UID).findMany({
where: {
$or: pathsToDelete.map((path) => ({ folderPath: { $startsWith: path } })),
$or: pathsToDelete.flatMap((path) => [
{ folderPath: { $eq: path } },
{ folderPath: { $startsWith: `${path}/` } },
]),
},
});
await Promise.all(filesToDelete.map((file) => getService('upload').remove(file)));
// delete folders
// delete folders and subfolders
const { count: totalFolderNumber } = await strapi.db.query(FOLDER_MODEL_UID).deleteMany({
where: {
$or: pathsToDelete.map((path) => ({ path: { $startsWith: path } })),
$or: pathsToDelete.flatMap((path) => [
{ path: { $eq: path } },
{ path: { $startsWith: `${path}/` } },
]),
},
});