mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: NLP Value update DTO + base logic
This commit is contained in:
parent
16e34531b0
commit
2744c51736
@ -168,10 +168,7 @@ export class NlpValueController extends BaseController<
|
||||
@Param('id') id: string,
|
||||
@Body() updateNlpValueDto: NlpValueUpdateDto,
|
||||
): Promise<NlpValue> {
|
||||
const result = await this.nlpValueService.updateOne(id, {
|
||||
...updateNlpValueDto,
|
||||
entity: updateNlpValueDto.entity || undefined,
|
||||
});
|
||||
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`);
|
||||
|
@ -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).
|
||||
*/
|
||||
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsArray,
|
||||
@ -52,8 +51,38 @@ export class NlpValueCreateDto {
|
||||
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<{
|
||||
create: NlpValueCreateDto;
|
||||
update: NlpValueUpdateDto;
|
||||
}>;
|
||||
|
@ -478,7 +478,7 @@ export abstract class BaseRepository<
|
||||
|
||||
async updateOne<D extends Partial<U>>(
|
||||
criteria: string | TFilterQuery<T>,
|
||||
dto: UpdateQuery<D>,
|
||||
dto: UpdateQuery<DtoInfer<DtoAction.Update, Dto, D>>,
|
||||
options: QueryOptions<D> | null = {
|
||||
new: true,
|
||||
},
|
||||
|
@ -177,7 +177,7 @@ export abstract class BaseService<
|
||||
|
||||
async updateOne(
|
||||
criteria: string | TFilterQuery<T>,
|
||||
dto: Partial<U>,
|
||||
dto: DtoInfer<DtoAction.Update, Dto, Partial<U>>,
|
||||
options?: QueryOptions<Partial<U>> | null,
|
||||
): Promise<T | null> {
|
||||
return await this.repository.updateOne(criteria, dto, options);
|
||||
|
Loading…
Reference in New Issue
Block a user