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
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { callMobileApi } from "@/app/lib/server/mobileApi";
|
|
import { getToken } from "@/app/lib/server/session";
|
|
import { errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
|
|
import { paging, SORT, TEXT, upstreamQuery } from "@/app/lib/server/upstreamQuery";
|
|
import type { AdminMemberPage } from "@/app/lib/types";
|
|
|
|
// GET -> /api/admin/members*. Forwards the bb_admin JWT from the session cookie
|
|
// and the full query string (filters + paging) to mobile-api. Read-only — no
|
|
// side effect on GET (Next.js prefetch-safe).
|
|
|
|
const QUERY = {
|
|
memberCode: TEXT,
|
|
name: TEXT,
|
|
email: TEXT,
|
|
phoneNo: TEXT,
|
|
status: TEXT,
|
|
joinDateFrom: TEXT,
|
|
joinDateTo: TEXT,
|
|
gender: TEXT,
|
|
bank: TEXT,
|
|
sponsorId: TEXT,
|
|
q: TEXT,
|
|
rank: TEXT,
|
|
nickname: TEXT,
|
|
sponsor: TEXT,
|
|
referrer: TEXT,
|
|
...paging(500),
|
|
...SORT,
|
|
};
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
|
|
// portal-query-allowlist (F38): only the params mobile-api accepts, validated and encoded.
|
|
const qs = upstreamQuery(new URL(req.url).searchParams, QUERY);
|
|
const result = await callMobileApi<AdminMemberPage>(`/api/admin/members${qs}`, { token });
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|
|
|
|
// POST -> admin "Register member" (babyboo-42). Only the registration fields are forwarded, as
|
|
// strings — never an actor or a password; the actor comes from the JWT upstream (mobile-api), and a
|
|
// caller without BO_MEMBERS is refused there with 403, which passes through.
|
|
const REGISTRATION_FIELDS = ["name", "nickname", "email", "dob", "phoneNoPrefix", "phoneNo", "referralCode"] as const;
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
|
|
const raw = (await req.json().catch(() => ({}))) as Record<string, unknown>;
|
|
const body = Object.fromEntries(
|
|
REGISTRATION_FIELDS.map(key => [key, typeof raw[key] === "string" ? raw[key] : ""]),
|
|
);
|
|
const result = await callMobileApi<{ memberCode: string; emailSent: boolean }>("/api/admin/members", {
|
|
method: "POST",
|
|
body,
|
|
token,
|
|
});
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|