feat: post pin
This commit is contained in:
@@ -53,7 +53,9 @@ export class PostController {
|
||||
limit: size,
|
||||
page,
|
||||
select,
|
||||
sort: sortBy ? { [sortBy]: sortOrder || -1 } : { created: -1 },
|
||||
sort: sortBy
|
||||
? { [sortBy]: sortOrder || -1 }
|
||||
: { created: -1, pin: -1, pinOrder: -1 },
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -113,7 +115,6 @@ export class PostController {
|
||||
|
||||
@Post('/')
|
||||
@Auth()
|
||||
@HttpCode(201)
|
||||
@HTTPDecorators.Idempotence()
|
||||
async create(@Body() body: PostModel) {
|
||||
const _id = new Types.ObjectId()
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import { Transform } from 'class-transformer'
|
||||
import {
|
||||
ArrayUnique,
|
||||
IsBoolean,
|
||||
IsDate,
|
||||
IsInt,
|
||||
IsMongoId,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsString,
|
||||
} from 'class-validator'
|
||||
import { Query } from 'mongoose'
|
||||
|
||||
import { UnprocessableEntityException } from '@nestjs/common'
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
import { ApiHideProperty, ApiProperty } from '@nestjs/swagger'
|
||||
import {
|
||||
@@ -89,6 +94,28 @@ export class PostModel extends WriteBaseModel {
|
||||
@ApiHideProperty()
|
||||
count?: Count
|
||||
|
||||
@prop()
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => {
|
||||
if (typeof value != 'boolean') {
|
||||
throw new UnprocessableEntityException('pin value must be boolean')
|
||||
}
|
||||
|
||||
if (value === true) {
|
||||
return new Date()
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
})
|
||||
pin?: Date | null
|
||||
|
||||
@prop()
|
||||
@IsPositive()
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
pinOrder?: number
|
||||
|
||||
static get protectedKeys() {
|
||||
return ['count'].concat(super.protectedKeys)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user