feat: 修复冲突
parent
450357a396
commit
06eb67ad55
|
|
@ -16,7 +16,7 @@ export class Response<T = any> {
|
|||
* 响应消息
|
||||
* @example '请求成功'
|
||||
*/
|
||||
@ApiProperty({ type: 'string', example: '请求成功' })
|
||||
@ApiProperty({ type: 'string', example: '操作成功' })
|
||||
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 });
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败响应结果
|
||||
*/
|
||||
static error(data = null, message = '请求失败') {
|
||||
static error(data = null, message = '操作失败') {
|
||||
return this.create({ code: ResponseCode.ERROR, message, data });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,17 +9,14 @@ export class AuthService {
|
|||
constructor(private userService: UserService, private jwtService: JwtService) {}
|
||||
|
||||
async signIn(authUserDto: AuthUserDto) {
|
||||
const user = await this.userService.findByUsername(authUserDto.username);
|
||||
const { password, ...user } = await this.userService.findByUsername(authUserDto.username);
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('用户名不存在');
|
||||
}
|
||||
if (user.password !== authUserDto.password) {
|
||||
if (password !== authUserDto.password) {
|
||||
throw new UnauthorizedException('密码错误');
|
||||
}
|
||||
const loginedUser = new LoginedUserVo();
|
||||
for (const key in loginedUser) {
|
||||
loginedUser[key] = user[key];
|
||||
}
|
||||
const loginedUser = Object.assign(new LoginedUserVo(), user);
|
||||
loginedUser.token = await this.jwtService.signAsync({ id: user.id, username: user.username });
|
||||
return loginedUser;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import { User } from '@/modules/user';
|
||||
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'
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { ApiHideProperty } from '@nestjs/swagger';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { BaseEntity } from '@/database';
|
||||
import { Post } from '@/modules/post';
|
||||
import { Role } from '@/modules/role';
|
||||
import { ApiHideProperty } from '@nestjs/swagger';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { Column, Entity, JoinTable, ManyToMany, RelationId } from 'typeorm';
|
||||
|
||||
@Entity({ orderBy: { id: 'DESC' } })
|
||||
|
|
@ -66,6 +66,9 @@ export class User extends BaseEntity {
|
|||
@JoinTable()
|
||||
roles: Role[];
|
||||
|
||||
/**
|
||||
* 用户角色ID
|
||||
*/
|
||||
@RelationId('roles')
|
||||
roleIds: number[];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue