fix: preUpdate

This commit is contained in:
hexastack 2024-11-20 13:30:40 +01:00
parent 8f815d468c
commit b4bf2d4ff7
2 changed files with 10 additions and 5 deletions

View File

@ -265,7 +265,7 @@ export class BlockController extends BaseController<
@Patch('bulk')
async updateMany(@Body() body: { ids: string[]; payload: BlockUpdateDto }) {
if (!body.ids || body.ids.length === 0) {
throw new BadRequestException('No IDs provided for ...');
throw new BadRequestException('No IDs provided to perform the update');
}
const updates = await this.blockService.updateMany(
{

View File

@ -99,9 +99,14 @@ export class BlockRepository extends BaseRepository<
const movedBlockId = criteria._id;
// Find and update blocks that reference the moved block
await this.model.updateMany(
{ nextBlocks: movedBlockId },
{ $pull: { nextBlocks: movedBlockId } },
);
await this.model.updateMany(
{ attachedBlock: movedBlockId },
{ $set: { attachedBlock: null }, $pull: { nextBlocks: movedBlockId } },
{ $set: { attachedBlock: null } },
);
} else if (update?.category && !criteria._id) {
throw new Error('Criteria must include a valid id to update category.');
@ -154,7 +159,7 @@ export class BlockRepository extends BaseRepository<
}
}
private mapIdsAndCategory(
mapIdsAndCategory(
ids: string[],
category: string,
): {
@ -166,7 +171,7 @@ export class BlockRepository extends BaseRepository<
return { objIds, objCategory };
}
private async updateBlocksInScope(
async updateBlocksInScope(
objCategory: mongoose.Types.ObjectId,
ids: string[],
): Promise<void> {
@ -196,7 +201,7 @@ export class BlockRepository extends BaseRepository<
}
}
private async updateExternalBlocks(
async updateExternalBlocks(
otherBlocks,
objIds: Types.ObjectId[],
): Promise<void> {