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
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
import { apiGet, apiPost } from "@/app/lib/clientApi";
|
|
import type { Currency, CurrencyType } from "@/app/lib/types";
|
|
|
|
// Client-side wrapper for the /currency management page. Calls only the
|
|
// portal's own /api/currency/** route handlers, which forward the admin JWT
|
|
// from the session cookie — never solvway-mobile-api directly.
|
|
|
|
export interface CurrencyListParams {
|
|
type: CurrencyType;
|
|
searchKey?: string;
|
|
/** "Y" | "N"; omitted for both. */
|
|
status?: string;
|
|
/** 1-based, matching this portal's other list pages. */
|
|
page: number;
|
|
pageSize: number;
|
|
/** Server-side sort: attribute name + direction; sent only when present. */
|
|
sortBy?: string;
|
|
sortDir?: "asc" | "desc";
|
|
}
|
|
|
|
export interface CurrencyListResult {
|
|
items: Currency[];
|
|
total: number;
|
|
}
|
|
|
|
/**
|
|
* The upstream pageable endpoint mixes both rate families and accepts no type
|
|
* filter, so the list fetch pulls ONE large window (mobile-api returns the
|
|
* complete filtered set in it) and pagination happens client-side over the
|
|
* filtered rows. This is viable because the currency table is small.
|
|
*/
|
|
const CURRENCY_FETCH_WINDOW = 500;
|
|
|
|
/**
|
|
* Builds the query string for GET /api/currency. The window is requested in one
|
|
* page (page=0, size=500); {@code page}/{@code pageSize} in {@code params} are
|
|
* applied client-side by {@link listCurrency}, not in the query.
|
|
*/
|
|
export function buildCurrencyQuery(params: CurrencyListParams): string {
|
|
const qs = new URLSearchParams();
|
|
qs.set("type", params.type);
|
|
if (params.searchKey) qs.set("searchKey", params.searchKey);
|
|
if (params.status) qs.set("status", params.status);
|
|
qs.set("page", "0");
|
|
qs.set("size", String(CURRENCY_FETCH_WINDOW));
|
|
if (params.sortBy) qs.set("sortBy", params.sortBy);
|
|
if (params.sortDir && params.sortBy) qs.set("sortDir", params.sortDir);
|
|
return qs.toString();
|
|
}
|
|
|
|
/**
|
|
* Fetches the full filtered window, re-filters it by the tab's type, and
|
|
* paginates the FILTERED set client-side — so every TRX/BNS row is reachable
|
|
* and the returned {@code total} (driving pagination) reflects the filtered set
|
|
* with no empty pages offered.
|
|
*/
|
|
export async function listCurrency(params: CurrencyListParams): Promise<CurrencyListResult> {
|
|
const raw = await apiGet<{ content?: Currency[]; totalElements?: number }>(
|
|
`/api/currency?${buildCurrencyQuery(params)}`,
|
|
);
|
|
const filtered = (raw.content ?? []).filter((row) => row.type === params.type);
|
|
const start = (params.page - 1) * params.pageSize;
|
|
const items = filtered.slice(start, start + params.pageSize);
|
|
return { items, total: filtered.length };
|
|
}
|
|
|
|
/** Rate history for a country+type, newest first (index 0 is the active rate). */
|
|
export async function getCurrencyHistory(
|
|
countryCode: string,
|
|
type: CurrencyType,
|
|
): Promise<Currency[]> {
|
|
return apiGet<Currency[]>(`/api/currency/history/${countryCode}/${type}`);
|
|
}
|
|
|
|
/** Append-only create: posts a new effective rate (never an id — a new row is always an insert). */
|
|
export async function createCurrency(payload: Omit<Currency, "id">): Promise<Currency> {
|
|
return apiPost<Currency>("/api/currency", payload);
|
|
}
|