|
@@ -15,13 +15,31 @@ import { ICryptoRepository, ILibraryRepository, IUserRepository, UserListFilter
|
|
|
|
|
|
const SALT_ROUNDS = 10;
|
|
const SALT_ROUNDS = 10;
|
|
|
|
|
|
|
|
+let instance: UserCore | null;
|
|
|
|
+
|
|
export class UserCore {
|
|
export class UserCore {
|
|
- constructor(
|
|
|
|
- private userRepository: IUserRepository,
|
|
|
|
- private libraryRepository: ILibraryRepository,
|
|
|
|
|
|
+ private constructor(
|
|
private cryptoRepository: ICryptoRepository,
|
|
private cryptoRepository: ICryptoRepository,
|
|
|
|
+ private libraryRepository: ILibraryRepository,
|
|
|
|
+ private userRepository: IUserRepository,
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
+ static create(
|
|
|
|
+ cryptoRepository: ICryptoRepository,
|
|
|
|
+ libraryRepository: ILibraryRepository,
|
|
|
|
+ userRepository: IUserRepository,
|
|
|
|
+ ) {
|
|
|
|
+ if (!instance) {
|
|
|
|
+ instance = new UserCore(cryptoRepository, libraryRepository, userRepository);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return instance;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static reset() {
|
|
|
|
+ instance = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
async updateUser(authUser: AuthUserDto, id: string, dto: Partial<UserEntity>): Promise<UserEntity> {
|
|
async updateUser(authUser: AuthUserDto, id: string, dto: Partial<UserEntity>): Promise<UserEntity> {
|
|
if (!authUser.isAdmin && authUser.id !== id) {
|
|
if (!authUser.isAdmin && authUser.id !== id) {
|
|
throw new ForbiddenException('You are not allowed to update this user');
|
|
throw new ForbiddenException('You are not allowed to update this user');
|