62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import BaseService from "@Services/BaseService";
|
|
import "reflect-metadata";
|
|
import { Service } from "typedi";
|
|
import UsersRepository from "@Repositories/UsersRepository";
|
|
import User from "le-coffre-resources/dist/Admin";
|
|
import { Prisma, Users } from "@prisma/client";
|
|
|
|
@Service()
|
|
export default class UsersService extends BaseService {
|
|
constructor(private userRepository: UsersRepository) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description : Get all users
|
|
* @throws {Error} If users cannot be get
|
|
*/
|
|
public get(query: Prisma.UsersFindManyArgs) {
|
|
return this.userRepository.findMany(query);
|
|
}
|
|
|
|
/**
|
|
* @description : Modify a user
|
|
* @throws {Error} If user modification failed
|
|
*/
|
|
public async update(uid: string, userEntity: User): Promise<Users> {
|
|
return this.userRepository.update(uid, userEntity);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a user by uid
|
|
* @throws {Error} If user cannot be get by uid
|
|
*/
|
|
public getByUid(uid: string, query?: Prisma.UsersInclude) {
|
|
return this.userRepository.findOneByUid(uid, query);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a user by uid with office
|
|
* @throws {Error} If user cannot be get by uid
|
|
*/
|
|
public getByUidWithOffice(uid: string) {
|
|
return this.userRepository.findOneByUidWithOffice(uid);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a user by uid with office
|
|
* @throws {Error} If user cannot be get by uid
|
|
*/
|
|
public getByUidWithRole(uid: string) {
|
|
return this.userRepository.findOneByUidWithRole(uid);
|
|
}
|
|
|
|
/**
|
|
* @description : Get a user by uid
|
|
* @throws {Error} If user cannot be get by uid
|
|
*/
|
|
public getByProvider(providerName: string, id: string) {
|
|
return this.userRepository.findOneByProvider(providerName, id);
|
|
}
|
|
}
|