From c9f411e813ef0be3db3c55e57226786aaf1e7939 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Wed, 15 Jan 2025 12:11:20 +0100 Subject: [PATCH] fix: feedback udaptes --- .../controllers/attachment.controller.ts | 2 +- .../attachment/services/attachment.service.ts | 10 ++++++++-- .../extensions/helpers/llm-nlu/index.helper.ts | 2 +- .../nlp/controllers/nlp-value.controller.spec.ts | 4 ++-- api/src/utils/pipes/object-id.pipe.ts | 16 ++++++++++++---- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/api/src/attachment/controllers/attachment.controller.ts b/api/src/attachment/controllers/attachment.controller.ts index 90964dea..3607903f 100644 --- a/api/src/attachment/controllers/attachment.controller.ts +++ b/api/src/attachment/controllers/attachment.controller.ts @@ -146,7 +146,7 @@ export class AttachmentController extends BaseController { @Get('download/:id/:filename?') async download( @Param() params: AttachmentDownloadDto, - ): Promise { + ): Promise { const attachment = await this.attachmentService.findOne(params.id); if (!attachment) { diff --git a/api/src/attachment/services/attachment.service.ts b/api/src/attachment/services/attachment.service.ts index 665e0d2b..3cdae64a 100644 --- a/api/src/attachment/services/attachment.service.ts +++ b/api/src/attachment/services/attachment.service.ts @@ -256,9 +256,15 @@ export class AttachmentService extends BaseService { async download( attachment: Attachment, rootDir = config.parameters.uploadDir, - ) { + ): Promise { if (this.getStoragePlugin()) { - return await this.getStoragePlugin()?.download(attachment); + const streamableFile = + await this.getStoragePlugin()?.download(attachment); + if (!streamableFile) { + throw new NotFoundException('No file was found'); + } + + return streamableFile; } else { const path = resolve(join(rootDir, attachment.location)); diff --git a/api/src/extensions/helpers/llm-nlu/index.helper.ts b/api/src/extensions/helpers/llm-nlu/index.helper.ts index 8591d954..6e7022c4 100644 --- a/api/src/extensions/helpers/llm-nlu/index.helper.ts +++ b/api/src/extensions/helpers/llm-nlu/index.helper.ts @@ -146,7 +146,7 @@ export default class LlmNluHelper { entity: 'language', value: language || defaultLanguage.code, - confidence: 0.0, + confidence: 100, }, ]; for await (const { name, doc, prompt, values } of this diff --git a/api/src/nlp/controllers/nlp-value.controller.spec.ts b/api/src/nlp/controllers/nlp-value.controller.spec.ts index 97b7c437..cb535137 100644 --- a/api/src/nlp/controllers/nlp-value.controller.spec.ts +++ b/api/src/nlp/controllers/nlp-value.controller.spec.ts @@ -125,7 +125,7 @@ describe('NlpValueController', () => { (acc, curr) => { const ValueWithEntities = { ...curr, - entity: nlpEntities[parseInt(curr.entity!)].id, + entity: curr.entity ? nlpEntities[parseInt(curr.entity!)].id : null, expressions: curr.expressions!, metadata: curr.metadata!, builtin: curr.builtin!, @@ -133,7 +133,7 @@ describe('NlpValueController', () => { acc.push(ValueWithEntities); return acc; }, - [] as TFixtures[], + [] as TFixtures[], ); expect(result).toEqualPayload(nlpValueFixturesWithEntities); }); diff --git a/api/src/utils/pipes/object-id.pipe.ts b/api/src/utils/pipes/object-id.pipe.ts index 4685e6ff..135a6b55 100644 --- a/api/src/utils/pipes/object-id.pipe.ts +++ b/api/src/utils/pipes/object-id.pipe.ts @@ -33,8 +33,13 @@ export class ObjectIdPipe implements PipeTransform> { async transform(value: string, { type, data }: ArgumentMetadata) { if (typeof value === 'string' && data === 'id' && type === 'param') { const errors = await this.getErrors(value); - if (errors?.constraints) - throw new BadRequestException(Object.values(errors.constraints)[0]); + if (errors) { + throw new BadRequestException( + errors?.constraints + ? Object.values(errors.constraints)[0] + : errors.toString(), + ); + } } else if ( typeof value === 'object' && Object.keys(value).length > 1 && @@ -45,10 +50,13 @@ export class ObjectIdPipe implements PipeTransform> { if (param.startsWith('id')) { const errors = await this.getErrors(String(paramValue)); - if (errors?.constraints) + if (errors) { throw new BadRequestException( - Object.values(errors.constraints)[0], + errors?.constraints + ? Object.values(errors.constraints)[0] + : errors.toString(), ); + } } }), );