46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import BaseService from "@Services/BaseService";
|
|
import "reflect-metadata";
|
|
import { Service } from "typedi";
|
|
import RolesRepository from "@Repositories/RolesRepository";
|
|
import { Role } from "le-coffre-resources/dist/SuperAdmin";
|
|
import { Prisma, Roles } from "@prisma/client";
|
|
|
|
@Service()
|
|
export default class RolesService extends BaseService {
|
|
constructor(private roleRepository: RolesRepository) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description : Get all roles
|
|
* @throws {Error} If roles cannot be get
|
|
*/
|
|
public get(query: Prisma.RolesFindManyArgs): Promise<Roles[]> {
|
|
return this.roleRepository.findMany(query);
|
|
}
|
|
|
|
/**
|
|
* @description : Create a role
|
|
* @throws {Error} If role couldn't be created
|
|
*/
|
|
public create(roleEntity: Role): Promise<Roles> {
|
|
return this.roleRepository.create(roleEntity);
|
|
}
|
|
|
|
/**
|
|
* @description : Modify a role
|
|
* @throws {Error} If role modification failed
|
|
*/
|
|
public update(roleEntity: Role): Promise<Roles> {
|
|
return this.roleRepository.update(roleEntity);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a role by uid
|
|
* @throws {Error} If role cannot be get by uid
|
|
*/
|
|
public getByUid(uid: string, query?: any): Promise<Roles | null> {
|
|
return this.roleRepository.findOneByUid(uid, query);
|
|
}
|
|
}
|