21 lines
718 B
TypeScript
21 lines
718 B
TypeScript
import { forwardToCms } from "~/server/utils/cmsApi";
|
|
import { invalidOrderUpdate, pickCustomerUpdate } from "~/server/utils/customerUpdate";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const uuid = getRouterParam(event, "uuid");
|
|
if (!uuid) {
|
|
throw createError({ statusCode: 400, statusMessage: "Missing order UUID" });
|
|
}
|
|
|
|
// Only the fields of the checkout's steps reach the CMS, which checks their values. Any other field is answered 400 here.
|
|
const update = pickCustomerUpdate(await readBody(event));
|
|
if (update.ok === false) {
|
|
throw createError(invalidOrderUpdate(update.errors));
|
|
}
|
|
|
|
return await forwardToCms(`/orders/${uuid}/cart`, {
|
|
method: "PUT",
|
|
body: { data: update.data }
|
|
});
|
|
});
|