mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: update block repository logic to correctly reference source category and handle block updates
This commit is contained in:
parent
9cde4f85bc
commit
266730ba81
@ -140,12 +140,12 @@ export class BlockRepository extends BaseRepository<
|
|||||||
|
|
||||||
// Step 1: Map IDs and Category
|
// Step 1: Map IDs and Category
|
||||||
const objIds = ids.map((id) => new Types.ObjectId(id));
|
const objIds = ids.map((id) => new Types.ObjectId(id));
|
||||||
const objCategoryId = new Types.ObjectId(categoryId);
|
const sourceCategoryId = movedBlocks[0].category;
|
||||||
|
|
||||||
// Step 2: Find other blocks
|
// Step 2: Find blocks in source category that reference the moved blocks
|
||||||
const otherBlocks = await this.find({
|
const otherBlocks = await this.find({
|
||||||
_id: { $nin: objIds },
|
_id: { $nin: objIds },
|
||||||
category: { $ne: objCategoryId },
|
category: sourceCategoryId,
|
||||||
$or: [
|
$or: [
|
||||||
{ attachedBlock: { $in: objIds } },
|
{ attachedBlock: { $in: objIds } },
|
||||||
{ nextBlocks: { $in: objIds } },
|
{ nextBlocks: { $in: objIds } },
|
||||||
@ -154,7 +154,7 @@ export class BlockRepository extends BaseRepository<
|
|||||||
// Step 3: Update blocks in the provided scope
|
// Step 3: Update blocks in the provided scope
|
||||||
await this.prepareBlocksInCategoryUpdateScope(categoryId, ids);
|
await this.prepareBlocksInCategoryUpdateScope(categoryId, ids);
|
||||||
|
|
||||||
// Step 4: Update external blocks
|
// Step 4: Update blocks in source category
|
||||||
await this.prepareBlocksOutOfCategoryUpdateScope(otherBlocks, ids);
|
await this.prepareBlocksOutOfCategoryUpdateScope(otherBlocks, ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,16 +206,21 @@ export class BlockRepository extends BaseRepository<
|
|||||||
ids: string[],
|
ids: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const block of otherBlocks) {
|
for (const block of otherBlocks) {
|
||||||
|
// Handle attached block references
|
||||||
if (block.attachedBlock && ids.includes(block.attachedBlock)) {
|
if (block.attachedBlock && ids.includes(block.attachedBlock)) {
|
||||||
await this.updateOne(block.id, { attachedBlock: null });
|
await this.updateOne(block.id, { attachedBlock: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextBlocks = block.nextBlocks?.filter(
|
// Handle nextBlocks references
|
||||||
|
const filteredNextBlocks = block.nextBlocks?.filter(
|
||||||
(nextBlock) => !ids.includes(nextBlock),
|
(nextBlock) => !ids.includes(nextBlock),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (nextBlocks?.length) {
|
// If the filtered nextBlocks length is different from the original, update the block
|
||||||
await this.updateOne(block.id, { nextBlocks });
|
if (filteredNextBlocks?.length !== block.nextBlocks?.length) {
|
||||||
|
await this.updateOne(block.id, {
|
||||||
|
nextBlocks: filteredNextBlocks || [],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user