mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
@@ -429,45 +429,4 @@ describe('NlpSampleController', () => {
|
||||
expect(result).toEqual({ success: true });
|
||||
});
|
||||
});
|
||||
describe('deleteMany', () => {
|
||||
it('should delete multiple nlp samples', async () => {
|
||||
const samplesToDelete = [
|
||||
(
|
||||
await nlpSampleService.findOne({
|
||||
text: 'How much does a BMW cost?',
|
||||
})
|
||||
).id,
|
||||
(
|
||||
await nlpSampleService.findOne({
|
||||
text: 'text1',
|
||||
})
|
||||
).id,
|
||||
];
|
||||
|
||||
const result = await nlpSampleController.deleteMany(samplesToDelete);
|
||||
|
||||
expect(result.deletedCount).toEqual(samplesToDelete.length);
|
||||
const remainingSamples = await nlpSampleService.find({
|
||||
_id: { $in: samplesToDelete },
|
||||
});
|
||||
expect(remainingSamples.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should throw BadRequestException when no IDs are provided', async () => {
|
||||
await expect(nlpSampleController.deleteMany([])).rejects.toThrow(
|
||||
BadRequestException,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw NotFoundException when provided IDs do not exist', async () => {
|
||||
const nonExistentIds = [
|
||||
'614c1b2f58f4f04c876d6b8d',
|
||||
'614c1b2f58f4f04c876d6b8e',
|
||||
];
|
||||
|
||||
await expect(
|
||||
nlpSampleController.deleteMany(nonExistentIds),
|
||||
).rejects.toThrow(NotFoundException);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,7 +37,6 @@ import { LanguageService } from '@/i18n/services/language.service';
|
||||
import { CsrfInterceptor } from '@/interceptors/csrf.interceptor';
|
||||
import { LoggerService } from '@/logger/logger.service';
|
||||
import { BaseController } from '@/utils/generics/base-controller';
|
||||
import { DeleteResult } from '@/utils/generics/base-repository';
|
||||
import { PageQueryDto } from '@/utils/pagination/pagination-query.dto';
|
||||
import { PageQueryPipe } from '@/utils/pagination/pagination-query.pipe';
|
||||
import { PopulatePipe } from '@/utils/pipes/populate.pipe';
|
||||
@@ -322,33 +321,6 @@ export class NlpSampleController extends BaseController<
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple NLP samples by their IDs.
|
||||
* @param ids - IDs of NLP samples to be deleted.
|
||||
* @returns A Promise that resolves to the deletion result.
|
||||
*/
|
||||
@CsrfCheck(true)
|
||||
@Delete('')
|
||||
@HttpCode(204)
|
||||
async deleteMany(@Body('ids') ids: string[]): Promise<DeleteResult> {
|
||||
if (!ids || ids.length === 0) {
|
||||
throw new BadRequestException('No IDs provided for deletion.');
|
||||
}
|
||||
const deleteResult = await this.nlpSampleService.deleteMany({
|
||||
_id: { $in: ids },
|
||||
});
|
||||
|
||||
if (deleteResult.deletedCount === 0) {
|
||||
this.logger.warn(
|
||||
`Unable to delete NLP samples with provided IDs: ${ids}`,
|
||||
);
|
||||
throw new NotFoundException('NLP samples with provided IDs not found');
|
||||
}
|
||||
|
||||
this.logger.log(`Successfully deleted NLP samples with IDs: ${ids}`);
|
||||
return deleteResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports NLP samples from a CSV file.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user