chore: fix some code
This commit is contained in:
parent
5231e5f565
commit
326d16068f
4
.vscode/project.code-workspace
vendored
4
.vscode/project.code-workspace
vendored
@ -19,9 +19,9 @@
|
|||||||
{
|
{
|
||||||
"name": "database",
|
"name": "database",
|
||||||
"path": "../packages/database"
|
"path": "../packages/database"
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"testing.automaticallyOpenPeekView": "never"
|
"testing.automaticallyOpenPeekView": "never"
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -55,7 +55,6 @@
|
|||||||
"@socket.io/redis-emitter": "^5.1.0",
|
"@socket.io/redis-emitter": "^5.1.0",
|
||||||
"@trpc/server": "10.45.1",
|
"@trpc/server": "10.45.1",
|
||||||
"@types/lodash": "^4.14.201",
|
"@types/lodash": "^4.14.201",
|
||||||
"database": "workspace:*",
|
|
||||||
"axios": "^1.6.1",
|
"axios": "^1.6.1",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"bull": "^4.11.4",
|
"bull": "^4.11.4",
|
||||||
@ -65,6 +64,7 @@
|
|||||||
"cron": "^3.1.6",
|
"cron": "^3.1.6",
|
||||||
"cron-parser": "^4.9.0",
|
"cron-parser": "^4.9.0",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
|
"database": "workspace:*",
|
||||||
"dayjs": "^1.11.10",
|
"dayjs": "^1.11.10",
|
||||||
"dotenv": "16.3.1",
|
"dotenv": "16.3.1",
|
||||||
"dotenv-expand": "^10.0.0",
|
"dotenv-expand": "^10.0.0",
|
||||||
|
@ -3,5 +3,5 @@ export default async () => {
|
|||||||
const t = {
|
const t = {
|
||||||
["./modules/auth/auth.model"]: await import("./modules/auth/auth.model")
|
["./modules/auth/auth.model"]: await import("./modules/auth/auth.model")
|
||||||
};
|
};
|
||||||
return { "@nestjs/swagger": { "models": [[import("./modules/auth/auth.dto"), { "LoginDto": {}, "RegisterDto": {} }], [import("./common/dto/id.dto"), { "IdDto": {} }], [import("./common/dto/pager.dto"), { "PagerDto": {} }], [import("./modules/user/dto/password.dto"), { "PasswordUpdateDto": {}, "UserPasswordDto": {} }], [import("./modules/user/dto/user.dto"), { "UserDto": {}, "UserUpdateDto": {}, "UserQueryDto": {} }], [import("./modules/user/dto/account.dto"), { "UpdateProfileDto": {}, "ResetPasswordDto": {} }], [import("./modules/user/dto/search.dto"), { "UserSearchDto": {} }], [import("./common/dto/delete.dto"), { "BatchDeleteDto": {} }], [import("./modules/todo/todo.dto"), { "TodoDto": {}, "TodoUpdateDto": {}, "TodoPagerDto": {} }], [import("./modules/auth/captcha/captcha.dto"), { "ImageCaptchaDto": {}, "SendEmailCodeDto": {}, "SendSmsCodeDto": {}, "CheckCodeDto": {} }], [import("./modules/file/file.dto"), { "FileQueryDto": {}, "FileUploadDto": {} }], [import("./common/dto/image.dto"), { "ImagesDto": {} }]], "controllers": [[import("./modules/user/user.controller"), { "UserController": { "list": {}, "getUserById": {}, "create": {}, "update": {}, "delete": {}, "password": {} } }], [import("./modules/auth/auth.admin.controller"), { "AuthAdminController": { "login": {} } }], [import("./modules/auth/auth.controller"), { "AuthController": { "login": {}, "register": {} } }], [import("./modules/auth/captcha/captcha.controller"), { "CaptchaController": { "captchaByImg": { type: t["./modules/auth/auth.model"].ImageCaptcha } } }], [import("./modules/auth/controllers/account.controller"), { "AccountController": { "profile": {}, "updateProfile": {}, "logout": {}, "password": {} } }], [import("./modules/auth/controllers/email.controller"), { "EmailController": { "sendEmailCode": {} } }], [import("./modules/file/file.controller"), { "FileController": { "getTypes": { type: Object }, "get": {}, "upload": {}, "uploadMultiple": { type: [Object] }, "delete": {} } }], [import("./modules/todo/todo.controller"), { "TodoController": { "list": {}, "findOne": {}, "create": {}, "update": {}, "delete": {}, "batchDelete": {} } }]] } };
|
return { "@nestjs/swagger": { "models": [[import("./modules/auth/auth.dto"), { "LoginDto": {}, "RegisterDto": {} }], [import("./common/dto/id.dto"), { "IdDto": {} }], [import("./common/dto/pager.dto"), { "PagerDto": {} }], [import("./modules/user/dto/password.dto"), { "PasswordUpdateDto": {}, "UserPasswordDto": {} }], [import("./modules/user/dto/user.dto"), { "UserDto": {}, "UserUpdateDto": {}, "UserQueryDto": {} }], [import("./modules/user/dto/account.dto"), { "UpdateProfileDto": {}, "ResetPasswordDto": {} }], [import("./modules/user/dto/search.dto"), { "UserSearchDto": {} }], [import("./common/dto/delete.dto"), { "BatchDeleteDto": {} }], [import("./modules/todo/todo.dto"), { "TodoDto": {}, "TodoUpdateDto": {}, "TodoPagerDto": {} }], [import("./modules/auth/captcha/captcha.dto"), { "ImageCaptchaDto": {}, "SendEmailCodeDto": {}, "SendSmsCodeDto": {}, "CheckCodeDto": {} }], [import("./modules/file/file.dto"), { "FileQueryDto": {}, "FileUploadDto": {} }], [import("./common/dto/image.dto"), { "ImagesDto": {} }]], "controllers": [[import("./modules/user/user.controller"), { "UserController": { "list": {}, "getUserById": {}, "create": {}, "update": {}, "delete": {}, "password": {} } }], [import("./modules/auth/auth.admin.controller"), { "AuthAdminController": { "login": {} } }], [import("./modules/auth/auth.controller"), { "AuthController": { "login": {}, "register": {} } }], [import("./modules/auth/captcha/captcha.controller"), { "CaptchaController": { "captchaByImg": { type: t["./modules/auth/auth.model"].ImageCaptcha } } }], [import("./modules/auth/controllers/account.controller"), { "AccountController": { "profile": {}, "updateProfile": {}, "logout": {}, "password": {} } }], [import("./modules/auth/controllers/email.controller"), { "EmailController": { "sendEmailCode": {} } }], [import("./modules/file/file.controller"), { "FileController": { "getTypes": { type: Object }, "get": {}, "upload": {}, "uploadMultiple": { type: [Object] }, "delete": {} } }], [import("./modules/todo/todo.controller"), { "TodoController": { "list": {}, "page": {}, "findOne": {}, "create": {}, "update": {}, "delete": {}, "batchDelete": {} } }]] } };
|
||||||
};
|
};
|
@ -1,14 +1,14 @@
|
|||||||
import { Injectable, OnModuleInit } from '@nestjs/common'
|
import { Injectable, OnModuleInit } from '@nestjs/common'
|
||||||
|
|
||||||
|
import { BizException } from '@server/common/exceptions/biz.exception'
|
||||||
|
import { ErrorCodeEnum } from '@server/constants/error-code.constant'
|
||||||
import { TRPCRouter } from '@server/shared/trpc/trpc.decorator'
|
import { TRPCRouter } from '@server/shared/trpc/trpc.decorator'
|
||||||
import { defineTrpcRouter } from '@server/shared/trpc/trpc.helper'
|
import { defineTrpcRouter } from '@server/shared/trpc/trpc.helper'
|
||||||
import { TRPCService } from '@server/shared/trpc/trpc.service'
|
import { TRPCService } from '@server/shared/trpc/trpc.service'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import { AuthService } from './auth.service'
|
|
||||||
import { CredentialsSchema } from './auth.dto'
|
import { CredentialsSchema } from './auth.dto'
|
||||||
import { BizException } from '@server/common/exceptions/biz.exception'
|
import { AuthService } from './auth.service'
|
||||||
import { ErrorCodeEnum } from '@server/constants/error-code.constant'
|
|
||||||
|
|
||||||
@TRPCRouter()
|
@TRPCRouter()
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -41,7 +41,7 @@ export class AuthTrpcRouter implements OnModuleInit {
|
|||||||
if (user.role === 'Admin')
|
if (user.role === 'Admin')
|
||||||
throw new BizException(ErrorCodeEnum.PasswordMismatch)
|
throw new BizException(ErrorCodeEnum.PasswordMismatch)
|
||||||
|
|
||||||
const jwt = await this.authService.sign(user.id, user.role, { ip, ua })
|
const jwt = await this.authService.sign(user.id, user.role)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: { authToken: jwt },
|
data: { authToken: jwt },
|
||||||
|
@ -5,9 +5,9 @@ import { ApiSecurityAuth } from '@server/common/decorators/swagger.decorator'
|
|||||||
import { AuthUser } from '@server/modules/auth/decorators/auth-user.decorator'
|
import { AuthUser } from '@server/modules/auth/decorators/auth-user.decorator'
|
||||||
import { PasswordUpdateDto } from '@server/modules/user/dto/password.dto'
|
import { PasswordUpdateDto } from '@server/modules/user/dto/password.dto'
|
||||||
|
|
||||||
|
import { UpdateProfileDto } from '../../user/dto/account.dto'
|
||||||
import { UserService } from '../../user/user.service'
|
import { UserService } from '../../user/user.service'
|
||||||
import { AuthService } from '../auth.service'
|
import { AuthService } from '../auth.service'
|
||||||
import { UpdateProfileDto } from '../../user/dto/account.dto'
|
|
||||||
import { JwtAuthGuard } from '../guards/jwt-auth.guard'
|
import { JwtAuthGuard } from '../guards/jwt-auth.guard'
|
||||||
|
|
||||||
@ApiTags('Account - 账户模块')
|
@ApiTags('Account - 账户模块')
|
||||||
@ -27,9 +27,10 @@ export class AccountController {
|
|||||||
|
|
||||||
@Put('profile')
|
@Put('profile')
|
||||||
async updateProfile(
|
async updateProfile(
|
||||||
@AuthUser() user: IAuthUser, @Body() dto: UpdateProfileDto,
|
@AuthUser() user: IAuthUser, @Body()
|
||||||
|
dto: UpdateProfileDto,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.userService.updateProfile(user.id, dto)
|
await this.userService.updateProfile(dto, user.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('logout')
|
@Get('logout')
|
||||||
|
@ -14,7 +14,6 @@ export enum Action {
|
|||||||
export type PrismaSubjects = {
|
export type PrismaSubjects = {
|
||||||
User: User
|
User: User
|
||||||
Todo: Todo
|
Todo: Todo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AppAbility = PureAbility<[Action, Subjects<PrismaSubjects>]>
|
export type AppAbility = PureAbility<[Action, Subjects<PrismaSubjects>]>
|
||||||
|
@ -20,10 +20,16 @@ import { TodoService } from './todo.service'
|
|||||||
export class TodoController {
|
export class TodoController {
|
||||||
constructor(private readonly todoService: TodoService) { }
|
constructor(private readonly todoService: TodoService) { }
|
||||||
|
|
||||||
@Get('page')
|
@Get()
|
||||||
@Policy({ model: 'Todo', action: Action.Manage })
|
@Policy({ model: 'Todo', action: Action.Manage })
|
||||||
async list(@Query() dto: TodoPagerDto, @AuthUser() user: IAuthUser) {
|
async list(@Query() dto: TodoPagerDto, @AuthUser() user: IAuthUser) {
|
||||||
return this.todoService.paginate(dto, user.id)
|
return this.todoService.list(dto, user.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('page')
|
||||||
|
@Policy({ model: 'Todo', action: Action.Manage })
|
||||||
|
async page(@Query() dto: TodoPagerDto, @AuthUser() user: IAuthUser) {
|
||||||
|
return this.todoService.paginate(dto)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@ -29,15 +29,6 @@ export class UserPublicService {
|
|||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
...UserSelect,
|
...UserSelect,
|
||||||
gender: true,
|
|
||||||
yoId: true,
|
|
||||||
campus: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
logo: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}).catch(resourceNotFoundWrapper(
|
}).catch(resourceNotFoundWrapper(
|
||||||
new BizException(ErrorCodeEnum.UserNotFound),
|
new BizException(ErrorCodeEnum.UserNotFound),
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
"reinstall": "rimraf pnpm-lock.yaml && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",
|
"reinstall": "rimraf pnpm-lock.yaml && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",
|
||||||
|
"postinstall": "cp .env apps/server/.env && cp .env packages/database/.env",
|
||||||
"build": "turbo run build",
|
"build": "turbo run build",
|
||||||
"dev": "turbo run dev",
|
"dev": "turbo run dev",
|
||||||
"bundle": "pnpm -F server run bundle",
|
"bundle": "pnpm -F server run bundle",
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
},
|
},
|
||||||
"main": "./client/index.js",
|
"main": "./client/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"postinstall": "npm run db:generate",
|
||||||
"db:generate": "rimraf dist client && prisma generate && tsc && cp -r client dist/client",
|
"db:generate": "rimraf dist client && prisma generate && tsc && cp -r client dist/client",
|
||||||
"db:push": "prisma db push --skip-generate",
|
"db:push": "prisma db push --skip-generate",
|
||||||
"migrate:dev": "prisma migrate dev",
|
"migrate:dev": "prisma migrate dev",
|
||||||
|
@ -484,12 +484,6 @@ importers:
|
|||||||
'@trpc/server':
|
'@trpc/server':
|
||||||
specifier: 10.45.1
|
specifier: 10.45.1
|
||||||
version: 10.45.1
|
version: 10.45.1
|
||||||
cookies-next:
|
|
||||||
specifier: ^4.1.1
|
|
||||||
version: 4.1.1
|
|
||||||
js-cookie:
|
|
||||||
specifier: ^3.0.5
|
|
||||||
version: 3.0.5
|
|
||||||
next:
|
next:
|
||||||
specifier: 14.2.2
|
specifier: 14.2.2
|
||||||
version: 14.2.2(@opentelemetry/api@1.8.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)
|
version: 14.2.2(@opentelemetry/api@1.8.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)
|
||||||
@ -3640,9 +3634,6 @@ packages:
|
|||||||
'@types/node@12.20.55':
|
'@types/node@12.20.55':
|
||||||
resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==}
|
resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==}
|
||||||
|
|
||||||
'@types/node@16.18.96':
|
|
||||||
resolution: {integrity: sha512-84iSqGXoO+Ha16j8pRZ/L90vDMKX04QTYMTfYeE1WrjWaZXuchBehGUZEpNgx7JnmlrIHdnABmpjrQjhCnNldQ==}
|
|
||||||
|
|
||||||
'@types/node@20.12.7':
|
'@types/node@20.12.7':
|
||||||
resolution: {integrity: sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==}
|
resolution: {integrity: sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==}
|
||||||
|
|
||||||
@ -5319,9 +5310,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==}
|
resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
|
|
||||||
cookies-next@4.1.1:
|
|
||||||
resolution: {integrity: sha512-20QaN0iQSz87Os0BhNg9M71eM++gylT3N5szTlhq2rK6QvXn1FYGPB4eAgU4qFTunbQKhD35zfQ95ZWgzUy3Cg==}
|
|
||||||
|
|
||||||
copy-anything@2.0.6:
|
copy-anything@2.0.6:
|
||||||
resolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==}
|
resolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==}
|
||||||
|
|
||||||
@ -17108,8 +17096,6 @@ snapshots:
|
|||||||
|
|
||||||
'@types/node@12.20.55': {}
|
'@types/node@12.20.55': {}
|
||||||
|
|
||||||
'@types/node@16.18.96': {}
|
|
||||||
|
|
||||||
'@types/node@20.12.7':
|
'@types/node@20.12.7':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 5.26.5
|
undici-types: 5.26.5
|
||||||
@ -19826,12 +19812,6 @@ snapshots:
|
|||||||
|
|
||||||
cookie@0.6.0: {}
|
cookie@0.6.0: {}
|
||||||
|
|
||||||
cookies-next@4.1.1:
|
|
||||||
dependencies:
|
|
||||||
'@types/cookie': 0.6.0
|
|
||||||
'@types/node': 16.18.96
|
|
||||||
cookie: 0.6.0
|
|
||||||
|
|
||||||
copy-anything@2.0.6:
|
copy-anything@2.0.6:
|
||||||
dependencies:
|
dependencies:
|
||||||
is-what: 3.14.1
|
is-what: 3.14.1
|
||||||
|
Loading…
Reference in New Issue
Block a user