fix: apply feedbacks

This commit is contained in:
yassinedorbozgithub 2025-01-10 15:16:27 +01:00
parent 542a02ac05
commit 008e6e43db
3 changed files with 15 additions and 15 deletions

View File

@ -151,7 +151,7 @@ export default abstract class BaseNlpHelper<
})
.concat({
entity: 'language',
value: s.language.code,
value: s.language!.code,
});
return {

View File

@ -11,9 +11,11 @@ import {
Inject,
Injectable,
InternalServerErrorException,
NotFoundException,
} from '@nestjs/common';
import { Cache } from 'cache-manager';
import { LoggerService } from '@/logger/logger.service';
import {
DEFAULT_LANGUAGE_CACHE_KEY,
LANGUAGES_CACHE_KEY,
@ -29,6 +31,7 @@ export class LanguageService extends BaseService<Language> {
constructor(
readonly repository: LanguageRepository,
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
private readonly logger: LoggerService,
) {
super(repository);
}
@ -72,6 +75,15 @@ export class LanguageService extends BaseService<Language> {
* @returns A promise that resolves to the `Language` object.
*/
async getLanguageByCode(code: string) {
return await this.findOne({ code });
const language = await this.findOne({ code });
if (!language) {
this.logger.warn(`Unable to Language by languageCode ${code}`);
throw new NotFoundException(
`Language with languageCode ${code} not found`,
);
}
return language;
}
}

View File

@ -91,7 +91,7 @@ export class NlpSampleController extends BaseController<
);
const entities = await this.nlpEntityService.findAllAndPopulate();
const helper = await this.helperService.getDefaultNluHelper();
const result = await helper.format?.(samples, entities);
const result = await helper.format(samples, entities);
// Sending the JSON data as a file
const buffer = Buffer.from(JSON.stringify(result));
@ -129,11 +129,6 @@ export class NlpSampleController extends BaseController<
): Promise<NlpSampleFull> {
const language = await this.languageService.getLanguageByCode(languageCode);
if (!language)
throw new NotFoundException(
`Language with code ${languageCode} not found`,
);
const nlpSample = await this.nlpSampleService.create({
...createNlpSampleDto,
language: language.id,
@ -303,13 +298,6 @@ export class NlpSampleController extends BaseController<
): Promise<NlpSampleFull> {
const language = await this.languageService.getLanguageByCode(languageCode);
if (!language) {
this.logger.warn(`Unable to Language by languageCode ${languageCode}`);
throw new NotFoundException(
`Language with languageCode ${languageCode} not found`,
);
}
const sample = await this.nlpSampleService.updateOne(id, {
...sampleAttrs,
language: language.id,