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> {
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<void> {
for (const block of otherBlocks) {
if (ids.includes(block.attachedBlock || '')) {
if (block.attachedBlock && ids.includes(block.attachedBlock)) {
await this.updateOne(block.id, { attachedBlock: null });
}

View File

@ -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

View File

@ -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 })

View File

@ -126,7 +126,9 @@ export class MenuService extends BaseService<Menu, MenuPopulate, MenuFull> {
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,

View File

@ -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,
};
}),
);