chore: fix some code

This commit is contained in:
Kuizuo 2024-05-05 20:37:52 +08:00
parent 5231e5f565
commit 326d16068f
11 changed files with 45 additions and 66 deletions

View File

@ -1,27 +1,27 @@
{
"folders": [
{
"name": "ROOT",
"path": "../"
},
{
"name": "server",
"path": "../apps/server"
},
{
"name": "admin",
"path": "../apps/admin"
},
{
"name": "web",
"path": "../apps/web"
},
{
"name": "database",
"path": "../packages/database"
},
],
"settings": {
"testing.automaticallyOpenPeekView": "never"
"folders": [
{
"name": "ROOT",
"path": "../"
},
}
{
"name": "server",
"path": "../apps/server"
},
{
"name": "admin",
"path": "../apps/admin"
},
{
"name": "web",
"path": "../apps/web"
},
{
"name": "database",
"path": "../packages/database"
}
],
"settings": {
"testing.automaticallyOpenPeekView": "never"
}
}

View File

@ -55,7 +55,6 @@
"@socket.io/redis-emitter": "^5.1.0",
"@trpc/server": "10.45.1",
"@types/lodash": "^4.14.201",
"database": "workspace:*",
"axios": "^1.6.1",
"bcrypt": "^5.1.1",
"bull": "^4.11.4",
@ -65,6 +64,7 @@
"cron": "^3.1.6",
"cron-parser": "^4.9.0",
"crypto-js": "^4.2.0",
"database": "workspace:*",
"dayjs": "^1.11.10",
"dotenv": "16.3.1",
"dotenv-expand": "^10.0.0",

View File

@ -3,5 +3,5 @@ export default async () => {
const t = {
["./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": {} } }]] } };
};

View File

@ -1,14 +1,14 @@
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 { defineTrpcRouter } from '@server/shared/trpc/trpc.helper'
import { TRPCService } from '@server/shared/trpc/trpc.service'
import { z } from 'zod'
import { AuthService } from './auth.service'
import { CredentialsSchema } from './auth.dto'
import { BizException } from '@server/common/exceptions/biz.exception'
import { ErrorCodeEnum } from '@server/constants/error-code.constant'
import { AuthService } from './auth.service'
@TRPCRouter()
@Injectable()
@ -41,7 +41,7 @@ export class AuthTrpcRouter implements OnModuleInit {
if (user.role === 'Admin')
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 {
data: { authToken: jwt },

View File

@ -5,9 +5,9 @@ import { ApiSecurityAuth } from '@server/common/decorators/swagger.decorator'
import { AuthUser } from '@server/modules/auth/decorators/auth-user.decorator'
import { PasswordUpdateDto } from '@server/modules/user/dto/password.dto'
import { UpdateProfileDto } from '../../user/dto/account.dto'
import { UserService } from '../../user/user.service'
import { AuthService } from '../auth.service'
import { UpdateProfileDto } from '../../user/dto/account.dto'
import { JwtAuthGuard } from '../guards/jwt-auth.guard'
@ApiTags('Account - 账户模块')
@ -27,9 +27,10 @@ export class AccountController {
@Put('profile')
async updateProfile(
@AuthUser() user: IAuthUser, @Body() dto: UpdateProfileDto,
@AuthUser() user: IAuthUser, @Body()
dto: UpdateProfileDto,
): Promise<void> {
await this.userService.updateProfile(user.id, dto)
await this.userService.updateProfile(dto, user.id)
}
@Get('logout')

View File

@ -14,7 +14,6 @@ export enum Action {
export type PrismaSubjects = {
User: User
Todo: Todo
}
export type AppAbility = PureAbility<[Action, Subjects<PrismaSubjects>]>

View File

@ -20,10 +20,16 @@ import { TodoService } from './todo.service'
export class TodoController {
constructor(private readonly todoService: TodoService) { }
@Get('page')
@Get()
@Policy({ model: 'Todo', action: Action.Manage })
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')

View File

@ -29,15 +29,6 @@ export class UserPublicService {
},
select: {
...UserSelect,
gender: true,
yoId: true,
campus: {
select: {
id: true,
logo: true,
name: true,
},
},
},
}).catch(resourceNotFoundWrapper(
new BizException(ErrorCodeEnum.UserNotFound),

View File

@ -11,6 +11,7 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"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",
"dev": "turbo run dev",
"bundle": "pnpm -F server run bundle",

View File

@ -11,6 +11,7 @@
},
"main": "./client/index.js",
"scripts": {
"postinstall": "npm run db:generate",
"db:generate": "rimraf dist client && prisma generate && tsc && cp -r client dist/client",
"db:push": "prisma db push --skip-generate",
"migrate:dev": "prisma migrate dev",

View File

@ -484,12 +484,6 @@ importers:
'@trpc/server':
specifier: 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:
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)
@ -3640,9 +3634,6 @@ packages:
'@types/node@12.20.55':
resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==}
'@types/node@16.18.96':
resolution: {integrity: sha512-84iSqGXoO+Ha16j8pRZ/L90vDMKX04QTYMTfYeE1WrjWaZXuchBehGUZEpNgx7JnmlrIHdnABmpjrQjhCnNldQ==}
'@types/node@20.12.7':
resolution: {integrity: sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==}
@ -5319,9 +5310,6 @@ packages:
resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==}
engines: {node: '>= 0.6'}
cookies-next@4.1.1:
resolution: {integrity: sha512-20QaN0iQSz87Os0BhNg9M71eM++gylT3N5szTlhq2rK6QvXn1FYGPB4eAgU4qFTunbQKhD35zfQ95ZWgzUy3Cg==}
copy-anything@2.0.6:
resolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==}
@ -17108,8 +17096,6 @@ snapshots:
'@types/node@12.20.55': {}
'@types/node@16.18.96': {}
'@types/node@20.12.7':
dependencies:
undici-types: 5.26.5
@ -19826,12 +19812,6 @@ snapshots:
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:
dependencies:
is-what: 3.14.1