You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

import { parseAdminAuth } from "@/lib/api/admin-auth-context";
import { fail, ok } from "@/lib/response";
import { AuthError } from "@/modules/auth/errors";
import { resolveBusinessCustomerByAccount } from "@/modules/customer/business-customer-user-service";
type RouteContext = {
params: Promise<{ customer_id: string }>;
};
/** GET ?account= 按登录账号反查业务客户 */
export async function GET(request: Request, context: RouteContext) {
try {
parseAdminAuth(request);
} catch (error) {
if (error instanceof AuthError) {
return fail(error.code, error.message, error.httpStatus);
}
throw error;
}
const { customer_id: customerId } = await context.params;
const account = new URL(request.url).searchParams.get("account")?.trim() || "";
if (!account) {
return fail("VALIDATION_FAILED", "请填写登录账号", 400);
}
const resolved = await resolveBusinessCustomerByAccount(customerId, account);
if (!resolved) {
return fail("NOT_FOUND", "未找到该账号对应的业务客户", 404);
}
return ok(resolved);
}