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
115 lines
4.6 KiB
TypeScript
115 lines
4.6 KiB
TypeScript
import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
|
|
import { CAMPAIGN_STATUS_FILTER_OPTIONS, REDEMPTION_STATUS_FILTER_OPTIONS, REDEMPTION_STATUS_LABEL } from "@/app/lib/promotionStatus";
|
|
import type {
|
|
CampaignInput,
|
|
CampaignStatus,
|
|
CampaignView,
|
|
PromotionPage,
|
|
VoucherBatch,
|
|
VoucherRow,
|
|
RedemptionRow,
|
|
} from "@/app/lib/types";
|
|
|
|
// Client-side wrapper for the /promotions BFF routes (add-promotions-campaigns). Calls only the
|
|
// portal's own /api/promotions/** route handlers, never solvway-mobile-api directly.
|
|
|
|
export { CAMPAIGN_STATUS_FILTER_OPTIONS, REDEMPTION_STATUS_FILTER_OPTIONS, REDEMPTION_STATUS_LABEL };
|
|
|
|
function filterQuery(filters: Record<string, string | undefined>): string {
|
|
return Object.entries(filters).filter(([, v]) => v).map(([k, v]) => `&${k}=${encodeURIComponent(v as string)}`).join("");
|
|
}
|
|
|
|
export async function listCampaigns(page = 0, size = 20, filters: { status?: string; q?: string; benefitType?: string; claimType?: string; channel?: string; from?: string; to?: string; sortBy?: string; sortDir?: string } = {}): Promise<PromotionPage<CampaignView>> {
|
|
return apiGet<CampaignView[]>(`/api/promotions/campaigns?page=${page}&size=${size}${filterQuery(filters)}`).then(
|
|
(r) => r as unknown as PromotionPage<CampaignView>,
|
|
);
|
|
}
|
|
|
|
export async function getCampaign(uuid: string): Promise<CampaignView> {
|
|
return apiGet<CampaignView>(`/api/promotions/campaigns/${encodeURIComponent(uuid)}`);
|
|
}
|
|
|
|
export async function createCampaign(input: CampaignInput): Promise<CampaignView> {
|
|
return apiPost<CampaignView>("/api/promotions/campaigns", input);
|
|
}
|
|
|
|
export async function updateCampaign(uuid: string, input: CampaignInput): Promise<CampaignView> {
|
|
return apiPut<CampaignView>(`/api/promotions/campaigns/${encodeURIComponent(uuid)}`, input);
|
|
}
|
|
|
|
export async function setCampaignStatus(
|
|
uuid: string,
|
|
status: CampaignStatus,
|
|
): Promise<CampaignView> {
|
|
return apiPost<CampaignView>(`/api/promotions/campaigns/${encodeURIComponent(uuid)}/status`, {
|
|
status,
|
|
});
|
|
}
|
|
|
|
export async function duplicateCampaign(uuid: string): Promise<CampaignView> {
|
|
return apiPost<CampaignView>(`/api/promotions/campaigns/${encodeURIComponent(uuid)}/duplicate`, {});
|
|
}
|
|
|
|
export async function listVouchers(
|
|
uuid: string,
|
|
page = 0,
|
|
size = 20,
|
|
filters: { status?: string; batchId?: string; member?: string; code?: string; invoiceNo?: string; sortBy?: string; sortDir?: string } = {},
|
|
): Promise<PromotionPage<VoucherRow>> {
|
|
return apiGet<VoucherRow[]>(
|
|
`/api/promotions/campaigns/${encodeURIComponent(uuid)}/vouchers?page=${page}&size=${size}${filterQuery(filters)}`,
|
|
).then((r) => r as unknown as PromotionPage<VoucherRow>);
|
|
}
|
|
|
|
export async function issueVouchers(
|
|
uuid: string,
|
|
memberCodes: string[],
|
|
expiresAt?: string | null,
|
|
rank?: string,
|
|
sendEmail?: boolean,
|
|
): Promise<{ issued: number; skipped?: number; emailed?: number }> {
|
|
const body: Record<string, unknown> = { memberCodes };
|
|
if (expiresAt) body.expiresAt = expiresAt;
|
|
if (rank) body.rank = rank;
|
|
if (sendEmail !== undefined) body.sendEmail = sendEmail;
|
|
return apiPost<{ issued: number; skipped?: number; emailed?: number }>(
|
|
`/api/promotions/campaigns/${encodeURIComponent(uuid)}/vouchers`,
|
|
body,
|
|
);
|
|
}
|
|
|
|
export async function generateVoucherCodes(
|
|
uuid: string,
|
|
quantity: number,
|
|
expiresAt: string | null,
|
|
batchNote: string,
|
|
): Promise<{ batchId: string; batchNote: string; codes: string[] }> {
|
|
return apiPost(`/api/promotions/campaigns/${encodeURIComponent(uuid)}/vouchers/generate`, {
|
|
quantity,
|
|
batchNote,
|
|
...(expiresAt ? { expiresAt } : {}),
|
|
});
|
|
}
|
|
|
|
export async function listVoucherBatches(uuid: string): Promise<VoucherBatch[]> {
|
|
return apiGet<VoucherBatch[]>(`/api/promotions/campaigns/${encodeURIComponent(uuid)}/voucher-batches`);
|
|
}
|
|
|
|
export async function revokeVoucher(voucherUuid: string): Promise<VoucherRow> {
|
|
return apiPost<VoucherRow>(`/api/promotions/vouchers/${encodeURIComponent(voucherUuid)}/revoke`, {});
|
|
}
|
|
|
|
export async function resendVoucherEmail(voucherUuid: string): Promise<{ sent: true }> {
|
|
return apiPost<{ sent: true }>(`/api/promotions/vouchers/${encodeURIComponent(voucherUuid)}/resend-email`, {});
|
|
}
|
|
|
|
export async function listRedemptions(
|
|
page = 0,
|
|
size = 20,
|
|
filters: { status?: string; from?: string; to?: string; campaignUuid?: string; invoiceNo?: string; member?: string; channel?: string; sortBy?: string; sortDir?: string } = {},
|
|
): Promise<PromotionPage<RedemptionRow>> {
|
|
return apiGet<RedemptionRow[]>(
|
|
`/api/promotions/redemptions?page=${page}&size=${size}${filterQuery(filters)}`,
|
|
).then((r) => r as unknown as PromotionPage<RedemptionRow>);
|
|
}
|