mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
feat: implement dynamic create DTO for Category
This commit is contained in:
parent
21b2f46f4c
commit
9e49e8256e
@ -8,14 +8,16 @@
|
||||
|
||||
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsNumber,
|
||||
IsArray,
|
||||
} from 'class-validator';
|
||||
|
||||
import { DtoConfig } from '@/utils/types/dto.types';
|
||||
|
||||
export class CategoryCreateDto {
|
||||
@ApiProperty({ description: 'Category label', type: String })
|
||||
@IsNotEmpty()
|
||||
@ -39,3 +41,7 @@ export class CategoryCreateDto {
|
||||
}
|
||||
|
||||
export class CategoryUpdateDto extends PartialType(CategoryCreateDto) {}
|
||||
|
||||
export type CategoryDTOMapActions = DtoConfig<{
|
||||
create: CategoryCreateDto;
|
||||
}>;
|
||||
|
@ -14,11 +14,17 @@ import { Document, Model, Query } from 'mongoose';
|
||||
import { BaseRepository, DeleteResult } from '@/utils/generics/base-repository';
|
||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||
|
||||
import { CategoryDTOMapActions } from '../dto/category.dto';
|
||||
import { Category } from '../schemas/category.schema';
|
||||
import { BlockService } from '../services/block.service';
|
||||
|
||||
@Injectable()
|
||||
export class CategoryRepository extends BaseRepository<Category> {
|
||||
export class CategoryRepository extends BaseRepository<
|
||||
Category,
|
||||
never,
|
||||
never,
|
||||
CategoryDTOMapActions
|
||||
> {
|
||||
private readonly blockService: BlockService;
|
||||
|
||||
constructor(
|
||||
|
@ -25,19 +25,19 @@ export class Category extends BaseSchema {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
builtin?: boolean;
|
||||
builtin: boolean;
|
||||
|
||||
@Prop({
|
||||
type: Number,
|
||||
default: 100,
|
||||
})
|
||||
zoom?: number;
|
||||
zoom: number;
|
||||
|
||||
@Prop({
|
||||
type: [Number, Number],
|
||||
default: [0, 0],
|
||||
})
|
||||
offset?: [number, number];
|
||||
offset: [number, number];
|
||||
}
|
||||
|
||||
export const CategoryModel: ModelDefinition = LifecycleHookManager.attach({
|
||||
|
@ -10,11 +10,17 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { BaseSeeder } from '@/utils/generics/base-seeder';
|
||||
|
||||
import { CategoryDTOMapActions } from '../dto/category.dto';
|
||||
import { CategoryRepository } from '../repositories/category.repository';
|
||||
import { Category } from '../schemas/category.schema';
|
||||
|
||||
@Injectable()
|
||||
export class CategorySeeder extends BaseSeeder<Category> {
|
||||
export class CategorySeeder extends BaseSeeder<
|
||||
Category,
|
||||
never,
|
||||
never,
|
||||
CategoryDTOMapActions
|
||||
> {
|
||||
constructor(private readonly categoryRepository: CategoryRepository) {
|
||||
super(categoryRepository);
|
||||
}
|
||||
|
@ -10,11 +10,17 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { BaseService } from '@/utils/generics/base-service';
|
||||
|
||||
import { CategoryDTOMapActions } from '../dto/category.dto';
|
||||
import { CategoryRepository } from '../repositories/category.repository';
|
||||
import { Category } from '../schemas/category.schema';
|
||||
|
||||
@Injectable()
|
||||
export class CategoryService extends BaseService<Category> {
|
||||
export class CategoryService extends BaseService<
|
||||
Category,
|
||||
never,
|
||||
never,
|
||||
CategoryDTOMapActions
|
||||
> {
|
||||
constructor(readonly repository: CategoryRepository) {
|
||||
super(repository);
|
||||
}
|
||||
|
30
api/src/utils/test/fixtures/category.ts
vendored
30
api/src/utils/test/fixtures/category.ts
vendored
@ -8,13 +8,25 @@
|
||||
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import { CategoryCreateDto } from '@/chat/dto/category.dto';
|
||||
import { CategoryModel, Category } from '@/chat/schemas/category.schema';
|
||||
import { Category, CategoryModel } from '@/chat/schemas/category.schema';
|
||||
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||
|
||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||
import { TFixturesDefaultValues } from '../types';
|
||||
|
||||
export const categories: CategoryCreateDto[] = [
|
||||
export const fieldsWithDefaultValues = {
|
||||
builtin: false,
|
||||
zoom: 100,
|
||||
offset: [0, 0],
|
||||
} satisfies Partial<Category>;
|
||||
|
||||
type TFieldWithDefaultValues =
|
||||
| keyof typeof fieldsWithDefaultValues
|
||||
| keyof BaseSchema;
|
||||
type TTransformedField<T> = Omit<T, TFieldWithDefaultValues> &
|
||||
Partial<Pick<Category, TFieldWithDefaultValues>>;
|
||||
type TCategory = TTransformedField<Category>;
|
||||
|
||||
export const categories: TCategory[] = [
|
||||
{
|
||||
label: 'test category 1',
|
||||
},
|
||||
@ -23,15 +35,9 @@ export const categories: CategoryCreateDto[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const categoryDefaultValues: TFixturesDefaultValues<Category> = {
|
||||
builtin: false,
|
||||
zoom: 100,
|
||||
offset: [0, 0],
|
||||
};
|
||||
|
||||
export const categoryFixtures = getFixturesWithDefaultValues<Category>({
|
||||
export const categoryFixtures = getFixturesWithDefaultValues<TCategory>({
|
||||
fixtures: categories,
|
||||
defaultValues: categoryDefaultValues,
|
||||
defaultValues: fieldsWithDefaultValues,
|
||||
});
|
||||
|
||||
export const installCategoryFixtures = async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user