mirror of
https://github.com/hexastack/hexabot
synced 2025-04-16 21:56:00 +00:00
feat: implement dynamic create DTO for Content
This commit is contained in:
parent
559c6c586f
commit
635687536b
@ -9,6 +9,7 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
||||||
import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
import { DtoConfig } from '@/utils/types/dto.types';
|
||||||
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
|
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
|
||||||
|
|
||||||
export class ContentCreateDto {
|
export class ContentCreateDto {
|
||||||
@ -34,3 +35,7 @@ export class ContentCreateDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ContentUpdateDto extends PartialType(ContentCreateDto) {}
|
export class ContentUpdateDto extends PartialType(ContentCreateDto) {}
|
||||||
|
|
||||||
|
export type ContentDTOMapActions = DtoConfig<{
|
||||||
|
create: ContentCreateDto;
|
||||||
|
}>;
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||||
|
|
||||||
|
import { ContentDTOMapActions } from '../dto/content.dto';
|
||||||
import {
|
import {
|
||||||
Content,
|
Content,
|
||||||
CONTENT_POPULATE,
|
CONTENT_POPULATE,
|
||||||
@ -32,7 +33,8 @@ import {
|
|||||||
export class ContentRepository extends BaseRepository<
|
export class ContentRepository extends BaseRepository<
|
||||||
Content,
|
Content,
|
||||||
ContentPopulate,
|
ContentPopulate,
|
||||||
ContentFull
|
ContentFull,
|
||||||
|
ContentDTOMapActions
|
||||||
> {
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly eventEmitter: EventEmitter2,
|
readonly eventEmitter: EventEmitter2,
|
||||||
|
@ -41,7 +41,7 @@ export class ContentStub extends BaseSchema {
|
|||||||
* Either of not this content is active.
|
* Either of not this content is active.
|
||||||
*/
|
*/
|
||||||
@Prop({ type: Boolean, default: true })
|
@Prop({ type: Boolean, default: true })
|
||||||
status?: boolean;
|
status: boolean;
|
||||||
|
|
||||||
@Prop({ type: mongoose.Schema.Types.Mixed })
|
@Prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
dynamicFields: Record<string, any>;
|
dynamicFields: Record<string, any>;
|
||||||
|
@ -19,6 +19,7 @@ import { LoggerService } from '@/logger/logger.service';
|
|||||||
import { BaseService } from '@/utils/generics/base-service';
|
import { BaseService } from '@/utils/generics/base-service';
|
||||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||||
|
|
||||||
|
import { ContentDTOMapActions } from '../dto/content.dto';
|
||||||
import { ContentRepository } from '../repositories/content.repository';
|
import { ContentRepository } from '../repositories/content.repository';
|
||||||
import {
|
import {
|
||||||
Content,
|
Content,
|
||||||
@ -30,7 +31,8 @@ import {
|
|||||||
export class ContentService extends BaseService<
|
export class ContentService extends BaseService<
|
||||||
Content,
|
Content,
|
||||||
ContentPopulate,
|
ContentPopulate,
|
||||||
ContentFull
|
ContentFull,
|
||||||
|
ContentDTOMapActions
|
||||||
> {
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly repository: ContentRepository,
|
readonly repository: ContentRepository,
|
||||||
|
25
api/src/utils/test/fixtures/content.ts
vendored
25
api/src/utils/test/fixtures/content.ts
vendored
@ -8,16 +8,26 @@
|
|||||||
|
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
import { ContentCreateDto } from '@/cms/dto/content.dto';
|
|
||||||
import { Content, ContentModel } from '@/cms/schemas/content.schema';
|
import { Content, ContentModel } from '@/cms/schemas/content.schema';
|
||||||
|
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||||
|
|
||||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||||
import { TFixturesDefaultValues } from '../types';
|
|
||||||
|
|
||||||
import { installAttachmentFixtures } from './attachment';
|
import { installAttachmentFixtures } from './attachment';
|
||||||
import { installContentTypeFixtures } from './contenttype';
|
import { installContentTypeFixtures } from './contenttype';
|
||||||
|
|
||||||
const contents: ContentCreateDto[] = [
|
export const fieldsWithDefaultValues = {
|
||||||
|
status: true,
|
||||||
|
} satisfies Partial<Content>;
|
||||||
|
|
||||||
|
type TFieldWithDefaultValues =
|
||||||
|
| keyof typeof fieldsWithDefaultValues
|
||||||
|
| keyof BaseSchema;
|
||||||
|
type TTransformedField<T> = Omit<T, TFieldWithDefaultValues> &
|
||||||
|
Partial<Pick<Content, TFieldWithDefaultValues>>;
|
||||||
|
type TContent = TTransformedField<Content>;
|
||||||
|
|
||||||
|
const contents: TContent[] = [
|
||||||
{
|
{
|
||||||
title: 'Jean',
|
title: 'Jean',
|
||||||
dynamicFields: {
|
dynamicFields: {
|
||||||
@ -131,14 +141,9 @@ const contents: ContentCreateDto[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const categoryDefaultValues: TFixturesDefaultValues<Content> = {
|
export const contentFixtures = getFixturesWithDefaultValues<TContent>({
|
||||||
status: true,
|
|
||||||
createdAt: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const contentFixtures = getFixturesWithDefaultValues<Content>({
|
|
||||||
fixtures: contents,
|
fixtures: contents,
|
||||||
defaultValues: categoryDefaultValues,
|
defaultValues: fieldsWithDefaultValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const installContentFixtures = async () => {
|
export const installContentFixtures = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user