diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-08 08:20:36 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-08 08:20:36 +0100 |
| commit | 788564803d72c8d5aa412165ab7121398dc0feb3 (patch) | |
| tree | 06873f6fd302c55fe2020f99c4d314e955157d3f /api-src/order.ts | |
| parent | 91788279c9ad2712910c611887438920be0581f1 (diff) | |
Pulls out POST handler
Diffstat (limited to 'api-src/order.ts')
| -rw-r--r-- | api-src/order.ts | 10 |
1 files changed, 7 insertions, 3 deletions
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<Order> = 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<Order> = request.body; + if (!productDescription) { response.status(400).send('Expected body to contain productDescription, but none provided.'); } else if (!shortDescription) { |
