initial
This commit is contained in:
39
apps/backend/src/roles/repositories/roles.repository.ts
Normal file
39
apps/backend/src/roles/repositories/roles.repository.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { RoleEntity } from '../entities/role.entity';
|
||||
|
||||
@Injectable()
|
||||
export class RolesRepository {
|
||||
constructor(
|
||||
@InjectRepository(RoleEntity) private readonly repo: Repository<RoleEntity>,
|
||||
) {}
|
||||
|
||||
findByName(
|
||||
name: string,
|
||||
manager?: EntityManager,
|
||||
): Promise<RoleEntity | null> {
|
||||
return (manager?.getRepository(RoleEntity) ?? this.repo).findOne({
|
||||
where: { name },
|
||||
});
|
||||
}
|
||||
|
||||
findById(id: string): Promise<RoleEntity | null> {
|
||||
return this.repo.findOne({ where: { id }, relations: { users: true } });
|
||||
}
|
||||
|
||||
list(): Promise<RoleEntity[]> {
|
||||
return this.repo.find({
|
||||
order: { name: 'ASC' },
|
||||
relations: { users: true },
|
||||
});
|
||||
}
|
||||
|
||||
save(role: RoleEntity, manager?: EntityManager): Promise<RoleEntity> {
|
||||
return (manager?.getRepository(RoleEntity) ?? this.repo).save(role);
|
||||
}
|
||||
|
||||
remove(role: RoleEntity): Promise<RoleEntity> {
|
||||
return this.repo.remove(role);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user