Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import type { AdminUserDetailResponseDto } from '@/api/generated/models'
|
|
import axiosInstance from '@/config/axios'
|
|
import { API_ROUTES } from '@/services/config'
|
|
import {
|
|
createServiceError,
|
|
errorResult,
|
|
handleServiceError,
|
|
type ServiceCallOptions,
|
|
type ServiceResult,
|
|
shouldBubbleErrorToParent,
|
|
successResult,
|
|
} from '@/services/errorHandler'
|
|
import { unwrapApiData } from '@/services/apiResponse'
|
|
import { getAdminUserDetail } from '@/api/generated/admin-user-detail/admin-user-detail'
|
|
|
|
export type AdminIdentityStatus = AdminUserDetailResponseDto['identityStatus']
|
|
|
|
export type AdminUserDetail = AdminUserDetailResponseDto
|
|
|
|
const adminUserDetailApi = getAdminUserDetail()
|
|
|
|
export const GET_ADMIN_USER_DETAIL = async (userId: string, options?: ServiceCallOptions): Promise<ServiceResult<AdminUserDetail>> => {
|
|
try {
|
|
const res = await adminUserDetailApi.adminUserDetailControllerGetDetail(userId, { signal: options?.signal })
|
|
const payload = res.data
|
|
|
|
if (!payload.success) {
|
|
throw createServiceError(payload.message || 'دریافت اطلاعات کاربر ناموفق بود')
|
|
}
|
|
|
|
const detail = unwrapApiData(payload)
|
|
|
|
if (!detail?.id) {
|
|
throw createServiceError('پاسخ نامعتبر از سرور')
|
|
}
|
|
|
|
return successResult(detail)
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|
|
|
|
export const ADMIN_ATTEST_IDENTITY = async (userId: string, options?: ServiceCallOptions): Promise<ServiceResult<{ status: string }>> => {
|
|
try {
|
|
const res = await axiosInstance.post(API_ROUTES.USERS.ADMIN_IDENTITY_ATTEST(userId))
|
|
const payload = res.data as { success?: boolean; message?: string; data?: { status?: string } }
|
|
|
|
if (!payload.success) {
|
|
throw createServiceError(payload.message || 'تأیید احراز هویت ناموفق بود')
|
|
}
|
|
|
|
const data = unwrapApiData(payload)
|
|
|
|
if (!data?.status) {
|
|
throw createServiceError('پاسخ نامعتبر از سرور')
|
|
}
|
|
|
|
return successResult({ status: data.status })
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|