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
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
|
|
import type {
|
|
AdminBanner,
|
|
BannerImageUploadResult,
|
|
BannerLinkKind,
|
|
BannerStatus,
|
|
BannerZone,
|
|
BannerZoneSetting,
|
|
} from "@/app/lib/types";
|
|
|
|
// Client-side wrapper for the /banners management page. Calls only the portal's own
|
|
// /api/banners/** and /api/banner-settings/** route handlers, mirroring
|
|
// app/lib/services/bulletins.ts.
|
|
|
|
export interface BannerListParams {
|
|
/** Required: mobile-api's GET /api/admin/banners has no all-zones read. */
|
|
zone: BannerZone;
|
|
status?: BannerStatus;
|
|
}
|
|
|
|
export const ZONE_OPTIONS: { value: BannerZone; label: string }[] = [
|
|
{ value: "HERO", label: "BnrZoneHero" },
|
|
{ value: "CAMPAIGN", label: "BnrZoneCampaign" },
|
|
];
|
|
|
|
export const LINK_KIND_OPTIONS: { value: BannerLinkKind; label: string }[] = [
|
|
{ value: "PRODUCT", label: "BnrLinkProduct" },
|
|
{ value: "CATEGORY", label: "Category" },
|
|
{ value: "URL", label: "BnrLinkUrl" },
|
|
{ value: "NONE", label: "BnrLinkNone" },
|
|
];
|
|
|
|
export async function listBanners(params: BannerListParams): Promise<AdminBanner[]> {
|
|
const qs = new URLSearchParams();
|
|
qs.set("zone", params.zone);
|
|
if (params.status) qs.set("status", params.status);
|
|
return apiGet<AdminBanner[]>(`/api/banners?${qs.toString()}`);
|
|
}
|
|
|
|
export async function getBanner(id: number): Promise<AdminBanner> {
|
|
return apiGet<AdminBanner>(`/api/banners/${id}`);
|
|
}
|
|
|
|
/** Upsert: `payload.id` present -> PUT (update), absent -> POST (insert). */
|
|
export async function saveBanner(payload: AdminBanner): Promise<AdminBanner> {
|
|
return payload.id
|
|
? apiPut<AdminBanner>(`/api/banners/${payload.id}`, payload)
|
|
: apiPost<AdminBanner>("/api/banners", payload);
|
|
}
|
|
|
|
/**
|
|
* Uploads a banner image (upload-on-submit): the mobile-api upload is SAME-REQUEST
|
|
* (file_autocommit=Y), so the returned public URL can be persisted immediately.
|
|
*/
|
|
export async function uploadBannerImage(input: {
|
|
fileName: string;
|
|
fileType: string;
|
|
base: string;
|
|
zone: BannerZone;
|
|
}): Promise<BannerImageUploadResult> {
|
|
return apiPost<BannerImageUploadResult>("/api/banners/image", input);
|
|
}
|
|
|
|
export async function getBannerSetting(zone: BannerZone): Promise<BannerZoneSetting> {
|
|
return apiGet<BannerZoneSetting>(`/api/banner-settings/${zone}`);
|
|
}
|
|
|
|
export async function saveBannerSetting(
|
|
zone: BannerZone,
|
|
rotationIntervalMs: number,
|
|
): Promise<BannerZoneSetting> {
|
|
return apiPut<BannerZoneSetting>(`/api/banner-settings/${zone}`, { rotationIntervalMs });
|
|
}
|