feat: 修复冲突
parent
450357a396
commit
06eb67ad55
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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'
|
||||||
|
|
|
||||||
|
|
@ -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[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue