mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(api): move builtin logic + adapt unit tests
This commit is contained in:
@@ -223,20 +223,6 @@ export class NlpEntityController extends BaseController<
|
||||
throw new BadRequestException('No IDs provided for deletion.');
|
||||
}
|
||||
|
||||
const { count: builtinNlpEntitiesCount } = await this.filterCount({
|
||||
_id: { $in: ids },
|
||||
builtin: true,
|
||||
});
|
||||
|
||||
if (builtinNlpEntitiesCount > 0) {
|
||||
this.logger.warn(
|
||||
`Unable to delete NLP entities with provided IDs: ${ids}`,
|
||||
);
|
||||
throw new MethodNotAllowedException(
|
||||
'Deletion failed: Selection includes built-in NLP entities that are protected',
|
||||
);
|
||||
}
|
||||
|
||||
const deleteResult = await this.nlpEntityService.deleteMany({
|
||||
_id: { $in: ids },
|
||||
});
|
||||
|
||||
@@ -163,7 +163,7 @@ describe('NlpValueController', () => {
|
||||
entity: intentNlpEntity!.id,
|
||||
value: 'updated',
|
||||
expressions: [],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
};
|
||||
const result = await nlpValueController.updateOne(
|
||||
@@ -191,7 +191,6 @@ describe('NlpValueController', () => {
|
||||
describe('deleteMany', () => {
|
||||
it('should delete multiple nlp values', async () => {
|
||||
const valuesToDelete = [positiveValue!.id, negativeValue!.id];
|
||||
|
||||
const result = await nlpValueController.deleteMany(valuesToDelete);
|
||||
|
||||
expect(result.deletedCount).toEqual(valuesToDelete.length);
|
||||
|
||||
@@ -232,7 +232,7 @@ describe('NlpEntityService', () => {
|
||||
{
|
||||
value: 'jhon',
|
||||
expressions: ['john', 'joohn', 'jhonny'],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -561,7 +561,7 @@ export abstract class BaseRepository<
|
||||
}
|
||||
|
||||
async deleteMany(criteria: TFilterQuery<T>): Promise<DeleteResult> {
|
||||
return await this.model.deleteMany(criteria);
|
||||
return await this.model.deleteMany({ ...criteria, builtin: { $ne: true } });
|
||||
}
|
||||
|
||||
async preCreateValidate(
|
||||
|
||||
10
api/src/utils/test/fixtures/nlpvalue.ts
vendored
10
api/src/utils/test/fixtures/nlpvalue.ts
vendored
@@ -18,35 +18,35 @@ export const nlpValueFixtures: NlpValueCreateDto[] = [
|
||||
entity: '0',
|
||||
value: 'positive',
|
||||
expressions: [],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
},
|
||||
{
|
||||
entity: '0',
|
||||
value: 'negative',
|
||||
expressions: [],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
},
|
||||
{
|
||||
entity: '1',
|
||||
value: 'jhon',
|
||||
expressions: ['john', 'joohn', 'jhonny'],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
},
|
||||
{
|
||||
entity: '0',
|
||||
value: 'greeting',
|
||||
expressions: ['heello', 'Hello', 'hi', 'heyy'],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
},
|
||||
{
|
||||
entity: '0',
|
||||
value: 'goodbye',
|
||||
expressions: ['bye', 'bye bye'],
|
||||
builtin: true,
|
||||
builtin: false,
|
||||
doc: '',
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user