feat(api): add nlp pattern lookup strategy

This commit is contained in:
Mohamed Marrouchi
2025-05-13 10:56:55 +01:00
parent e2d6d15215
commit 9e0df0d530
9 changed files with 66 additions and 21 deletions

View File

@@ -95,7 +95,7 @@ describe('NlpValueController', () => {
entity: nlpEntities[0].id,
value: 'valuetest',
expressions: ['synonym1', 'synonym2'],
metadata: { firstkey: 'firstvalue', secondKey: 1995 },
metadata: {},
builtin: false,
doc: '',
};

View File

@@ -71,14 +71,17 @@ export class NlpValueController extends BaseController<
async create(
@Body() createNlpValueDto: NlpValueCreateDto,
): Promise<NlpValue> {
const nlpEntity = createNlpValueDto.entity
? await this.nlpEntityService.findOne(createNlpValueDto.entity!)
: null;
this.validate({
dto: createNlpValueDto,
allowedIds: {
entity: createNlpValueDto.entity
? (await this.nlpEntityService.findOne(createNlpValueDto.entity))?.id
: null,
entity: nlpEntity?.id,
},
});
return await this.nlpValueService.create(createNlpValueDto);
}
@@ -171,6 +174,17 @@ export class NlpValueController extends BaseController<
@Param('id') id: string,
@Body() updateNlpValueDto: NlpValueUpdateDto,
): Promise<NlpValue> {
const nlpEntity = updateNlpValueDto.entity
? await this.nlpEntityService.findOne(updateNlpValueDto.entity!)
: null;
this.validate({
dto: updateNlpValueDto,
allowedIds: {
entity: nlpEntity?.id,
},
});
return await this.nlpValueService.updateOne(id, updateNlpValueDto);
}