feat: implement strict null check

This commit is contained in:
yassinedorbozgithub
2025-01-13 20:10:19 +01:00
parent 11ef58d048
commit d2223d6bfd
19 changed files with 84 additions and 83 deletions

View File

@@ -109,7 +109,7 @@ describe('NlpEntityController', () => {
acc.push({
...curr,
values: nlpValueFixtures.filter(
({ entity }) => parseInt(entity) === index,
({ entity }) => parseInt(entity!) === index,
) as NlpEntityFull['values'],
lookups: curr.lookups!,
builtin: curr.builtin!,

View File

@@ -98,7 +98,7 @@ describe('NlpValueController', () => {
acc.push({
...curr,
entity: nlpEntityFixtures[
parseInt(curr.entity)
parseInt(curr.entity!)
] as NlpValueFull['entity'],
builtin: curr.builtin!,
expressions: curr.expressions!,
@@ -125,7 +125,7 @@ describe('NlpValueController', () => {
(acc, curr) => {
const ValueWithEntities = {
...curr,
entity: nlpEntities[parseInt(curr.entity)].id,
entity: nlpEntities[parseInt(curr.entity!)].id,
expressions: curr.expressions!,
metadata: curr.metadata!,
builtin: curr.builtin!,

View File

@@ -75,8 +75,9 @@ export class NlpValueController extends BaseController<
this.validate({
dto: createNlpValueDto,
allowedIds: {
entity: (await this.nlpEntityService.findOne(createNlpValueDto.entity))
?.id,
entity: createNlpValueDto.entity
? (await this.nlpEntityService.findOne(createNlpValueDto.entity))?.id
: null,
},
});
return await this.nlpValueService.create(createNlpValueDto);
@@ -167,7 +168,10 @@ export class NlpValueController extends BaseController<
@Param('id') id: string,
@Body() updateNlpValueDto: NlpValueUpdateDto,
): Promise<NlpValue> {
const result = await this.nlpValueService.updateOne(id, updateNlpValueDto);
const result = await this.nlpValueService.updateOne(id, {
...updateNlpValueDto,
entity: updateNlpValueDto.entity || undefined,
});
if (!result) {
this.logger.warn(`Unable to update NLP Value by id ${id}`);
throw new NotFoundException(`NLP Value with ID ${id} not found`);