mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: simplify prepareBlocksOutOfCategoryUpdateScope logic and add error handling
This commit is contained in:
parent
79f866e406
commit
6a128541df
@ -178,18 +178,25 @@ export class BlockRepository extends BaseRepository<
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const { id, nextBlocks, attachedBlock } of blocks) {
|
for (const { id, nextBlocks, attachedBlock } of blocks) {
|
||||||
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
|
try {
|
||||||
ids.includes(nextBlock),
|
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
|
||||||
);
|
ids.includes(nextBlock),
|
||||||
|
);
|
||||||
|
|
||||||
const updatedAttachedBlock = ids.includes(attachedBlock || '')
|
const updatedAttachedBlock = ids.includes(attachedBlock || '')
|
||||||
? attachedBlock
|
? attachedBlock
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
await this.updateOne(id, {
|
await this.updateOne(id, {
|
||||||
nextBlocks: updatedNextBlocks,
|
nextBlocks: updatedNextBlocks,
|
||||||
attachedBlock: updatedAttachedBlock,
|
attachedBlock: updatedAttachedBlock,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.logger?.error(
|
||||||
|
`Failed to update block ${id} during in-category scope update.`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,21 +213,30 @@ 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
|
try {
|
||||||
if (block.attachedBlock && ids.includes(block.attachedBlock)) {
|
// If block has an attachedBlock, we only need to check that
|
||||||
await this.updateOne(block.id, { attachedBlock: null });
|
if (block.attachedBlock) {
|
||||||
}
|
if (ids.includes(block.attachedBlock)) {
|
||||||
|
await this.updateOne(block.id, { attachedBlock: null });
|
||||||
|
}
|
||||||
|
continue; // Skip nextBlocks check since it can't have both
|
||||||
|
}
|
||||||
|
|
||||||
// Handle nextBlocks references
|
// Only check nextBlocks if there is no attachedBlock
|
||||||
const filteredNextBlocks = block.nextBlocks?.filter(
|
const filteredNextBlocks = block.nextBlocks?.filter(
|
||||||
(nextBlock) => !ids.includes(nextBlock),
|
(nextBlock) => !ids.includes(nextBlock),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the filtered nextBlocks length is different from the original, update the block
|
if (filteredNextBlocks?.length !== block.nextBlocks?.length) {
|
||||||
if (filteredNextBlocks?.length !== block.nextBlocks?.length) {
|
await this.updateOne(block.id, {
|
||||||
await this.updateOne(block.id, {
|
nextBlocks: filteredNextBlocks || [],
|
||||||
nextBlocks: filteredNextBlocks || [],
|
});
|
||||||
});
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger?.error(
|
||||||
|
`Failed to update block ${block.id} during out-of-category scope update.`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user