From 788564803d72c8d5aa412165ab7121398dc0feb3 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Tue, 8 Aug 2023 08:20:36 +0100 Subject: Pulls out POST handler --- api-src/order.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'api-src') diff --git a/api-src/order.ts b/api-src/order.ts index 8937d04..c440399 100644 --- a/api-src/order.ts +++ b/api-src/order.ts @@ -3,14 +3,18 @@ import type Order from './_Order'; import { paypalCreateOrder } from './_paypal'; export default async function handler(request: VercelRequest, response: VercelResponse) { - const { productDescription, shortDescription, totalPrice }: Partial = request.body; - - if (request.method !== 'POST') { + if (request.method === 'POST') { + await handlePost(request, response); + } else { console.warn('Method was not POST. Method was ' + request.method); response.status(404); return; } +} +async function handlePost(request: VercelRequest, response: VercelResponse) { + const { productDescription, shortDescription, totalPrice }: Partial = request.body; + if (!productDescription) { response.status(400).send('Expected body to contain productDescription, but none provided.'); } else if (!shortDescription) { -- cgit v1.2.3