mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
refactor: minor updates
This commit is contained in:
parent
09b3201949
commit
978562900e
@ -332,7 +332,7 @@ export class BlockController extends BaseController<
|
|||||||
@CsrfCheck(true)
|
@CsrfCheck(true)
|
||||||
@Delete('')
|
@Delete('')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
async deleteMany(@Body('ids') ids: string[]): Promise<DeleteResult> {
|
async deleteBlocksByIds(@Body('ids') ids: string[]): Promise<DeleteResult> {
|
||||||
if (!ids || ids.length === 0) {
|
if (!ids || ids.length === 0) {
|
||||||
throw new BadRequestException('No IDs provided for deletion.');
|
throw new BadRequestException('No IDs provided for deletion.');
|
||||||
}
|
}
|
||||||
|
@ -372,14 +372,7 @@ const Diagrams = () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const handleBlockDeletion = async (blockIds: string[]) => {
|
const handleBlocksDeletion = async (blockIds: string[]) => {
|
||||||
if (blockIds.length > 1) {
|
|
||||||
await deleteMultipleBlocks(blockIds);
|
|
||||||
} else {
|
|
||||||
await deleteSingleBlock(blockIds[0]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const deleteMultipleBlocks = async (blockIds: string[]) => {
|
|
||||||
await deleteBlocks(blockIds, {
|
await deleteBlocks(blockIds, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
blockIds.forEach((blockId) => {
|
blockIds.forEach((blockId) => {
|
||||||
@ -393,18 +386,6 @@ const Diagrams = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const deleteSingleBlock = async (blockId: string) => {
|
|
||||||
const block = getBlockFromCache(blockId);
|
|
||||||
|
|
||||||
await deleteBlock(blockId, {
|
|
||||||
onSuccess() {
|
|
||||||
if (block) {
|
|
||||||
updateLinkedBlocks(block, [blockId]);
|
|
||||||
deleteCachedBlock(blockId);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const getLinkedBlockIds = (block: IBlock): string[] => [
|
const getLinkedBlockIds = (block: IBlock): string[] => [
|
||||||
...(block?.nextBlocks || []),
|
...(block?.nextBlocks || []),
|
||||||
...(block?.previousBlocks || []),
|
...(block?.previousBlocks || []),
|
||||||
@ -481,7 +462,7 @@ const Diagrams = () => {
|
|||||||
if (isLink) {
|
if (isLink) {
|
||||||
await handleLinkDeletion(ids[0]);
|
await handleLinkDeletion(ids[0]);
|
||||||
} else {
|
} else {
|
||||||
await handleBlockDeletion(ids);
|
await handleBlocksDeletion(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanupAfterDeletion();
|
cleanupAfterDeletion();
|
||||||
|
Loading…
Reference in New Issue
Block a user