fix collectionOrder updating + remove index
This commit is contained in:
@@ -31,6 +31,8 @@ export default async function deleteCollection(
|
||||
},
|
||||
});
|
||||
|
||||
await removeFromOrders(userId, collectionId);
|
||||
|
||||
return { response: deletedUsersAndCollectionsRelation, status: 200 };
|
||||
} else if (collectionIsAccessible?.ownerId !== userId) {
|
||||
return { response: "Collection is not accessible.", status: 401 };
|
||||
@@ -57,6 +59,8 @@ export default async function deleteCollection(
|
||||
|
||||
await removeFolder({ filePath: `archives/${collectionId}` });
|
||||
|
||||
await removeFromOrders(userId, collectionId);
|
||||
|
||||
return await prisma.collection.delete({
|
||||
where: {
|
||||
id: collectionId,
|
||||
@@ -98,3 +102,28 @@ async function deleteSubCollections(collectionId: number) {
|
||||
await removeFolder({ filePath: `archives/${subCollection.id}` });
|
||||
}
|
||||
}
|
||||
|
||||
async function removeFromOrders(userId: number, collectionId: number) {
|
||||
const userCollectionOrder = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
collectionOrder: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (userCollectionOrder)
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
data: {
|
||||
collectionOrder: {
|
||||
set: userCollectionOrder.collectionOrder.filter(
|
||||
(e: number) => e !== collectionId
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user