feat(migrations): add national_code_verified flag to users and normalize bank_account representation

- Added a new column `national_code_verified` to the `users` table.
- Normalized the `bank_account` field in the `representations` table from a single object to an array of IBANs with a default `verified` status of false.

feat(ApiIrService): implement identity verification client for api.ir

- Created `ApiIrService` to handle identity verification via api.ir.
- Implemented methods for matching national code with mobile and IBAN with national code and birth date.
- Added error handling and logging for external API requests.
This commit is contained in:
hamed
2026-06-25 19:38:47 +03:30
parent 9b608aaeac
commit c2c6ae4d02
515 changed files with 194899 additions and 55 deletions
@@ -22,9 +22,13 @@ const STATUS_CLASS: Record<string, string> = {
pending: 'gray', approved: 'green', rejected: 'red', paid: 'green',
};
interface IbanItem { id: string; iban: string; bank_name: string | null; verified: boolean }
interface RepMe { bank_account: IbanItem[] | null }
export default function RepresentationSettlementPage() {
const qc = useQueryClient();
const [amount, setAmount] = useState('');
const [ibanId, setIbanId] = useState('');
const balanceQ = useQuery({
queryKey: ['wallet-balance'],
@@ -34,6 +38,14 @@ export default function RepresentationSettlementPage() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const balance: number = ((balanceQ.data?.data as any)?.data ?? balanceQ.data?.data)?.balance_rials ?? 0;
const meQ = useQuery({
queryKey: ['representation-me'],
queryFn: () => api.get<ApiResponse<RepMe>>('/api/v1/representation/me'),
staleTime: 30_000,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ibans: IbanItem[] = (((meQ.data?.data as any)?.data ?? meQ.data?.data)?.bank_account ?? []).filter((b: IbanItem) => b.verified);
const summaryQ = useQuery({
queryKey: ['representation-summary'],
queryFn: () => api.get<ApiResponse<RepSummary>>('/api/v1/representation/dashboard/summary'),
@@ -51,8 +63,8 @@ export default function RepresentationSettlementPage() {
const settlements: SettlementRow[] = (listQ.data?.data as any)?.data ?? listQ.data?.data ?? [];
const createMut = useMutation({
mutationFn: (amountRials: number) =>
api.post<ApiResponse<SettlementRow>>('/api/v1/settlement', { amount_rials: amountRials }),
mutationFn: (payload: { amount_rials: number; iban_id: string }) =>
api.post<ApiResponse<SettlementRow>>('/api/v1/settlement', payload),
onSuccess: () => {
toast.success('درخواست تسویه ثبت شد');
setAmount('');
@@ -67,7 +79,8 @@ export default function RepresentationSettlementPage() {
const n = Number(amount);
if (!n || n <= 0) { toast.error('مبلغ نامعتبر است'); return; }
if (n > balance) { toast.error('مبلغ بیشتر از موجودی قابل برداشت است'); return; }
createMut.mutate(n);
if (!ibanId) { toast.error('انتخاب شماره شبا الزامی است'); return; }
createMut.mutate({ amount_rials: n, iban_id: ibanId });
};
const cards = [
@@ -98,17 +111,34 @@ export default function RepresentationSettlementPage() {
<div className="card-title-row" style={{ marginBottom: 12 }}>
<h3 style={{ fontSize: 16 }}>ثبت درخواست جدید</h3>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<input
type="number" min={0} dir="ltr" value={amount} placeholder="مبلغ به ریال"
onChange={(e) => setAmount(e.target.value)}
style={{ width: 240, height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13.5, boxSizing: 'border-box' }}
/>
<button className="btn primary" onClick={submit} disabled={createMut.isPending}>
{createMut.isPending ? 'در حال ثبت...' : 'ثبت درخواست'}
</button>
<span className="muted" style={{ fontSize: 12 }}>حداکثر: {formatRial(balance)}</span>
</div>
{ibans.length === 0 ? (
<div className="muted" style={{ fontSize: 13 }}>
برای ثبت درخواست تسویه، ابتدا در{' '}
<a href="/admin/representation-profile" style={{ color: 'var(--primary)', fontWeight: 600 }}>پروفایل</a>{' '}
یک شماره شبای تأییدشده اضافه کنید.
</div>
) : (
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<input
type="number" min={0} dir="ltr" value={amount} placeholder="مبلغ به ریال"
onChange={(e) => setAmount(e.target.value)}
style={{ width: 200, height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13.5, boxSizing: 'border-box' }}
/>
<select
value={ibanId} onChange={(e) => setIbanId(e.target.value)} dir="ltr"
style={{ width: 320, height: 38, padding: '0 10px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 12.5, boxSizing: 'border-box' }}
>
<option value="">انتخاب شماره شبا...</option>
{ibans.map((b) => (
<option key={b.id} value={b.id}>{b.iban}{b.bank_name ? `${b.bank_name}` : ''}</option>
))}
</select>
<button className="btn primary" onClick={submit} disabled={createMut.isPending}>
{createMut.isPending ? 'در حال ثبت...' : 'ثبت درخواست'}
</button>
<span className="muted" style={{ fontSize: 12 }}>حداکثر: {formatRial(balance)}</span>
</div>
)}
</div>
<div className="card card-pad" style={{ marginTop: 'var(--gap)' }}>