mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: restore conflict exception
This commit is contained in:
parent
f2fede7e68
commit
6ba4c76440
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user