39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ListUsersUseCase, ListUsersInput } from '@core/admin/application/use-cases/ListUsersUseCase';
|
|
import { ListUsersPresenter, ListUsersViewModel } from './presenters/ListUsersPresenter';
|
|
import { GetDashboardStatsUseCase, GetDashboardStatsInput } from './use-cases/GetDashboardStatsUseCase';
|
|
import { DashboardStatsPresenter, DashboardStatsResponse } from './presenters/DashboardStatsPresenter';
|
|
|
|
@Injectable()
|
|
export class AdminService {
|
|
constructor(
|
|
private readonly listUsersUseCase: ListUsersUseCase,
|
|
private readonly listUsersPresenter: ListUsersPresenter,
|
|
private readonly getDashboardStatsUseCase: GetDashboardStatsUseCase,
|
|
private readonly dashboardStatsPresenter: DashboardStatsPresenter,
|
|
) {}
|
|
|
|
async listUsers(input: ListUsersInput): Promise<ListUsersViewModel> {
|
|
const result = await this.listUsersUseCase.execute(input);
|
|
|
|
if (result.isErr()) {
|
|
const error = result.unwrapErr();
|
|
throw new Error(`${error.code}: ${error.details.message}`);
|
|
}
|
|
|
|
return this.listUsersPresenter.getViewModel();
|
|
}
|
|
|
|
async getDashboardStats(input: GetDashboardStatsInput): Promise<DashboardStatsResponse> {
|
|
this.dashboardStatsPresenter.reset();
|
|
|
|
const result = await this.getDashboardStatsUseCase.execute(input);
|
|
|
|
if (result.isErr()) {
|
|
const error = result.unwrapErr();
|
|
throw new Error(`${error.code}: ${error.details.message}`);
|
|
}
|
|
|
|
return this.dashboardStatsPresenter.responseModel;
|
|
}
|
|
} |