refactor: extract interface

This commit is contained in:
Innei
2022-02-18 13:42:01 +08:00
parent c5658d1d26
commit c1efdbb49f
5 changed files with 32 additions and 54 deletions

View File

@@ -11,11 +11,8 @@ import {
IsString,
ValidateNested,
} from 'class-validator'
import {
CountMixed,
Paginator,
WriteBaseModel,
} from '~/shared/model/base.model'
import { Paginator } from '~/shared/interface/paginator.interface'
import { CountMixed, WriteBaseModel } from '~/shared/model/base.model'
@modelOptions({ schemaOptions: { id: false, _id: false } })
export class Coordinate {

View File

@@ -19,11 +19,8 @@ import {
IsString,
} from 'class-validator'
import { Query } from 'mongoose'
import {
CountMixed as Count,
Paginator,
WriteBaseModel,
} from '~/shared/model/base.model'
import { Paginator } from '~/shared/interface/paginator.interface'
import { CountMixed as Count, WriteBaseModel } from '~/shared/model/base.model'
import { CategoryModel as Category } from '../category/category.model'
function autoPopulateCategory(

View File

@@ -1,15 +1,6 @@
import {
Body,
Controller,
Get,
HttpCode,
Patch,
Post,
SerializeOptions,
UseGuards,
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger'
import { Body, Controller, Get, HttpCode, Patch, Post } from '@nestjs/common'
import { ApiOperation } from '@nestjs/swagger'
import { Auth } from '~/common/decorator/auth.decorator'
import { HttpCache } from '~/common/decorator/cache.decorator'
import { CurrentUser } from '~/common/decorator/current-user.decorator'
import { IpLocation, IpRecord } from '~/common/decorator/ip.decorator'
@@ -36,9 +27,6 @@ export class UserController {
}
@Post('register')
@SerializeOptions({
excludePrefixes: ['password'],
})
@ApiOperation({ summary: '注册' })
async register(@Body() userDto: UserDto) {
userDto.name = userDto.name ?? userDto.username
@@ -71,17 +59,16 @@ export class UserController {
@Get('check_logged')
@ApiOperation({ summary: '判断当前 Token 是否有效 ' })
@ApiBearerAuth()
@HttpCache({ disable: true })
@Auth()
@HttpCache.disable
checkLogged(@IsMaster() isMaster: boolean) {
return { ok: +isMaster, isGuest: !isMaster }
}
@Patch()
@ApiOperation({ summary: '修改主人的信息 ' })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@HttpCache({ disable: true })
@ApiOperation({ summary: '修改主人的信息' })
@Auth()
@HttpCache.disable
async patchMasterData(
@Body() body: UserPatchDto,
@CurrentUser() user: UserDocument,

View File

@@ -1,6 +1,24 @@
import { Paginator } from '../model/base.model'
export interface Pagination<T> {
data: T[]
pagination: Paginator
}
export class Paginator {
/**
* 总条数
*/
readonly total: number
/**
* 一页多少条
*/
readonly size: number
/**
* 当前页
*/
readonly currentPage: number
/**
* 总页数
*/
readonly totalPage: number
readonly hasNextPage: boolean
readonly hasPrevPage: boolean
}

View File

@@ -40,27 +40,6 @@ export class BaseModel {
}
}
export class Paginator {
/**
* 总条数
*/
readonly total: number
/**
* 一页多少条
*/
readonly size: number
/**
* 当前页
*/
readonly currentPage: number
/**
* 总页数
*/
readonly totalPage: number
readonly hasNextPage: boolean
readonly hasPrevPage: boolean
}
@modelOptions({
schemaOptions: { _id: false },
})