diff options
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) { |
