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
95 lines
3.3 KiB
TypeScript
95 lines
3.3 KiB
TypeScript
import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi";
|
|
import type {
|
|
AdminBulletin,
|
|
BulletinArea,
|
|
BulletinImageUploadResult,
|
|
BulletinStatus,
|
|
} from "@/app/lib/types";
|
|
|
|
// Client-side wrapper for the /bulletins management page. Calls only the portal's own
|
|
// /api/bulletins/** route handlers, mirroring app/lib/services/messages.ts.
|
|
|
|
export interface BulletinListParams {
|
|
area?: BulletinArea;
|
|
countryPrefix?: string;
|
|
status?: BulletinStatus;
|
|
type?: "B" | "P";
|
|
/** 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 BulletinListResult {
|
|
items: AdminBulletin[];
|
|
total: number;
|
|
}
|
|
|
|
export const AREA_OPTIONS: { value: BulletinArea; label: string }[] = [
|
|
{ value: "A", label: "Admin" },
|
|
{ value: "M", label: "Member" },
|
|
{ value: "P", label: "Public" },
|
|
{ value: "K", label: "BltnAreaBcKp" },
|
|
];
|
|
|
|
/** `page` here is 1-based; mobile-api's `/api/admin/bulletins` is 0-based. */
|
|
export function buildBulletinsQuery(params: BulletinListParams): string {
|
|
const qs = new URLSearchParams();
|
|
if (params.area) qs.set("area", params.area);
|
|
if (params.countryPrefix) qs.set("countryPrefix", params.countryPrefix);
|
|
if (params.status) qs.set("status", params.status);
|
|
if (params.type) qs.set("type", params.type);
|
|
qs.set("page", String(Math.max(0, params.page - 1)));
|
|
qs.set("size", String(params.pageSize));
|
|
if (params.sortBy) qs.set("sortBy", params.sortBy);
|
|
if (params.sortDir && params.sortBy) qs.set("sortDir", params.sortDir);
|
|
return qs.toString();
|
|
}
|
|
|
|
function normalizeBulletinPage(raw: unknown): BulletinListResult {
|
|
if (!raw || typeof raw !== "object") return { items: [], total: 0 };
|
|
const obj = raw as Record<string, unknown>;
|
|
const items: AdminBulletin[] = Array.isArray(obj.content)
|
|
? (obj.content as AdminBulletin[])
|
|
: Array.isArray(obj.items)
|
|
? (obj.items as AdminBulletin[])
|
|
: [];
|
|
const total =
|
|
typeof obj.totalElements === "number"
|
|
? obj.totalElements
|
|
: typeof obj.total === "number"
|
|
? obj.total
|
|
: items.length;
|
|
return { items, total };
|
|
}
|
|
|
|
export async function listBulletins(params: BulletinListParams): Promise<BulletinListResult> {
|
|
const raw = await apiGet<unknown>(`/api/bulletins?${buildBulletinsQuery(params)}`);
|
|
return normalizeBulletinPage(raw);
|
|
}
|
|
|
|
export async function getBulletin(id: number): Promise<AdminBulletin> {
|
|
return apiGet<AdminBulletin>(`/api/bulletins/${id}`);
|
|
}
|
|
|
|
/** Upsert: `payload.id` present -> PUT (update/deactivate), absent -> POST (insert). */
|
|
export async function saveBulletin(payload: AdminBulletin): Promise<AdminBulletin> {
|
|
return payload.id
|
|
? apiPut<AdminBulletin>(`/api/bulletins/${payload.id}`, payload)
|
|
: apiPost<AdminBulletin>("/api/bulletins", payload);
|
|
}
|
|
|
|
/**
|
|
* Uploads a bulletin image (upload-on-submit): the mobile-api upload is SAME-REQUEST
|
|
* (file_autocommit=Y), so the returned public URL can be persisted in `imageUrl` immediately.
|
|
*/
|
|
export async function uploadBulletinImage(input: {
|
|
fileName: string;
|
|
fileType: string;
|
|
base: string;
|
|
}): Promise<BulletinImageUploadResult> {
|
|
return apiPost<BulletinImageUploadResult>("/api/bulletins/image", input);
|
|
}
|