mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: implement dynamic create DTO for ContentType
This commit is contained in:
parent
7578c485f1
commit
559c6c586f
@ -9,16 +9,18 @@
|
||||
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
IsString,
|
||||
IsArray,
|
||||
ValidateNested,
|
||||
IsOptional,
|
||||
IsEnum,
|
||||
Matches,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
Validate,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
|
||||
import { DtoConfig } from '@/utils/types/dto.types';
|
||||
|
||||
import { ValidateRequiredFields } from '../validators/validate-required-fields.validator';
|
||||
|
||||
export class FieldType {
|
||||
@ -55,3 +57,7 @@ export class ContentTypeCreateDto {
|
||||
}
|
||||
|
||||
export class ContentTypeUpdateDto extends PartialType(ContentTypeCreateDto) {}
|
||||
|
||||
export type ContentTypeDtoMapActions = DtoConfig<{
|
||||
create: ContentTypeCreateDto;
|
||||
}>;
|
||||
|
@ -15,11 +15,17 @@ import { BlockService } from '@/chat/services/block.service';
|
||||
import { BaseRepository, DeleteResult } from '@/utils/generics/base-repository';
|
||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||
|
||||
import { ContentTypeDtoMapActions } from '../dto/contentType.dto';
|
||||
import { ContentType } from '../schemas/content-type.schema';
|
||||
import { Content } from '../schemas/content.schema';
|
||||
|
||||
@Injectable()
|
||||
export class ContentTypeRepository extends BaseRepository<ContentType> {
|
||||
export class ContentTypeRepository extends BaseRepository<
|
||||
ContentType,
|
||||
never,
|
||||
never,
|
||||
ContentTypeDtoMapActions
|
||||
> {
|
||||
constructor(
|
||||
readonly eventEmitter: EventEmitter2,
|
||||
@InjectModel(ContentType.name) readonly model: Model<ContentType>,
|
||||
|
@ -6,7 +6,7 @@
|
||||
* 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 { Prop, Schema, SchemaFactory, ModelDefinition } from '@nestjs/mongoose';
|
||||
import { ModelDefinition, Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||
@ -39,7 +39,7 @@ export class ContentType extends BaseSchema {
|
||||
},
|
||||
],
|
||||
})
|
||||
fields?: {
|
||||
fields: {
|
||||
name: string;
|
||||
label: string;
|
||||
type: string;
|
||||
|
@ -10,11 +10,17 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { BaseService } from '@/utils/generics/base-service';
|
||||
|
||||
import { ContentTypeDtoMapActions } from '../dto/contentType.dto';
|
||||
import { ContentTypeRepository } from '../repositories/content-type.repository';
|
||||
import { ContentType } from '../schemas/content-type.schema';
|
||||
|
||||
@Injectable()
|
||||
export class ContentTypeService extends BaseService<ContentType> {
|
||||
export class ContentTypeService extends BaseService<
|
||||
ContentType,
|
||||
never,
|
||||
never,
|
||||
ContentTypeDtoMapActions
|
||||
> {
|
||||
constructor(readonly repository: ContentTypeRepository) {
|
||||
super(repository);
|
||||
}
|
||||
|
46
api/src/utils/test/fixtures/contenttype.ts
vendored
46
api/src/utils/test/fixtures/contenttype.ts
vendored
@ -8,16 +8,37 @@
|
||||
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import { ContentTypeCreateDto } from '@/cms/dto/contentType.dto';
|
||||
import {
|
||||
ContentType,
|
||||
ContentTypeModel,
|
||||
} from '@/cms/schemas/content-type.schema';
|
||||
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||
|
||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||
import { TFixturesDefaultValues } from '../types';
|
||||
|
||||
const contentTypes: ContentTypeCreateDto[] = [
|
||||
export const fieldsWithDefaultValues = {
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
} satisfies Partial<ContentType>;
|
||||
|
||||
type TFieldWithDefaultValues =
|
||||
| keyof typeof fieldsWithDefaultValues
|
||||
| keyof BaseSchema;
|
||||
type TTransformedField<T> = Omit<T, TFieldWithDefaultValues> &
|
||||
Partial<Pick<ContentType, TFieldWithDefaultValues>>;
|
||||
type TContentType = TTransformedField<ContentType>;
|
||||
|
||||
const contentTypes: TContentType[] = [
|
||||
{
|
||||
name: 'Product',
|
||||
fields: [
|
||||
@ -100,24 +121,9 @@ const contentTypes: ContentTypeCreateDto[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const contentTypeDefaultValues: TFixturesDefaultValues<ContentType> = {
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const contentTypeFixtures = getFixturesWithDefaultValues<ContentType>({
|
||||
export const contentTypeFixtures = getFixturesWithDefaultValues<TContentType>({
|
||||
fixtures: contentTypes,
|
||||
defaultValues: contentTypeDefaultValues,
|
||||
defaultValues: fieldsWithDefaultValues,
|
||||
});
|
||||
|
||||
export const installContentTypeFixtures = async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user