add content

This commit is contained in:
liuyi 2025-05-19 21:04:15 +08:00
parent 56f85173cf
commit d61527709d
3 changed files with 96 additions and 2 deletions

View File

@ -24,7 +24,7 @@
"@nestjs/common": "^10.0.3",
"@nestjs/core": "^10.0.3",
"@nestjs/platform-fastify": "^10.0.3",
"@nestjs/swagger": "^7.0.4",
"@nestjs/swagger": "^7.4.2",
"@nestjs/typeorm": "^11.0.0",
"better-sqlite3": "^11.10.0",
"class-transformer": "^0.5.1",

View File

@ -18,7 +18,7 @@ importers:
specifier: ^10.0.3
version: 10.4.17(@nestjs/common@10.4.17(class-transformer@0.5.1)(class-validator@0.14.2)(reflect-metadata@0.1.14)(rxjs@7.8.2))(@nestjs/core@10.4.17)
'@nestjs/swagger':
specifier: ^7.0.4
specifier: ^7.4.2
version: 7.4.2(@nestjs/common@10.4.17(class-transformer@0.5.1)(class-validator@0.14.2)(reflect-metadata@0.1.14)(rxjs@7.8.2))(@nestjs/core@10.4.17)(class-transformer@0.5.1)(class-validator@0.14.2)(reflect-metadata@0.1.14)
'@nestjs/typeorm':
specifier: ^11.0.0

View File

@ -0,0 +1,94 @@
import { PartialType } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import {
IsBoolean,
IsDefined,
IsEnum,
IsNotEmpty,
IsNumber,
IsOptional,
IsUUID,
MaxLength,
Min,
ValidateIf,
} from 'class-validator';
import { isNil, toNumber } from 'lodash';
import { PostOrder } from '@/modules/content/constants';
import { toBoolean } from '@/modules/core/helpers';
import { PaginateOptions } from '@/modules/database/types';
export class QueryPostDto implements PaginateOptions {
@Transform(({ value }) => toBoolean(value))
@IsBoolean()
@IsOptional()
isPublished?: boolean;
@IsEnum(PostOrder, { message: `` })
@IsOptional()
orderBy: PostOrder;
@Transform(({ value }) => toNumber(value))
@Min(1, { message: '' })
@IsNumber()
@IsOptional()
page = 1;
@Transform(({ value }) => toNumber(value))
@Min(1, { message: '' })
@IsNumber()
@IsOptional()
limit = 10;
}
export class CreatePostDto {
@MaxLength(255, {
always: true,
message: 'The maximum length of the article title is $constraint1',
})
@IsNotEmpty({ groups: ['create'], message: 'The article title must be filled in.' })
@IsOptional({ groups: ['update'] })
title: string;
@IsNotEmpty({ groups: ['create'], message: 'The content of the article must be filled in.' })
@IsOptional({ groups: ['update'] })
body: string;
@MaxLength(500, {
always: true,
message: 'The maximum length of the article description is $constraint1',
})
@IsOptional({ always: true })
summary?: string;
@Transform(({ value }) => toBoolean(value))
@IsBoolean({ always: true })
@ValidateIf((value) => !isNil(value.publish))
@IsOptional({ always: true })
publish?: boolean;
@MaxLength(20, {
always: true,
each: true,
message: 'The maximum length of each keyword is $constraint1',
})
@IsOptional({ always: true })
keywords?: string[];
@Transform(({ value }) => toNumber(value))
@Min(0, { message: 'The sorted value must be greater than 0.' })
@IsNumber(undefined, { always: true })
@IsOptional({ always: true })
customOrder?: number;
}
export class UpdatePostDto extends PartialType(CreatePostDto) {
@IsUUID(undefined, {
groups: ['update'],
message: 'The format of the article ID is incorrect.',
})
@IsDefined({ groups: ['update'], message: 'The article ID must be specified' })
id: string;
}