fixed some types, add some labels
This commit is contained in:
@@ -4,12 +4,33 @@ import { isStatusValue } from "@/constants";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { postFile, buildFileUrl } from "@/features/shared/api/sharedApi";
|
||||
|
||||
// ─── Types (UI-facing) ────────────────────────────────────────────────────────
|
||||
// ─── Shared types ─────────────────────────────────────────────────────────────
|
||||
|
||||
export type IntlPaymentStatus = "pending" | "approved" | "rejected";
|
||||
export type CurrencyType = "visa" | "mastercard";
|
||||
|
||||
export interface IntlPaymentItem {
|
||||
/** Kabul ediji + Upgradyý resminamalar (15 sany) — hem UI hem Payload ortak */
|
||||
export interface IntlPaymentDocs {
|
||||
doc_sberbank_account: string | null;
|
||||
doc_school_enrollment: string | null;
|
||||
doc_summons: string | null;
|
||||
doc_passport_tm: string | null;
|
||||
doc_foreign_passport: string | null;
|
||||
doc_foreign_passport_copy: string | null;
|
||||
doc_exit_permission: string | null;
|
||||
doc_school_foreign_info: string | null;
|
||||
doc_school_departure_info: string | null;
|
||||
upd_doc_passport_tm: string | null;
|
||||
upd_doc_foreign_passport: string | null;
|
||||
upd_doc_visa: string | null;
|
||||
upd_doc_acceptance_letter: string | null;
|
||||
upd_doc_passport_biometric: string | null;
|
||||
upd_doc_passport_old: string | null;
|
||||
}
|
||||
|
||||
// ─── UI-facing types ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface IntlPaymentItem extends IntlPaymentDocs {
|
||||
id: string;
|
||||
client_id: string;
|
||||
client_label: string;
|
||||
@@ -39,25 +60,6 @@ export interface IntlPaymentItem {
|
||||
// Töleg kabul edijiniň maglumatlary
|
||||
receiver_info: string;
|
||||
|
||||
// Kabul ediji talyp boyunca resminamalar (9 sany)
|
||||
doc_sberbank_account: string | null; // file url
|
||||
doc_school_enrollment: string | null;
|
||||
doc_summons: string | null;
|
||||
doc_passport_tm: string | null;
|
||||
doc_foreign_passport: string | null;
|
||||
doc_foreign_passport_copy: string | null;
|
||||
doc_exit_permission: string | null;
|
||||
doc_school_foreign_info: string | null;
|
||||
doc_school_departure_info: string | null;
|
||||
|
||||
// Upgradyý boyunca resminamalar (6 sany)
|
||||
upd_doc_passport_tm: string | null;
|
||||
upd_doc_foreign_passport: string | null;
|
||||
upd_doc_visa: string | null;
|
||||
upd_doc_acceptance_letter: string | null;
|
||||
upd_doc_passport_biometric: string | null;
|
||||
upd_doc_passport_old: string | null;
|
||||
|
||||
created_by: string;
|
||||
created_by_label: string;
|
||||
}
|
||||
@@ -85,7 +87,7 @@ export interface IntlPaymentListResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export type IntlPaymentCreatePayload = {
|
||||
export type IntlPaymentCreatePayload = IntlPaymentDocs & {
|
||||
client_id: string;
|
||||
status: string;
|
||||
note: string;
|
||||
@@ -105,25 +107,6 @@ export type IntlPaymentCreatePayload = {
|
||||
payer_account_number: string;
|
||||
|
||||
receiver_info: string;
|
||||
|
||||
// kabul ediji docs (uploaded URL strings, same as DocumentUpload in loan orders)
|
||||
doc_sberbank_account: string | null;
|
||||
doc_school_enrollment: string | null;
|
||||
doc_summons: string | null;
|
||||
doc_passport_tm: string | null;
|
||||
doc_foreign_passport: string | null;
|
||||
doc_foreign_passport_copy: string | null;
|
||||
doc_exit_permission: string | null;
|
||||
doc_school_foreign_info: string | null;
|
||||
doc_school_departure_info: string | null;
|
||||
|
||||
// upgradyý docs (uploaded URL strings)
|
||||
upd_doc_passport_tm: string | null;
|
||||
upd_doc_foreign_passport: string | null;
|
||||
upd_doc_visa: string | null;
|
||||
upd_doc_acceptance_letter: string | null;
|
||||
upd_doc_passport_biometric: string | null;
|
||||
upd_doc_passport_old: string | null;
|
||||
};
|
||||
|
||||
export type IntlPaymentUpdatePayload = Partial<IntlPaymentCreatePayload>;
|
||||
@@ -140,7 +123,6 @@ interface BackendIntlPayment {
|
||||
email?: string | null;
|
||||
region?: string | null;
|
||||
regionName?: LocalizedText | string | null;
|
||||
branchId?: number | null;
|
||||
branch?: {
|
||||
id: number;
|
||||
uniqueCode: string;
|
||||
@@ -149,8 +131,9 @@ interface BackendIntlPayment {
|
||||
provinceId: number;
|
||||
provinceName?: LocalizedText;
|
||||
} | null;
|
||||
userId?: number | null;
|
||||
branchId?: number | null;
|
||||
user?: { id: number; name: string; username: string; phone: string; email: string } | null;
|
||||
userId?: number | null;
|
||||
address?: string | null;
|
||||
senderDatas?: { fullName?: string; passportSerie?: string; passportNumber?: string; depositAccount?: string } | null;
|
||||
paymentReciever?: Array<{ fullName?: string; passportSerie?: string; passportNumber?: string; depositAccount?: string }> | null;
|
||||
@@ -199,55 +182,6 @@ function firstFileUrl(arr?: string[] | null): string | null {
|
||||
return toFileUrl(arr[0]);
|
||||
}
|
||||
|
||||
function mapBackendToUI(o: BackendIntlPayment): IntlPaymentItem {
|
||||
const status: IntlPaymentStatus = isStatusValue(o.status ?? "") ? (o.status as IntlPaymentStatus) : "pending";
|
||||
const d = o.documents ?? {};
|
||||
|
||||
return {
|
||||
id: String(o.id ?? o.uniqueId ?? ""),
|
||||
client_id: o.userId != null ? String(o.userId) : (o.uniqueId ?? String(o.id ?? "")),
|
||||
client_label: o.user?.name ?? o.uniqueId ?? String(o.id ?? ""),
|
||||
currency_type: (o.type as CurrencyType) ?? "visa",
|
||||
currency_type_label: o.type ?? "",
|
||||
created_at: o.createdAt ?? "",
|
||||
province: o.region ?? "",
|
||||
province_label: resolveLocalizedName(o.regionName) || o.region || "",
|
||||
branch: o.branchId != null ? String(o.branchId) : "",
|
||||
branch_label: o.branch?.name ? resolveLocalizedName(o.branch.name) : "",
|
||||
status,
|
||||
note: o.notes ?? "",
|
||||
passport_first_name: o.passportName ?? "",
|
||||
passport_last_name: o.passportSurname ?? "",
|
||||
phone: formatFromApiPhone(o.phone),
|
||||
email: o.email ?? "",
|
||||
home_address: o.address ?? "",
|
||||
passport_series: o.senderDatas?.passportSerie ?? o.senderPassportSerie ?? o.paymentReciever?.[0]?.passportSerie ?? "",
|
||||
passport_number: o.senderDatas?.passportNumber ?? o.senderPassportNumber ?? o.paymentReciever?.[0]?.passportNumber ?? "",
|
||||
payer_full_name: o.senderFullName ?? o.senderDatas?.fullName ?? "",
|
||||
payer_account_number: o.senderDepositAccount ?? o.senderDatas?.depositAccount ?? "",
|
||||
receiver_info: o.recieverFullName ?? o.paymentReciever?.[0]?.fullName ?? "",
|
||||
|
||||
doc_sberbank_account: firstFileUrl(d.student_visa_card_details),
|
||||
doc_school_enrollment: firstFileUrl(d.student_enrollment_certificate),
|
||||
doc_summons: firstFileUrl(d.student_ticket_copy),
|
||||
doc_passport_tm: firstFileUrl(d.student_internal_passport),
|
||||
doc_foreign_passport: firstFileUrl(d.student_foreign_passport),
|
||||
doc_foreign_passport_copy: firstFileUrl(d.student_visa_page),
|
||||
doc_exit_permission: firstFileUrl(d.student_stamp_page),
|
||||
doc_school_foreign_info: firstFileUrl(d.student_enrollment_clarification),
|
||||
doc_school_departure_info: firstFileUrl(d.sender_internal_passport),
|
||||
upd_doc_passport_tm: firstFileUrl(d.sender_foreign_passport),
|
||||
upd_doc_foreign_passport: firstFileUrl(d.sender_stamp_page),
|
||||
upd_doc_visa: firstFileUrl(d.kinship_documents),
|
||||
upd_doc_acceptance_letter: firstFileUrl(d.first_passport_series_info),
|
||||
upd_doc_passport_biometric: firstFileUrl(d.police_passport_series_info),
|
||||
upd_doc_passport_old: null,
|
||||
|
||||
created_by: o.userId != null ? String(o.userId) : "",
|
||||
created_by_label: o.user?.name ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
// Form doc field -> backend documents key
|
||||
const DOC_FILE_TO_KEY: Record<string, string> = {
|
||||
doc_sberbank_account: "student_visa_card_details",
|
||||
@@ -266,22 +200,78 @@ const DOC_FILE_TO_KEY: Record<string, string> = {
|
||||
upd_doc_passport_biometric: "police_passport_series_info",
|
||||
};
|
||||
|
||||
async function mapPayloadToBackend(
|
||||
payload: IntlPaymentCreatePayload | Partial<IntlPaymentCreatePayload>,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const documents: Record<string, string[]> = {};
|
||||
function mapDocs(d: Record<string, string[]>): IntlPaymentDocs {
|
||||
return {
|
||||
doc_sberbank_account: firstFileUrl(d.student_visa_card_details),
|
||||
doc_school_enrollment: firstFileUrl(d.student_enrollment_certificate),
|
||||
doc_summons: firstFileUrl(d.student_ticket_copy),
|
||||
doc_passport_tm: firstFileUrl(d.student_internal_passport),
|
||||
doc_foreign_passport: firstFileUrl(d.student_foreign_passport),
|
||||
doc_foreign_passport_copy: firstFileUrl(d.student_visa_page),
|
||||
doc_exit_permission: firstFileUrl(d.student_stamp_page),
|
||||
doc_school_foreign_info: firstFileUrl(d.student_enrollment_clarification),
|
||||
doc_school_departure_info: firstFileUrl(d.sender_internal_passport),
|
||||
upd_doc_passport_tm: firstFileUrl(d.sender_foreign_passport),
|
||||
upd_doc_foreign_passport: firstFileUrl(d.sender_stamp_page),
|
||||
upd_doc_visa: firstFileUrl(d.kinship_documents),
|
||||
upd_doc_acceptance_letter: firstFileUrl(d.first_passport_series_info),
|
||||
upd_doc_passport_biometric: firstFileUrl(d.police_passport_series_info),
|
||||
upd_doc_passport_old: null,
|
||||
};
|
||||
}
|
||||
|
||||
function mapBackendToUI(o: BackendIntlPayment): IntlPaymentItem {
|
||||
const status: IntlPaymentStatus = isStatusValue(o.status ?? "") ? (o.status as IntlPaymentStatus) : "pending";
|
||||
|
||||
return {
|
||||
...mapDocs(o.documents ?? {}),
|
||||
id: String(o.id ?? o.uniqueId ?? ""),
|
||||
client_id: o.user?.id != null ? String(o.user.id) : o.userId != null ? String(o.userId) : o.uniqueId || String(o.id ?? ""),
|
||||
client_label: o.user?.name ?? o.uniqueId ?? String(o.id ?? ""),
|
||||
currency_type: (o.type as CurrencyType) ?? "visa",
|
||||
currency_type_label: o.type ?? "",
|
||||
created_at: o.createdAt ?? "",
|
||||
province: o.region ?? "",
|
||||
province_label: resolveLocalizedName(o.regionName) || o.region || "",
|
||||
branch: o.branch?.id != null ? String(o.branch.id) : o.branchId != null ? String(o.branchId) : "",
|
||||
branch_label: o.branch?.name ? resolveLocalizedName(o.branch.name) : "",
|
||||
status,
|
||||
note: o.notes ?? "",
|
||||
passport_first_name: o.passportName ?? "",
|
||||
passport_last_name: o.passportSurname ?? "",
|
||||
phone: formatFromApiPhone(o.phone),
|
||||
email: o.email ?? "",
|
||||
home_address: o.address ?? "",
|
||||
passport_series: o.senderDatas?.passportSerie ?? o.senderPassportSerie ?? o.paymentReciever?.[0]?.passportSerie ?? "",
|
||||
passport_number: o.senderDatas?.passportNumber ?? o.senderPassportNumber ?? o.paymentReciever?.[0]?.passportNumber ?? "",
|
||||
payer_full_name: o.senderFullName ?? o.senderDatas?.fullName ?? "",
|
||||
payer_account_number: o.senderDepositAccount ?? o.senderDatas?.depositAccount ?? "",
|
||||
receiver_info: o.recieverFullName ?? o.paymentReciever?.[0]?.fullName ?? "",
|
||||
created_by: o.user?.id != null ? String(o.user.id) : o.userId != null ? String(o.userId) : "",
|
||||
created_by_label: o.user?.name ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
async function mapFileDocsToBackend(docs: IntlPaymentDocs): Promise<Record<string, string[]>> {
|
||||
const result: Record<string, string[]> = {};
|
||||
await Promise.all(
|
||||
Object.entries(DOC_FILE_TO_KEY).map(async ([field, key]) => {
|
||||
const value = payload[field as keyof IntlPaymentCreatePayload] as File | string | null | undefined;
|
||||
const value = docs[field as keyof IntlPaymentDocs] as File | string | null | undefined;
|
||||
if (value instanceof File) {
|
||||
const filename = await postFile(value);
|
||||
documents[key] = [filename];
|
||||
result[key] = [filename];
|
||||
} else if (typeof value === "string" && value) {
|
||||
documents[key] = [value];
|
||||
result[key] = [value];
|
||||
}
|
||||
}),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
async function mapPayloadToBackend(
|
||||
payload: IntlPaymentCreatePayload | Partial<IntlPaymentCreatePayload>,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const documents = await mapFileDocsToBackend(payload as IntlPaymentDocs);
|
||||
|
||||
return {
|
||||
address: payload.home_address ?? "",
|
||||
|
||||
Reference in New Issue
Block a user