Report account-balance evaluate results and fall back to cached balances.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,12 +5,19 @@ import { api } from '@/lib/api';
|
||||
import {
|
||||
ACCOUNT_BALANCE_WEIGHT_KEYS,
|
||||
ACCOUNT_BALANCE_WEIGHT_LABELS,
|
||||
type AccountBalanceEvaluateResultDto,
|
||||
type AccountBalanceRangeDto,
|
||||
type AccountBalanceSettingsDto,
|
||||
type UpdateAccountBalanceSettingsRequest,
|
||||
} from '@mento/shared';
|
||||
import { UiButton, UiCard, UiField, UiInput, UiPageHeader } from '@/components/ui';
|
||||
|
||||
function toLatinDigits(raw: string) {
|
||||
return String(raw ?? '')
|
||||
.replace(/[۰-۹]/g, (d) => String('۰۱۲۳۴۵۶۷۸۹'.indexOf(d)))
|
||||
.replace(/[٠-٩]/g, (d) => String('٠١٢٣٤٥٦٧٨٩'.indexOf(d)));
|
||||
}
|
||||
|
||||
type RangeDraft = { enabled: boolean; min: string; max: string };
|
||||
|
||||
const loading = ref(false);
|
||||
@@ -46,8 +53,8 @@ function toDraft(range: AccountBalanceRangeDto | null | undefined): RangeDraft {
|
||||
|
||||
function parseDraft(draft: RangeDraft): AccountBalanceRangeDto | null {
|
||||
if (!draft.enabled) return null;
|
||||
const min = Number(String(draft.min).replace(/,/g, ''));
|
||||
const max = Number(String(draft.max).replace(/,/g, ''));
|
||||
const min = Number(toLatinDigits(String(draft.min)).replace(/,/g, '').trim());
|
||||
const max = Number(toLatinDigits(String(draft.max)).replace(/,/g, '').trim());
|
||||
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
||||
throw new Error('بازه نامعتبر');
|
||||
}
|
||||
@@ -121,11 +128,21 @@ async function runEvaluate() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
await api.post('/account-balances/evaluate');
|
||||
ok.value = 'بروزرسانی مطالبات اجرا شد.';
|
||||
const { data } = await api.post<AccountBalanceEvaluateResultDto>('/account-balances/evaluate');
|
||||
ok.value = data.message || 'بروزرسانی مطالبات اجرا شد.';
|
||||
if (data.matched === 0 && data.created === 0) {
|
||||
error.value =
|
||||
data.candidates === 0
|
||||
? 'برای ساخت فعالیت، مشتری باید به تهحساب لینک باشد و حداقل در یک گروه با مسئول باشد.'
|
||||
: 'هیچ مشتریای داخل بازههای فعال نبود. علامت بد/بس (منفی/مثبت) و اعداد بازه را با ماندهٔ پروفایل مشتری مقایسه کنید.';
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = axios.isAxiosError(e)
|
||||
? String(e.response?.data?.message || 'اجرای ارزیابی ناموفق بود.')
|
||||
? String(
|
||||
Array.isArray(e.response?.data?.message)
|
||||
? e.response.data.message.join('، ')
|
||||
: e.response?.data?.message || 'اجرای ارزیابی ناموفق بود.',
|
||||
)
|
||||
: 'اجرای ارزیابی ناموفق بود.';
|
||||
} finally {
|
||||
evaluating.value = false;
|
||||
|
||||
Reference in New Issue
Block a user