diff --git a/api/src/chat/repositories/block.repository.ts b/api/src/chat/repositories/block.repository.ts index 4e8f02c9..31b0bacd 100644 --- a/api/src/chat/repositories/block.repository.ts +++ b/api/src/chat/repositories/block.repository.ts @@ -179,13 +179,13 @@ export class BlockRepository extends BaseRepository< ): Promise { for (const id of ids) { const oldState = await this.findOne(id); - if (oldState?.category !== category) { - const updatedNextBlocks = oldState?.nextBlocks?.filter((nextBlock) => + if (oldState && oldState.category !== category) { + const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) => ids.includes(nextBlock), ); - const updatedAttachedBlock = ids.includes(oldState?.attachedBlock || '') - ? oldState?.attachedBlock + const updatedAttachedBlock = ids.includes(oldState.attachedBlock || '') + ? oldState.attachedBlock : null; await this.updateOne(id, { @@ -209,7 +209,7 @@ export class BlockRepository extends BaseRepository< ids: string[], ): Promise { for (const block of otherBlocks) { - if (ids.includes(block.attachedBlock || '')) { + if (block.attachedBlock && ids.includes(block.attachedBlock)) { await this.updateOne(block.id, { attachedBlock: null }); } diff --git a/api/src/chat/services/bot.service.ts b/api/src/chat/services/bot.service.ts index e10ec508..93cb4f1b 100644 --- a/api/src/chat/services/bot.service.ts +++ b/api/src/chat/services/bot.service.ts @@ -240,7 +240,7 @@ export class BotService { event.getMessageType() === IncomingMessageType.message && fallbackOptions.active && convo.context?.attempt && - convo.context?.attempt < fallbackOptions.max_attempts + convo.context.attempt < fallbackOptions.max_attempts ) { // Trigger block fallback // NOTE : current is not populated, this may cause some anomaly diff --git a/api/src/cms/schemas/menu.schema.ts b/api/src/cms/schemas/menu.schema.ts index 18bed2b6..125533e7 100644 --- a/api/src/cms/schemas/menu.schema.ts +++ b/api/src/cms/schemas/menu.schema.ts @@ -59,7 +59,7 @@ export class MenuStub extends BaseSchema { @Schema({ timestamps: true }) export class Menu extends MenuStub { @Transform(({ obj }) => obj.parent?.toString()) - parent?: string | undefined; + parent?: string; } @Schema({ timestamps: true }) diff --git a/api/src/cms/services/menu.service.ts b/api/src/cms/services/menu.service.ts index c55cd099..ba560d41 100644 --- a/api/src/cms/services/menu.service.ts +++ b/api/src/cms/services/menu.service.ts @@ -126,7 +126,9 @@ export class MenuService extends BaseService { parent: string | symbol = this.RootSymbol, ): MenuTree { const item = parents.get(parent); - if (!item) return []; + if (!item) { + return []; + } const children: MenuTree = item.map((menu) => { return { ...menu, diff --git a/api/src/utils/test/fixtures/menu.ts b/api/src/utils/test/fixtures/menu.ts index 04af7b6d..d659ddb1 100644 --- a/api/src/utils/test/fixtures/menu.ts +++ b/api/src/utils/test/fixtures/menu.ts @@ -108,7 +108,7 @@ export const installMenuFixtures = async () => { const offerDocs = await Menu.insertMany( offersMenuFixtures.map((m) => ({ ...m, - parent: m.parent && docs[parseInt(m.parent)].id, + parent: m.parent ? docs[parseInt(m.parent)].id : undefined, })), ); @@ -117,7 +117,7 @@ export const installMenuFixtures = async () => { await Menu.insertMany( devicesMenuFixtures.map((m) => ({ ...m, - parent: m.parent && allDocs[parseInt(m.parent)].id, + parent: m.parent ? allDocs[parseInt(m.parent)].id : undefined, })), ); @@ -125,7 +125,7 @@ export const installMenuFixtures = async () => { accountMenuFixtures.map((m) => { return { ...m, - parent: m.parent && docs[parseInt(m.parent)].id, + parent: m.parent ? docs[parseInt(m.parent)].id : undefined, }; }), );