Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
/**
|
|
* Pure helper for the KYC Excel export feature.
|
|
*
|
|
* Builds an xlsx workbook via the shared toXlsx helper; returns raw bytes
|
|
* (Uint8Array) suitable for a browser download.
|
|
*
|
|
* Sheet "KYC" with headers:
|
|
* Member, Name on ID, ID type, ID number, Status, Channel,
|
|
* Submitted by, Submitted at, Actioned by, Actioned at, Remarks
|
|
*
|
|
* Status codes rendered as: Pending / Approved / Rejected / Revoked.
|
|
*/
|
|
import type { AdminKycRow } from "@/app/lib/types";
|
|
import { toXlsx, type XlsxColumn } from "@/app/lib/xlsx";
|
|
|
|
/** Human-readable label for a KYC status code. */
|
|
function statusLabel(status: AdminKycRow["status"]): string {
|
|
switch (status) {
|
|
case "P":
|
|
return "Pending";
|
|
case "A":
|
|
return "Approved";
|
|
case "R":
|
|
return "Rejected";
|
|
case "V":
|
|
return "Revoked";
|
|
}
|
|
}
|
|
|
|
/** Column definitions for the KYC export sheet. */
|
|
const KYC_COLUMNS: XlsxColumn[] = [
|
|
{ key: "memberCode", title: "Member" },
|
|
{ key: "submitName", title: "Name on ID" },
|
|
{ key: "identityType", title: "ID type" },
|
|
{ key: "identityNo", title: "ID number" },
|
|
{ key: "status", title: "Status" },
|
|
{ key: "submitChannel", title: "Channel" },
|
|
{ key: "submittedBy", title: "Submitted by" },
|
|
{ key: "createDateTime", title: "Submitted at" },
|
|
{ key: "actionBy", title: "Actioned by" },
|
|
{ key: "actionAt", title: "Actioned at" },
|
|
{ key: "actionRemarks", title: "Remarks" },
|
|
];
|
|
|
|
/**
|
|
* Build a KYC export workbook from rows.
|
|
* Returns raw bytes (Uint8Array) suitable for a browser download.
|
|
*
|
|
* @param rows - KYC rows to include in the export.
|
|
* @returns xlsx file bytes.
|
|
*/
|
|
export async function buildKycWorkbook(rows: AdminKycRow[]): Promise<Uint8Array> {
|
|
const mapped = rows.map((r) => ({
|
|
memberCode: r.memberCode,
|
|
submitName: r.submitName,
|
|
identityType: r.identityType,
|
|
identityNo: r.identityNo,
|
|
status: statusLabel(r.status),
|
|
submitChannel: r.submitChannel,
|
|
submittedBy: r.submittedBy,
|
|
createDateTime: r.createDateTime,
|
|
actionBy: r.actionBy ?? null,
|
|
actionAt: r.actionAt ?? null,
|
|
actionRemarks: r.actionRemarks ?? null,
|
|
}));
|
|
return toXlsx(mapped, KYC_COLUMNS, "KYC");
|
|
}
|
|
|
|
/**
|
|
* Generate a file name for the KYC export workbook.
|
|
* Format: kyc-YYYYMMDD-HHmm.xlsx
|
|
*
|
|
* @param now - The date to use (defaults to `new Date()` if omitted).
|
|
* @returns File name string.
|
|
*/
|
|
export function kycExportFileName(now: Date): string {
|
|
const y = now.getFullYear();
|
|
const m = String(now.getMonth() + 1).padStart(2, "0");
|
|
const d = String(now.getDate()).padStart(2, "0");
|
|
const H = String(now.getHours()).padStart(2, "0");
|
|
const M = String(now.getMinutes()).padStart(2, "0");
|
|
return `kyc-${y}${m}${d}-${H}${M}.xlsx`;
|
|
}
|