-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-all-users.usecase.ts
More file actions
27 lines (25 loc) · 1000 Bytes
/
get-all-users.usecase.ts
File metadata and controls
27 lines (25 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { UserModelDto } from '@shared/dto/models/user.model.dto';
import { UserAdapter } from '@api/adapters/user.adapter';
import { UserRepository } from '@api/repositories/user.repository';
import { MasterAccount } from '@prisma/generated';
import { UsersNotFoundError } from '@api/errors/users-not-found.error';
import { inject, injectable } from 'tsyringe';
@injectable()
export class GetAllUsersUseCase {
public constructor(
@inject(UserRepository) private readonly _userRepository: UserRepository,
@inject(UserAdapter) private readonly _userAdapter: UserAdapter
) {}
public async handle(): Promise<UserModelDto[]> {
let masterAccounts: MasterAccount[] | null = null;
try {
masterAccounts = await this._userRepository.getAll();
} catch (error) {
console.error(error);
}
if (!masterAccounts || masterAccounts.length === 0) {
throw new UsersNotFoundError();
}
return this._userAdapter.getUsersFromMasterAccounts(masterAccounts);
}
}