admin area
This commit is contained in:
39
apps/api/src/domain/admin/AdminService.ts
Normal file
39
apps/api/src/domain/admin/AdminService.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user