mirror of
https://github.com/hexastack/hexabot
synced 2025-05-31 10:57:06 +00:00
fix: handle preDelete criteria
This commit is contained in:
parent
803649c4d1
commit
92dbd8c996
@ -37,7 +37,7 @@ export class CategoryRepository extends BaseRepository<Category> {
|
|||||||
* @param criteria - The filter criteria for finding blocks to delete.
|
* @param criteria - The filter criteria for finding blocks to delete.
|
||||||
*/
|
*/
|
||||||
async preDelete(
|
async preDelete(
|
||||||
_query: Query<
|
query: Query<
|
||||||
DeleteResult,
|
DeleteResult,
|
||||||
Document<Category, any, any>,
|
Document<Category, any, any>,
|
||||||
unknown,
|
unknown,
|
||||||
@ -46,11 +46,18 @@ export class CategoryRepository extends BaseRepository<Category> {
|
|||||||
>,
|
>,
|
||||||
criteria: TFilterQuery<Category>,
|
criteria: TFilterQuery<Category>,
|
||||||
) {
|
) {
|
||||||
const associatedBlocks = await this.blockService.findOne({
|
criteria = query.getQuery();
|
||||||
category: criteria._id,
|
const ids = Array.isArray(criteria._id) ? criteria._id : [criteria._id];
|
||||||
});
|
|
||||||
if (associatedBlocks) {
|
for (const id of ids) {
|
||||||
throw new ForbiddenException(`Category have blocks associated to it`);
|
const associatedBlocks = await this.blockService.findOne({
|
||||||
|
category: id,
|
||||||
|
});
|
||||||
|
if (associatedBlocks) {
|
||||||
|
throw new ForbiddenException(
|
||||||
|
`Category ${id} has blocks associated with it`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user