feat: 修复冲突

master
绝弹 2023-08-07 19:09:58 +08:00
parent 450357a396
commit 06eb67ad55
4 changed files with 16 additions and 12 deletions

View File

@ -16,7 +16,7 @@ export class Response<T = any> {
* *
* @example '请求成功' * @example '请求成功'
*/ */
@ApiProperty({ type: 'string', example: '请求成功' }) @ApiProperty({ type: 'string', example: '操作成功' })
message?: string; message?: string;
/** /**
@ -41,14 +41,14 @@ export class Response<T = any> {
/** /**
* *
*/ */
static success({ code = ResponseCode.SUCESS, message = '请求成功', ...rest }: Response = {} as any) { static success({ code = ResponseCode.SUCESS, message = '操作成功', ...rest }: Response = {} as any) {
return this.create({ code, message, ...rest }); return this.create({ code, message, ...rest });
} }
/** /**
* *
*/ */
static error(data = null, message = '请求失败') { static error(data = null, message = '操作失败') {
return this.create({ code: ResponseCode.ERROR, message, data }); return this.create({ code: ResponseCode.ERROR, message, data });
} }

View File

@ -9,17 +9,14 @@ export class AuthService {
constructor(private userService: UserService, private jwtService: JwtService) {} constructor(private userService: UserService, private jwtService: JwtService) {}
async signIn(authUserDto: AuthUserDto) { async signIn(authUserDto: AuthUserDto) {
const user = await this.userService.findByUsername(authUserDto.username); const { password, ...user } = await this.userService.findByUsername(authUserDto.username);
if (!user) { if (!user) {
throw new UnauthorizedException('用户名不存在'); throw new UnauthorizedException('用户名不存在');
} }
if (user.password !== authUserDto.password) { if (password !== authUserDto.password) {
throw new UnauthorizedException('密码错误'); throw new UnauthorizedException('密码错误');
} }
const loginedUser = new LoginedUserVo(); const loginedUser = Object.assign(new LoginedUserVo(), user);
for (const key in loginedUser) {
loginedUser[key] = user[key];
}
loginedUser.token = await this.jwtService.signAsync({ id: user.id, username: user.username }); loginedUser.token = await this.jwtService.signAsync({ id: user.id, username: user.username });
return loginedUser; return loginedUser;
} }

View File

@ -1,7 +1,11 @@
import { User } from '@/modules/user'; import { User } from '@/modules/user';
import { OmitType } from '@nestjs/swagger'; import { OmitType } from '@nestjs/swagger';
export class LoginedUserVo extends OmitType(User, ['password'] as const) { export class LoginedUserVo extends OmitType(User, ['password', 'id'] as const) {
/**
* ID
*/
id: number;
/** /**
* 访 * 访
* @example 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjIsInVzZXJuYW1lIjoianVldGFuIiwiaWF0IjoxNjkxMTM5MjI3LCJleHAiOjE2OTExOTkyMjd9.6z7f-xfsHABbsyg401o2boKeqNQ1epPDYfEdavIcfYc' * @example 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjIsInVzZXJuYW1lIjoianVldGFuIiwiaWF0IjoxNjkxMTM5MjI3LCJleHAiOjE2OTExOTkyMjd9.6z7f-xfsHABbsyg401o2boKeqNQ1epPDYfEdavIcfYc'

View File

@ -1,8 +1,8 @@
import { ApiHideProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { BaseEntity } from '@/database'; import { BaseEntity } from '@/database';
import { Post } from '@/modules/post'; import { Post } from '@/modules/post';
import { Role } from '@/modules/role'; import { Role } from '@/modules/role';
import { ApiHideProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { Column, Entity, JoinTable, ManyToMany, RelationId } from 'typeorm'; import { Column, Entity, JoinTable, ManyToMany, RelationId } from 'typeorm';
@Entity({ orderBy: { id: 'DESC' } }) @Entity({ orderBy: { id: 'DESC' } })
@ -66,6 +66,9 @@ export class User extends BaseEntity {
@JoinTable() @JoinTable()
roles: Role[]; roles: Role[];
/**
* ID
*/
@RelationId('roles') @RelationId('roles')
roleIds: number[]; roleIds: number[];
} }