diff --git a/api/src/nlp/controllers/nlp-entity.controller.spec.ts b/api/src/nlp/controllers/nlp-entity.controller.spec.ts index 6e82b9cd..2f57c62f 100644 --- a/api/src/nlp/controllers/nlp-entity.controller.spec.ts +++ b/api/src/nlp/controllers/nlp-entity.controller.spec.ts @@ -9,6 +9,7 @@ import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { BadRequestException, + ConflictException, MethodNotAllowedException, NotFoundException, } from '@nestjs/common'; @@ -289,6 +290,17 @@ describe('NlpEntityController', () => { expect(result.weight).toBe(updatedNlpEntity.weight); }); + it('should throw an exception if entity is builtin but weight not provided', async () => { + await expect( + nlpEntityController.updateOne(buitInEntityId!, { + name: 'updated', + doc: '', + lookups: ['trait'], + builtin: false, + } as any), + ).rejects.toThrow(ConflictException); + }); + it('should update only the weight of the builtin entity', async () => { const updatedNlpEntity: NlpEntityUpdateDto = { weight: 8, diff --git a/api/src/nlp/controllers/nlp-entity.controller.ts b/api/src/nlp/controllers/nlp-entity.controller.ts index 32d22b11..1deb0c83 100644 --- a/api/src/nlp/controllers/nlp-entity.controller.ts +++ b/api/src/nlp/controllers/nlp-entity.controller.ts @@ -9,6 +9,7 @@ import { BadRequestException, Body, + ConflictException, Controller, Delete, Get, @@ -158,9 +159,18 @@ export class NlpEntityController extends BaseController< throw new NotFoundException(`NLP Entity with ID ${id} not found`); } - if (nlpEntity.builtin && nlpEntityDto.weight) { - // Only allow weight update for builtin entities - return await this.nlpEntityService.updateWeight(id, nlpEntityDto.weight); + if (nlpEntity.builtin) { + if (nlpEntityDto.weight) { + // Only allow weight update for builtin entities + return await this.nlpEntityService.updateWeight( + id, + nlpEntityDto.weight, + ); + } else { + throw new ConflictException( + `Cannot update builtin NLP Entity ${nlpEntity.name} except for weight`, + ); + } } return await this.nlpEntityService.updateOne(id, nlpEntityDto);