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/Order.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'api/Order.js') diff --git a/api/Order.js b/api/Order.js index 95ff8ab..1ef976d 100644 --- a/api/Order.js +++ b/api/Order.js @@ -38,17 +38,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) { Object.defineProperty(exports, "__esModule", { value: true }); var _paypal_1 = require("./_paypal"); function handler(request, response) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(request.method === 'POST')) return [3 /*break*/, 2]; + return [4 /*yield*/, handlePost(request, response)]; + case 1: + _a.sent(); + return [3 /*break*/, 3]; + case 2: + console.warn('Method was not POST. Method was ' + request.method); + response.status(404); + return [2 /*return*/]; + case 3: return [2 /*return*/]; + } + }); + }); +} +exports.default = handler; +function handlePost(request, response) { return __awaiter(this, void 0, void 0, function () { var _a, productDescription, shortDescription, totalPrice, paypalResponse, err_1; return __generator(this, function (_b) { switch (_b.label) { case 0: _a = request.body, productDescription = _a.productDescription, shortDescription = _a.shortDescription, totalPrice = _a.totalPrice; - if (request.method !== 'POST') { - console.warn('Method was not POST. Method was ' + request.method); - response.status(404); - return [2 /*return*/]; - } if (!!productDescription) return [3 /*break*/, 1]; response.status(400).send('Expected body to contain productDescription, but none provided.'); return [3 /*break*/, 6]; @@ -78,5 +93,4 @@ function handler(request, response) { }); }); } -exports.default = handler; //# sourceMappingURL=order.js.map \ No newline at end of file -- cgit v1.2.3