mirror of
https://github.com/hexastack/hexabot
synced 2025-04-16 21:56:00 +00:00
fix: apply feedbacks
This commit is contained in:
parent
542a02ac05
commit
008e6e43db
@ -151,7 +151,7 @@ export default abstract class BaseNlpHelper<
|
|||||||
})
|
})
|
||||||
.concat({
|
.concat({
|
||||||
entity: 'language',
|
entity: 'language',
|
||||||
value: s.language.code,
|
value: s.language!.code,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -11,9 +11,11 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
Injectable,
|
Injectable,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Cache } from 'cache-manager';
|
import { Cache } from 'cache-manager';
|
||||||
|
|
||||||
|
import { LoggerService } from '@/logger/logger.service';
|
||||||
import {
|
import {
|
||||||
DEFAULT_LANGUAGE_CACHE_KEY,
|
DEFAULT_LANGUAGE_CACHE_KEY,
|
||||||
LANGUAGES_CACHE_KEY,
|
LANGUAGES_CACHE_KEY,
|
||||||
@ -29,6 +31,7 @@ export class LanguageService extends BaseService<Language> {
|
|||||||
constructor(
|
constructor(
|
||||||
readonly repository: LanguageRepository,
|
readonly repository: LanguageRepository,
|
||||||
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
|
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
|
||||||
|
private readonly logger: LoggerService,
|
||||||
) {
|
) {
|
||||||
super(repository);
|
super(repository);
|
||||||
}
|
}
|
||||||
@ -72,6 +75,15 @@ export class LanguageService extends BaseService<Language> {
|
|||||||
* @returns A promise that resolves to the `Language` object.
|
* @returns A promise that resolves to the `Language` object.
|
||||||
*/
|
*/
|
||||||
async getLanguageByCode(code: string) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ export class NlpSampleController extends BaseController<
|
|||||||
);
|
);
|
||||||
const entities = await this.nlpEntityService.findAllAndPopulate();
|
const entities = await this.nlpEntityService.findAllAndPopulate();
|
||||||
const helper = await this.helperService.getDefaultNluHelper();
|
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
|
// Sending the JSON data as a file
|
||||||
const buffer = Buffer.from(JSON.stringify(result));
|
const buffer = Buffer.from(JSON.stringify(result));
|
||||||
@ -129,11 +129,6 @@ export class NlpSampleController extends BaseController<
|
|||||||
): Promise<NlpSampleFull> {
|
): Promise<NlpSampleFull> {
|
||||||
const language = await this.languageService.getLanguageByCode(languageCode);
|
const language = await this.languageService.getLanguageByCode(languageCode);
|
||||||
|
|
||||||
if (!language)
|
|
||||||
throw new NotFoundException(
|
|
||||||
`Language with code ${languageCode} not found`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const nlpSample = await this.nlpSampleService.create({
|
const nlpSample = await this.nlpSampleService.create({
|
||||||
...createNlpSampleDto,
|
...createNlpSampleDto,
|
||||||
language: language.id,
|
language: language.id,
|
||||||
@ -303,13 +298,6 @@ export class NlpSampleController extends BaseController<
|
|||||||
): Promise<NlpSampleFull> {
|
): Promise<NlpSampleFull> {
|
||||||
const language = await this.languageService.getLanguageByCode(languageCode);
|
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, {
|
const sample = await this.nlpSampleService.updateOne(id, {
|
||||||
...sampleAttrs,
|
...sampleAttrs,
|
||||||
language: language.id,
|
language: language.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user