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.
63 lines
2.1 KiB
63 lines
2.1 KiB
import { assertCustomerMatch, parseServiceAuth } from "@/lib/api/auth-context";
|
|
import { enforceRateLimits } from "@/lib/api/rate-limit";
|
|
import { fail, ok } from "@/lib/response";
|
|
import { AuthError } from "@/modules/auth/errors";
|
|
import { msRefineDetailsSchema } from "@/modules/mothership/refine-validation";
|
|
import { submitMsRefineDetails } from "@/modules/mothership/refine-service";
|
|
import type { QuoteRequestBody } from "@/lib/frontend/types";
|
|
|
|
/** 提交二级 Details → 驻留页 Save&update 刷价 */
|
|
export async function POST(request: Request) {
|
|
let auth;
|
|
try {
|
|
auth = await parseServiceAuth(request);
|
|
} catch (error) {
|
|
if (error instanceof AuthError) {
|
|
return fail(error.code, error.message, error.httpStatus);
|
|
}
|
|
throw error;
|
|
}
|
|
|
|
const rateLimited = await enforceRateLimits(request, auth.customerId);
|
|
if (rateLimited) return rateLimited;
|
|
|
|
let body: unknown;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return fail("VALIDATION_FAILED", "请求体格式无效", 400);
|
|
}
|
|
|
|
const parsed = msRefineDetailsSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
return fail(
|
|
"VALIDATION_FAILED",
|
|
parsed.error.issues[0]?.message ?? "参数无效",
|
|
400,
|
|
);
|
|
}
|
|
|
|
try {
|
|
assertCustomerMatch(auth, parsed.data.customer_id);
|
|
const result = await submitMsRefineDetails({
|
|
customerId: parsed.data.customer_id,
|
|
quoteId: parsed.data.quote_id,
|
|
sessionId: parsed.data.quote_session_id,
|
|
mothershipDetails:
|
|
parsed.data.mothership_details as QuoteRequestBody["mothership_details"],
|
|
pickupAccessorials: parsed.data.pickup_accessorials,
|
|
deliveryAccessorials: parsed.data.delivery_accessorials,
|
|
readyDate: parsed.data.ready_date,
|
|
readyTime: parsed.data.ready_time,
|
|
cargoLines: parsed.data.cargo_lines,
|
|
});
|
|
return ok(result);
|
|
} catch (error) {
|
|
if (error instanceof AuthError) {
|
|
return fail(error.code, error.message, error.httpStatus);
|
|
}
|
|
const msg = error instanceof Error ? error.message : "提交刷价失败";
|
|
return fail("VALIDATION_FAILED", msg, 400);
|
|
}
|
|
}
|