Files
co-lite/solvway-admin-portal/app/lib/services/adminWithdrawals.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
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
2026-11-26 15:55:45 +08:00

58 lines
2.5 KiB
TypeScript

import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
import type {
AdminWithdrawalPage,
AdminWithdrawalRow,
WithdrawalConfig,
WithdrawalConfigInput,
} from "@/app/lib/types";
// Client over the BFF route handlers (app/api/admin/withdrawal/**), which forward
// the bb_admin JWT to mobile-api. A caller without the BO_WALLET module gets a
// 4xx from mobile-api and the view renders its not-authorised state (the
// RequireModule gate fires first). Approve/reject are mutations and are always
// POST — never a GET. Mirrors adminTopups.ts.
/** Paged withdrawal queue. `status` is a status code or `"ALL"`; `member` matches code or name. `cycle` is `"NONE"` (unscheduled) or an ISO
* date-time exactly as returned by `nextCutoff`/`payoutCycleCutoff`; omitted entirely
* when not supplied (no filter). */
export async function getPendingWithdrawals(
page: number,
pageSize: number,
filters: { cycle?: string; status?: string; member?: string } = {},
sort: { sortBy?: string; sortDir?: "asc" | "desc" } = {},
): Promise<AdminWithdrawalPage> {
const params = new URLSearchParams({
page: String(Math.max(0, page - 1)),
size: String(pageSize),
});
for (const [key, value] of Object.entries(filters)) {
if (value) params.set(key, value);
}
if (sort.sortBy) {
params.set("sortBy", sort.sortBy);
if (sort.sortDir) params.set("sortDir", sort.sortDir);
}
return apiGet<AdminWithdrawalPage>(`/api/admin/withdrawal/list?${params.toString()}`);
}
/** Current min/max/increment/fee + weekly cut-off settings (BABYBOO-13, Task 4). */
export async function getWithdrawalConfig(): Promise<WithdrawalConfig> {
return apiGet<WithdrawalConfig>("/api/admin/withdrawal/config");
}
/** Saves the settings — a mutation, always PUT. Optional fields are sent as `null`
* when blank (never `0` or `""`); the server stays authoritative on validation. */
export async function updateWithdrawalConfig(input: WithdrawalConfigInput): Promise<WithdrawalConfig> {
return apiPut<WithdrawalConfig>("/api/admin/withdrawal/config", input);
}
/** Single-stage approval: disburses the net amount (stub adapter) and records the approver. */
export async function approveWithdrawal(uuid: string): Promise<AdminWithdrawalRow> {
return apiPost<AdminWithdrawalRow>("/api/admin/withdrawal/approve", { uuid });
}
/** Rejection with a reason (reverses the reservation). */
export async function rejectWithdrawal(uuid: string, reason: string): Promise<AdminWithdrawalRow> {
return apiPost<AdminWithdrawalRow>("/api/admin/withdrawal/reject", { uuid, reason });
}