add relations
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
IsDefined,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
MaxLength,
|
||||
Min,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { toNumber } from 'lodash';
|
||||
|
||||
import { PaginateOptions } from '@/modules/database/types';
|
||||
|
||||
export class QueryCategoryDto implements PaginateOptions {
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(1, { message: 'The current page must be greater than 1.' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
page = 1;
|
||||
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(1, { message: 'The number of data displayed per page must be greater than 1.' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
limit = 10;
|
||||
}
|
||||
|
||||
export class CreateCategoryDto {
|
||||
@MaxLength(25, {
|
||||
always: true,
|
||||
message: 'The length of the category name shall not exceed $constraint1',
|
||||
})
|
||||
@IsNotEmpty({ groups: ['create'], message: 'The classification name cannot be empty' })
|
||||
@IsOptional({ groups: ['update'] })
|
||||
name: string;
|
||||
|
||||
@IsUUID(undefined, {
|
||||
always: true,
|
||||
message: 'The format of the parent category ID is incorrect.',
|
||||
})
|
||||
@ValidateIf((value) => value.parent !== null && value.parent)
|
||||
@IsOptional({ always: true })
|
||||
@Transform((value) => (value === 'null' ? null : value))
|
||||
parent?: string;
|
||||
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(0, { always: true, message: 'The sorted value must be greater than 0.' })
|
||||
@IsNumber(undefined, { always: true })
|
||||
@IsOptional({ always: true })
|
||||
customOrder?: number = 0;
|
||||
}
|
||||
|
||||
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect', groups: ['update'] })
|
||||
@IsDefined({ groups: ['update'], message: 'The ID must be specified' })
|
||||
id: string;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { PickType } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
IsDefined,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
MaxLength,
|
||||
Min,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { toNumber } from 'lodash';
|
||||
|
||||
import { PaginateOptions } from '@/modules/database/types';
|
||||
|
||||
export class QueryCommentDto implements PaginateOptions {
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(1, { message: 'The current page must be greater than 1.' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
page = 1;
|
||||
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(1, { message: 'The number of data displayed per page must be greater than 1.' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
limit = 10;
|
||||
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect' })
|
||||
@IsOptional()
|
||||
post?: string;
|
||||
}
|
||||
|
||||
export class QueryCommentTreeDto extends PickType(QueryCommentDto, ['post']) {}
|
||||
|
||||
export class CreateCommentDto {
|
||||
@MaxLength(1000, { message: '' })
|
||||
@IsNotEmpty({ message: '' })
|
||||
body: string;
|
||||
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect' })
|
||||
@IsDefined({ message: 'The ID must be specified' })
|
||||
post: string;
|
||||
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect', always: true })
|
||||
@ValidateIf((value) => value.parent !== null && value.parent)
|
||||
@IsOptional({ always: true })
|
||||
@Transform(({ value }) => (value === 'null' ? null : value))
|
||||
parent?: string;
|
||||
}
|
||||
@@ -43,6 +43,14 @@ export class QueryPostDto implements PaginateOptions {
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
limit = 10;
|
||||
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect' })
|
||||
@IsOptional()
|
||||
category?: string;
|
||||
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect' })
|
||||
@IsOptional()
|
||||
tag?: string;
|
||||
}
|
||||
|
||||
export class CreatePostDto {
|
||||
@@ -84,6 +92,21 @@ export class CreatePostDto {
|
||||
@IsNumber(undefined, { always: true })
|
||||
@IsOptional({ always: true })
|
||||
customOrder?: number;
|
||||
|
||||
@IsUUID(undefined, {
|
||||
always: true,
|
||||
message: 'The ID format is incorrect',
|
||||
})
|
||||
@IsOptional({ always: true })
|
||||
category?: string;
|
||||
|
||||
@IsUUID(undefined, {
|
||||
always: true,
|
||||
each: true,
|
||||
message: 'The ID format is incorrect',
|
||||
})
|
||||
@IsOptional({ always: true })
|
||||
tags?: string[];
|
||||
}
|
||||
|
||||
export class UpdatePostDto extends PartialType(CreatePostDto) {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
IsDefined,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
MaxLength,
|
||||
Min,
|
||||
} from 'class-validator';
|
||||
import { toNumber } from 'lodash';
|
||||
|
||||
export class QueryTagDto implements PaginateOptions {
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(1, { message: 'The current page must be greater than 1.' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
page = 1;
|
||||
|
||||
@Transform(({ value }) => toNumber(value))
|
||||
@Min(1, { message: 'The number of data displayed per page must be greater than 1.' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
limit = 10;
|
||||
}
|
||||
|
||||
export class CreateTagDto {
|
||||
@MaxLength(255, {
|
||||
always: true,
|
||||
message: 'The maximum length of the label name is $constraint1',
|
||||
})
|
||||
@IsNotEmpty({ groups: ['create'], message: 'The classification name cannot be empty' })
|
||||
@IsOptional({ groups: ['update'] })
|
||||
name: string;
|
||||
|
||||
@MaxLength(500, {
|
||||
always: true,
|
||||
message: 'The maximum length of the label description is $constraint1',
|
||||
})
|
||||
@IsOptional({ always: true })
|
||||
desc?: string;
|
||||
}
|
||||
|
||||
export class UpdateTagDto extends PartialType(CreateTagDto) {
|
||||
@IsUUID(undefined, { message: 'The ID format is incorrect', groups: ['update'] })
|
||||
@IsDefined({ groups: ['update'], message: 'The ID must be specified' })
|
||||
id: string;
|
||||
}
|
||||
Reference in New Issue
Block a user