format + lint

This commit is contained in:
2025-06-14 14:12:18 +08:00
parent 95e8f8c648
commit 1de3a3f197
69 changed files with 1756 additions and 1583 deletions

View File

@@ -1,57 +1,59 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { UserRole } from "src/role/entities/user-role.entity";
import { IsNull, MoreThanOrEqual, Repository } from "typeorm";
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { UserRole } from 'src/role/entities/user-role.entity';
import { IsNull, MoreThanOrEqual, Repository } from 'typeorm';
@Injectable()
export class UserRoleService {
constructor(
@InjectRepository(UserRole)
private readonly userRoleRepository: Repository<UserRole>,
) { }
constructor(
@InjectRepository(UserRole)
private readonly userRoleRepository: Repository<UserRole>,
) {}
async findRoleIdsByUserId(userId: string): Promise<string[]> {
const userRoles = await this.userRoleRepository.find({
where: {
userId,
}
});
async findRoleIdsByUserId(userId: string): Promise<string[]> {
const userRoles = await this.userRoleRepository.find({
where: {
userId,
},
});
return userRoles.map(ur => ur.roleId);
}
return userRoles.map((ur) => ur.roleId);
}
async findValidRoleIdsByUserId(userId: string): Promise<string[]> {
return (await this.findValidRolesByUserId(userId)).map(ur => ur.roleId);
}
async findValidRoleIdsByUserId(userId: string): Promise<string[]> {
return (await this.findValidRolesByUserId(userId)).map((ur) => ur.roleId);
}
async findValidRolesByUserId(userId: string) {
const now = new Date();
async findValidRolesByUserId(userId: string) {
const now = new Date();
return this.userRoleRepository.find({
where: [
{
userId,
isEnabled: true,
expiredAt: MoreThanOrEqual(now),
},
{
userId,
isEnabled: true,
expiredAt: IsNull(),
}
]
})
}
return this.userRoleRepository.find({
where: [
{
userId,
isEnabled: true,
expiredAt: MoreThanOrEqual(now),
},
{
userId,
isEnabled: true,
expiredAt: IsNull(),
},
],
});
}
async addUserRole(userRole: Pick<UserRole, 'roleId' | 'userId' | 'isEnabled' | 'expiredAt'>): Promise<void> {
const newUserRole = this.userRoleRepository.create(userRole);
await this.userRoleRepository.save(newUserRole);
}
async addUserRole(
userRole: Pick<UserRole, 'roleId' | 'userId' | 'isEnabled' | 'expiredAt'>,
): Promise<void> {
const newUserRole = this.userRoleRepository.create(userRole);
await this.userRoleRepository.save(newUserRole);
}
async deleteUserRole(userId: string, roleId: string): Promise<void> {
await this.userRoleRepository.delete({
userId,
roleId,
});
}
}
async deleteUserRole(userId: string, roleId: string): Promise<void> {
await this.userRoleRepository.delete({
userId,
roleId,
});
}
}