From 0bb62e867d1674c5bbd19153ff8342f99a068e18 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 26 Apr 2022 21:45:05 +0800 Subject: [PATCH] fix: note dto update --- src/modules/note/note.controller.ts | 11 +++-------- src/modules/note/note.dto.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/modules/note/note.controller.ts b/src/modules/note/note.controller.ts index a143f598..2b5451f1 100644 --- a/src/modules/note/note.controller.ts +++ b/src/modules/note/note.controller.ts @@ -5,7 +5,6 @@ import { Delete, ForbiddenException, Get, - HttpCode, Param, Patch, Post, @@ -31,8 +30,8 @@ import { import { ListQueryDto, NidType, + NotePasswordQueryDto, NoteQueryDto, - PasswordQueryDto, } from './note.dto' import { NoteModel, PartialNoteModel } from './note.model' import { NoteService } from './note.service' @@ -169,7 +168,6 @@ export class NoteController { } @Patch('/:id') - @HttpCode(204) @Auth() async patch(@Body() body: PartialNoteModel, @Param() params: MongoIdDto) { await this.noteService.updateById(params.id, body) @@ -177,7 +175,6 @@ export class NoteController { } @Get('like/:id') - @HttpCode(204) async likeNote( @Param() param: IntIdOrMongoIdDto, @IpLocation() location: IpRecord, @@ -206,7 +203,6 @@ export class NoteController { @Delete(':id') @Auth() - @HttpCode(204) async deleteNote(@Param() params: MongoIdDto) { await this.noteService.deleteById(params.id) } @@ -217,11 +213,10 @@ export class NoteController { async getNoteByNid( @Param() params: NidType, @IsMaster() isMaster: boolean, - @Query() query: PasswordQueryDto, - @Query('single') isSingle?: boolean, + @Query() query: NotePasswordQueryDto, ) { const { nid } = params - const { password } = query + const { password, single: isSingle } = query const condition = isMaster ? {} : { hide: false } const current = await this.noteService.model .findOne({ diff --git a/src/modules/note/note.dto.ts b/src/modules/note/note.dto.ts index 86da298f..9767a10a 100644 --- a/src/modules/note/note.dto.ts +++ b/src/modules/note/note.dto.ts @@ -1,5 +1,6 @@ import { Transform } from 'class-transformer' import { + IsBoolean, IsDefined, IsIn, IsInt, @@ -26,11 +27,18 @@ export class NoteQueryDto extends PagerDto { sortOrder?: 1 | -1 } -export class PasswordQueryDto { +export class NotePasswordQueryDto { @IsString() @IsOptional() @IsNotEmpty() password?: string + + @IsBoolean() + @IsOptional() + @Transform(({ value }) => { + return value === '1' || value === 'true' || value === true || value === 1 + }) + single?: boolean } export class ListQueryDto {