fix(api): apply feedbacks

This commit is contained in:
yassinedorbozgithub 2025-01-08 16:39:17 +01:00
parent 54e5a38661
commit f9f764f3fe
5 changed files with 13 additions and 11 deletions

View File

@ -179,13 +179,13 @@ export class BlockRepository extends BaseRepository<
): Promise<void> { ): Promise<void> {
for (const id of ids) { for (const id of ids) {
const oldState = await this.findOne(id); const oldState = await this.findOne(id);
if (oldState?.category !== category) { if (oldState && oldState.category !== category) {
const updatedNextBlocks = oldState?.nextBlocks?.filter((nextBlock) => const updatedNextBlocks = oldState.nextBlocks?.filter((nextBlock) =>
ids.includes(nextBlock), ids.includes(nextBlock),
); );
const updatedAttachedBlock = ids.includes(oldState?.attachedBlock || '') const updatedAttachedBlock = ids.includes(oldState.attachedBlock || '')
? oldState?.attachedBlock ? oldState.attachedBlock
: null; : null;
await this.updateOne(id, { await this.updateOne(id, {
@ -209,7 +209,7 @@ export class BlockRepository extends BaseRepository<
ids: string[], ids: string[],
): Promise<void> { ): Promise<void> {
for (const block of otherBlocks) { for (const block of otherBlocks) {
if (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 });
} }

View File

@ -240,7 +240,7 @@ export class BotService {
event.getMessageType() === IncomingMessageType.message && event.getMessageType() === IncomingMessageType.message &&
fallbackOptions.active && fallbackOptions.active &&
convo.context?.attempt && convo.context?.attempt &&
convo.context?.attempt < fallbackOptions.max_attempts convo.context.attempt < fallbackOptions.max_attempts
) { ) {
// Trigger block fallback // Trigger block fallback
// NOTE : current is not populated, this may cause some anomaly // NOTE : current is not populated, this may cause some anomaly

View File

@ -59,7 +59,7 @@ export class MenuStub extends BaseSchema {
@Schema({ timestamps: true }) @Schema({ timestamps: true })
export class Menu extends MenuStub { export class Menu extends MenuStub {
@Transform(({ obj }) => obj.parent?.toString()) @Transform(({ obj }) => obj.parent?.toString())
parent?: string | undefined; parent?: string;
} }
@Schema({ timestamps: true }) @Schema({ timestamps: true })

View File

@ -126,7 +126,9 @@ export class MenuService extends BaseService<Menu, MenuPopulate, MenuFull> {
parent: string | symbol = this.RootSymbol, parent: string | symbol = this.RootSymbol,
): MenuTree { ): MenuTree {
const item = parents.get(parent); const item = parents.get(parent);
if (!item) return []; if (!item) {
return [];
}
const children: MenuTree = item.map((menu) => { const children: MenuTree = item.map((menu) => {
return { return {
...menu, ...menu,

View File

@ -108,7 +108,7 @@ export const installMenuFixtures = async () => {
const offerDocs = await Menu.insertMany( const offerDocs = await Menu.insertMany(
offersMenuFixtures.map((m) => ({ offersMenuFixtures.map((m) => ({
...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( await Menu.insertMany(
devicesMenuFixtures.map((m) => ({ devicesMenuFixtures.map((m) => ({
...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) => { accountMenuFixtures.map((m) => {
return { return {
...m, ...m,
parent: m.parent && docs[parseInt(m.parent)].id, parent: m.parent ? docs[parseInt(m.parent)].id : undefined,
}; };
}), }),
); );