后端实现权限验证
This commit is contained in:
@@ -25,3 +25,7 @@ export class UserSession {
|
||||
@DeleteDateColumn({ nullable: true, precision: 3 })
|
||||
deletedAt: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 考虑是否使用sessionId代替id,以节省存储空间
|
||||
*/
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Role } from 'src/auth/role.enum';
|
||||
import {
|
||||
BeforeInsert,
|
||||
Column,
|
||||
@@ -84,4 +85,7 @@ export class User {
|
||||
|
||||
@DeleteDateColumn({ nullable: true, precision: 3 })
|
||||
deletedAt: Date;
|
||||
|
||||
@Column('simple-array', { default: '' })
|
||||
roles: Role[];
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private readonly userRepository: Repository<User>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* @deprecated 尽量不使用该方法
|
||||
*/
|
||||
async findOne(
|
||||
options: UserFindOptions | UserFindOptions[],
|
||||
additionalOptions?: { withDeleted?: boolean },
|
||||
@@ -33,6 +36,14 @@ export class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
async findById(userId: string): Promise<User | null> {
|
||||
return this.userRepository.findOne({
|
||||
where: {
|
||||
userId,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async create(user: Partial<User>): Promise<User> {
|
||||
try {
|
||||
const newUser = this.userRepository.create(user);
|
||||
@@ -114,7 +125,7 @@ export class UserService {
|
||||
if (error.message.includes('IDX_user_phone')) {
|
||||
return '手机号已被使用';
|
||||
}
|
||||
return '数据已存在,请检查输入';
|
||||
return '该登陆方式异常,请更换其他登陆方式或联系管理员';
|
||||
}
|
||||
|
||||
async list(page = 1, pageSize = 20) {
|
||||
|
||||
Reference in New Issue
Block a user