Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import type { WalletTransaction } from '@/services/wallet'
|
|
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, type ApiResponse } from '@/services/apiResponse'
|
|
|
|
export interface AdminCreditWalletPayload {
|
|
/** Amount in Toman (integer). */
|
|
amount: number
|
|
description?: string
|
|
}
|
|
|
|
export interface AdminCreditWalletResult {
|
|
walletBalance: number
|
|
transaction: WalletTransaction
|
|
}
|
|
|
|
export const ADMIN_CREDIT_WALLET = async (
|
|
userId: string,
|
|
payload: AdminCreditWalletPayload,
|
|
options?: ServiceCallOptions
|
|
): Promise<ServiceResult<AdminCreditWalletResult>> => {
|
|
try {
|
|
const res = await axiosInstance.post<ApiResponse<AdminCreditWalletResult>>(API_ROUTES.USERS.ADMIN_WALLET_CREDIT(userId), payload)
|
|
const body = res.data
|
|
|
|
if (!body.success) {
|
|
throw createServiceError(body.message || 'شارژ کیفپول ناموفق بود')
|
|
}
|
|
|
|
const data = unwrapApiData(body)
|
|
|
|
if (data?.walletBalance === undefined || !data.transaction?.id) {
|
|
throw createServiceError('پاسخ نامعتبر از سرور')
|
|
}
|
|
|
|
return successResult(data)
|
|
} catch (error) {
|
|
const normalizedError = handleServiceError(error, options)
|
|
|
|
if (shouldBubbleErrorToParent(options)) {
|
|
throw normalizedError
|
|
}
|
|
|
|
return errorResult(normalizedError)
|
|
}
|
|
}
|