admin/services/adminReports.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

44 lines
1.2 KiB
TypeScript

import type { AdminReportsOverviewDto } from '@/api/generated/models'
import {
createServiceError,
errorResult,
handleServiceError,
type ServiceCallOptions,
type ServiceResult,
shouldBubbleErrorToParent,
successResult,
} from '@/services/errorHandler'
import { unwrapApiData } from '@/services/apiResponse'
import { getAdminReports } from '@/api/generated/admin-reports/admin-reports'
export type AdminReportsOverview = AdminReportsOverviewDto
const adminReportsApi = getAdminReports()
export const GET_ADMIN_REPORTS_OVERVIEW = async (options?: ServiceCallOptions): Promise<ServiceResult<AdminReportsOverview>> => {
try {
const res = await adminReportsApi.adminReportsControllerGetOverview()
const payload = res.data
if (!payload.success) {
throw createServiceError(payload.message || 'دریافت گزارش‌ها ناموفق بود')
}
const overview = unwrapApiData(payload)
if (!overview) {
throw createServiceError('پاسخ نامعتبر از سرور')
}
return successResult(overview)
} catch (error) {
const normalizedError = handleServiceError(error, options)
if (shouldBubbleErrorToParent(options)) {
throw normalizedError
}
return errorResult(normalizedError)
}
}