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') @Patch('bulk')
async updateMany(@Body() body: { ids: string[]; payload: BlockUpdateDto }) { async updateMany(@Body() body: { ids: string[]; payload: BlockUpdateDto }) {
if (!body.ids || body.ids.length === 0) { 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( const updates = await this.blockService.updateMany(
{ {

View File

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