diff --git a/api/src/chat/controllers/block.controller.ts b/api/src/chat/controllers/block.controller.ts index 3d4d82e..47ef62f 100644 --- a/api/src/chat/controllers/block.controller.ts +++ b/api/src/chat/controllers/block.controller.ts @@ -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( { diff --git a/api/src/chat/repositories/block.repository.ts b/api/src/chat/repositories/block.repository.ts index 69e575c..2931ad6 100644 --- a/api/src/chat/repositories/block.repository.ts +++ b/api/src/chat/repositories/block.repository.ts @@ -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 { @@ -196,7 +201,7 @@ export class BlockRepository extends BaseRepository< } } - private async updateExternalBlocks( + async updateExternalBlocks( otherBlocks, objIds: Types.ObjectId[], ): Promise {