mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: implement dynamic create DTO for Label
This commit is contained in:
parent
df8e48a830
commit
dc7d451378
@ -9,12 +9,14 @@
|
||||
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
IsObject,
|
||||
} from 'class-validator';
|
||||
|
||||
import { DtoConfig } from '@/utils/types/dto.types';
|
||||
|
||||
export class LabelCreateDto {
|
||||
@ApiProperty({ description: 'Label title', type: String })
|
||||
@IsNotEmpty()
|
||||
@ -39,3 +41,7 @@ export class LabelCreateDto {
|
||||
}
|
||||
|
||||
export class LabelUpdateDto extends PartialType(LabelCreateDto) {}
|
||||
|
||||
export type LabelDtoMapActions = DtoConfig<{
|
||||
create: LabelCreateDto;
|
||||
}>;
|
||||
|
@ -14,6 +14,7 @@ import { Document, Model, Query } from 'mongoose';
|
||||
import { BaseRepository, DeleteResult } from '@/utils/generics/base-repository';
|
||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||
|
||||
import { LabelDtoMapActions } from '../dto/label.dto';
|
||||
import {
|
||||
Label,
|
||||
LABEL_POPULATE,
|
||||
@ -26,7 +27,8 @@ import {
|
||||
export class LabelRepository extends BaseRepository<
|
||||
Label,
|
||||
LabelPopulate,
|
||||
LabelFull
|
||||
LabelFull,
|
||||
LabelDtoMapActions
|
||||
> {
|
||||
constructor(
|
||||
readonly eventEmitter: EventEmitter2,
|
||||
|
@ -43,13 +43,13 @@ export class LabelStub extends BaseSchema {
|
||||
@Prop({
|
||||
type: String,
|
||||
})
|
||||
description?: string;
|
||||
description: string;
|
||||
|
||||
@Prop({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
builtin?: boolean;
|
||||
builtin: boolean;
|
||||
}
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
|
@ -10,11 +10,17 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { BaseService } from '@/utils/generics/base-service';
|
||||
|
||||
import { LabelDtoMapActions } from '../dto/label.dto';
|
||||
import { LabelRepository } from '../repositories/label.repository';
|
||||
import { Label, LabelFull, LabelPopulate } from '../schemas/label.schema';
|
||||
|
||||
@Injectable()
|
||||
export class LabelService extends BaseService<Label, LabelPopulate, LabelFull> {
|
||||
export class LabelService extends BaseService<
|
||||
Label,
|
||||
LabelPopulate,
|
||||
LabelFull,
|
||||
LabelDtoMapActions
|
||||
> {
|
||||
constructor(readonly repository: LabelRepository) {
|
||||
super(repository);
|
||||
}
|
||||
|
24
api/src/utils/test/fixtures/label.ts
vendored
24
api/src/utils/test/fixtures/label.ts
vendored
@ -8,13 +8,23 @@
|
||||
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import { LabelCreateDto } from '@/chat/dto/label.dto';
|
||||
import { Label, LabelModel } from '@/chat/schemas/label.schema';
|
||||
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||
|
||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||
import { TFixturesDefaultValues } from '../types';
|
||||
|
||||
export const labels: LabelCreateDto[] = [
|
||||
export const fieldsWithDefaultValues = {
|
||||
builtin: false,
|
||||
} satisfies Partial<Label>;
|
||||
|
||||
type TFieldWithDefaultValues =
|
||||
| keyof typeof fieldsWithDefaultValues
|
||||
| keyof BaseSchema;
|
||||
type TTransformedField<T> = Omit<T, TFieldWithDefaultValues> &
|
||||
Partial<Pick<Label, TFieldWithDefaultValues>>;
|
||||
type TLabel = TTransformedField<Label>;
|
||||
|
||||
export const labels: TLabel[] = [
|
||||
{
|
||||
description: 'test description 1',
|
||||
label_id: {
|
||||
@ -39,13 +49,9 @@ export const labels: LabelCreateDto[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const labelDefaultValues: TFixturesDefaultValues<Label> = {
|
||||
builtin: false,
|
||||
};
|
||||
|
||||
export const labelFixtures = getFixturesWithDefaultValues<Label>({
|
||||
export const labelFixtures = getFixturesWithDefaultValues<TLabel>({
|
||||
fixtures: labels,
|
||||
defaultValues: labelDefaultValues,
|
||||
defaultValues: fieldsWithDefaultValues,
|
||||
});
|
||||
|
||||
export const installLabelFixtures = async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user