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
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { apiGet, apiPost } from "@/app/lib/clientApi";
|
|
import type { AppliedGiftCard, GiftCardAmount, PosGiftCardCheck, PosGiftCardSaleBody, PosGiftCardSaleResult } from "@/app/lib/types";
|
|
|
|
// Client-side POS gift card helpers (add-gift-card-counter). Uses same-origin /api/* routes.
|
|
|
|
export const listPosGiftCardAmounts = () => apiGet<GiftCardAmount[]>("/api/pos/gift-card/amounts");
|
|
|
|
export const checkPosGiftCard = (code: string) => apiPost<PosGiftCardCheck>("/api/pos/gift-card/check", { code });
|
|
|
|
export const sellCounterGiftCard = (body: PosGiftCardSaleBody) =>
|
|
apiPost<PosGiftCardSaleResult>("/api/counter/gift-card/sale", body);
|
|
|
|
export const sellEventGiftCard = (body: PosGiftCardSaleBody) =>
|
|
apiPost<PosGiftCardSaleResult>("/api/pos/gift-card/sale", body);
|
|
|
|
/** Cards pay in the order applied, each up to its balance. */
|
|
export function cardCover(cards: AppliedGiftCard[], total: number): { perCard: number[]; covered: number; left: number } {
|
|
let left = Math.round(total * 100);
|
|
const perCard = cards.map((c) => {
|
|
const pay = Math.min(Math.round(c.balance * 100), left);
|
|
left -= pay;
|
|
return pay / 100;
|
|
});
|
|
return { perCard, covered: Math.round(total * 100 - left) / 100, left: left / 100 };
|
|
}
|