v0.1.2: checkout fixes for CMS v0.2.0 (#18)
Co-authored-by: Michael Czechowski <mail@librete.ch>
This commit was merged in pull request #18.
This commit is contained in:
1 parent
60b8f1ab58
commit
fccff147ba
29 files changed
+1108
-71
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { fetchCms } from "~/server/utils/cmsApi";
|
||||
import { forwardToCms } from "~/server/utils/cmsApi";
|
||||
import { invalidOrderUpdate, pickCustomerUpdate } from "~/server/utils/customerUpdate";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const uuid = getRouterParam(event, "uuid");
|
||||
@@ -6,10 +7,14 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 400, statusMessage: "Missing order UUID" });
|
||||
}
|
||||
|
||||
const body = await readBody(event);
|
||||
// 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 fetchCms(`/orders/${uuid}/cart`, {
|
||||
return await forwardToCms(`/orders/${uuid}/cart`, {
|
||||
method: "PUT",
|
||||
body
|
||||
body: { data: update.data }
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user