后端实现权限验证

This commit is contained in:
2025-06-18 17:10:55 +08:00
parent a5b8fa49ed
commit 490f0b56cc
12 changed files with 72 additions and 19 deletions

View File

@@ -25,3 +25,7 @@ export class UserSession {
@DeleteDateColumn({ nullable: true, precision: 3 })
deletedAt: Date;
}
/**
* 考虑是否使用sessionId代替id以节省存储空间
*/

View File

@@ -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[];
}

View File

@@ -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) {