fix: NLP Value update DTO + base logic

This commit is contained in:
yassinedorbozgithub 2025-01-15 11:45:44 +01:00
parent 16e34531b0
commit 2744c51736
4 changed files with 34 additions and 8 deletions

View File

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

View File

@ -6,7 +6,6 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { PartialType } from '@nestjs/mapped-types';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { import {
IsArray, IsArray,
@ -52,8 +51,38 @@ export class NlpValueCreateDto {
entity: string | null; entity: string | null;
} }
export class NlpValueUpdateDto extends PartialType(NlpValueCreateDto) {} export class NlpValueUpdateDto {
@ApiPropertyOptional({ description: 'Foreign ID', type: String })
@IsOptional()
@IsString()
foreign_id?: string;
@ApiPropertyOptional({ description: 'Nlp value', type: String })
@IsOptional()
@IsString()
value?: string;
@ApiPropertyOptional({
description: 'Nlp value expressions',
isArray: true,
type: Array,
})
@IsOptional()
@IsArray()
expressions?: string[];
@ApiPropertyOptional({ description: 'Nlp value entity', type: String })
@IsString()
@IsObjectId({ message: 'Entity must be a valid ObjectId' })
entity?: string | null;
@ApiPropertyOptional({ description: 'Nlp value is builtin', type: Boolean })
@IsOptional()
@IsBoolean()
builtin?: boolean;
}
export type NlpValueDto = DtoConfig<{ export type NlpValueDto = DtoConfig<{
create: NlpValueCreateDto; create: NlpValueCreateDto;
update: NlpValueUpdateDto;
}>; }>;

View File

@ -478,7 +478,7 @@ export abstract class BaseRepository<
async updateOne<D extends Partial<U>>( async updateOne<D extends Partial<U>>(
criteria: string | TFilterQuery<T>, criteria: string | TFilterQuery<T>,
dto: UpdateQuery<D>, dto: UpdateQuery<DtoInfer<DtoAction.Update, Dto, D>>,
options: QueryOptions<D> | null = { options: QueryOptions<D> | null = {
new: true, new: true,
}, },

View File

@ -177,7 +177,7 @@ export abstract class BaseService<
async updateOne( async updateOne(
criteria: string | TFilterQuery<T>, criteria: string | TFilterQuery<T>,
dto: Partial<U>, dto: DtoInfer<DtoAction.Update, Dto, Partial<U>>,
options?: QueryOptions<Partial<U>> | null, options?: QueryOptions<Partial<U>> | null,
): Promise<T | null> { ): Promise<T | null> {
return await this.repository.updateOne(criteria, dto, options); return await this.repository.updateOne(criteria, dto, options);