Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
44 lines
1.2 KiB
TypeScript
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)
|
|
}
|
|
}
|