mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
refactor(api): Refactor updateOne logic
This commit is contained in:
@@ -167,17 +167,7 @@ export class NlpEntityController extends BaseController<
|
||||
);
|
||||
}
|
||||
|
||||
const result = await this.nlpEntityService.updateOne(
|
||||
id,
|
||||
updateNlpEntityDto,
|
||||
);
|
||||
if (!result) {
|
||||
this.logger.warn(`Failed to update NLP Entity by id ${id}`);
|
||||
throw new InternalServerErrorException(
|
||||
`Failed to update NLP Entity with ID ${id}`,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
return await this.nlpEntityService.updateOne(id, updateNlpEntityDto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import { SettingRepository } from '@/setting/repositories/setting.repository';
|
||||
import { SettingModel } from '@/setting/schemas/setting.schema';
|
||||
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
||||
import { SettingService } from '@/setting/services/setting.service';
|
||||
import { getUpdateOneError } from '@/utils/test/errors/messages';
|
||||
import { installAttachmentFixtures } from '@/utils/test/fixtures/attachment';
|
||||
import { nlpSampleFixtures } from '@/utils/test/fixtures/nlpsample';
|
||||
import { installNlpSampleEntityFixtures } from '@/utils/test/fixtures/nlpsampleentity';
|
||||
@@ -310,7 +311,7 @@ describe('NlpSampleController', () => {
|
||||
type: NlpSampleState.test,
|
||||
language: 'fr',
|
||||
}),
|
||||
).rejects.toThrow(NotFoundException);
|
||||
).rejects.toThrow(getUpdateOneError(NlpSample.name, byeJhonSampleId!));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -305,11 +305,6 @@ export class NlpSampleController extends BaseController<
|
||||
trained: false,
|
||||
});
|
||||
|
||||
if (!sample) {
|
||||
this.logger.warn(`Unable to update NLP Sample by id ${id}`);
|
||||
throw new NotFoundException(`NLP Sample with ID ${id} not found`);
|
||||
}
|
||||
|
||||
await this.nlpSampleEntityService.deleteMany({ sample: id });
|
||||
|
||||
const updatedSampleEntities =
|
||||
|
||||
@@ -12,6 +12,7 @@ import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { LoggerService } from '@/logger/logger.service';
|
||||
import { getUpdateOneError } from '@/utils/test/errors/messages';
|
||||
import { nlpEntityFixtures } from '@/utils/test/fixtures/nlpentity';
|
||||
import {
|
||||
installNlpValueFixtures,
|
||||
@@ -241,7 +242,7 @@ describe('NlpValueController', () => {
|
||||
expressions: [],
|
||||
builtin: true,
|
||||
}),
|
||||
).rejects.toThrow(NotFoundException);
|
||||
).rejects.toThrow(getUpdateOneError(NlpValue.name, jhonNlpValue!.id));
|
||||
});
|
||||
});
|
||||
describe('deleteMany', () => {
|
||||
|
||||
@@ -168,12 +168,7 @@ export class NlpValueController extends BaseController<
|
||||
@Param('id') id: string,
|
||||
@Body() updateNlpValueDto: NlpValueUpdateDto,
|
||||
): Promise<NlpValue> {
|
||||
const result = await this.nlpValueService.updateOne(id, updateNlpValueDto);
|
||||
if (!result) {
|
||||
this.logger.warn(`Unable to update NLP Value by id ${id}`);
|
||||
throw new NotFoundException(`NLP Value with ID ${id} not found`);
|
||||
}
|
||||
return result;
|
||||
return await this.nlpValueService.updateOne(id, updateNlpValueDto);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user