diff options
| author | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-08 08:26:47 +0100 |
|---|---|---|
| committer | Joe Carstairs <65492573+Sycamost@users.noreply.github.com> | 2023-08-08 08:26:47 +0100 |
| commit | 59558223a39d069a368e556794918f0f42292373 (patch) | |
| tree | 7d379e65034724c168fa9f1f4f94d47308ea8e4f /api/Order.js | |
| parent | 788564803d72c8d5aa412165ab7121398dc0feb3 (diff) | |
Handles PATCH
Diffstat (limited to 'api/Order.js')
| -rw-r--r-- | api/Order.js | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/api/Order.js b/api/Order.js index 1ef976d..afc322e 100644 --- a/api/Order.js +++ b/api/Order.js @@ -46,12 +46,18 @@ function handler(request, response) { return [4 /*yield*/, handlePost(request, response)]; case 1: _a.sent(); - return [3 /*break*/, 3]; + return [3 /*break*/, 5]; case 2: + if (!(request.method === 'PATCH')) return [3 /*break*/, 4]; + return [4 /*yield*/, handlePatch(request, response)]; + case 3: + _a.sent(); + return [3 /*break*/, 5]; + case 4: console.warn('Method was not POST. Method was ' + request.method); response.status(404); return [2 /*return*/]; - case 3: return [2 /*return*/]; + case 5: return [2 /*return*/]; } }); }); @@ -93,4 +99,37 @@ function handlePost(request, response) { }); }); } +function handlePatch(request, response) { + return __awaiter(this, void 0, void 0, function () { + var _a, id, isApproved, paypalResponse, err_2; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = request.body, id = _a.id, isApproved = _a.isApproved; + if (!!id) return [3 /*break*/, 1]; + response.status(400).send('Expected body to contain id, but none provided.'); + return [3 /*break*/, 5]; + case 1: + if (!!isApproved) return [3 /*break*/, 2]; + response.status(400).send('Expected body to contain isApproved, but none provided.'); + return [3 /*break*/, 5]; + case 2: + _b.trys.push([2, 4, , 5]); + return [4 /*yield*/, (0, _paypal_1.paypalCaptureOrder)(id)]; + case 3: + paypalResponse = _b.sent(); + response.status(201).json({ + orderId: paypalResponse.id, + paypalStatus: paypalResponse.status, + }); + return [3 /*break*/, 5]; + case 4: + err_2 = _b.sent(); + response.status(500).send("Internal server error. ".concat(err_2)); + return [3 /*break*/, 5]; + case 5: return [2 /*return*/]; + } + }); + }); +} //# sourceMappingURL=order.js.map
\ No newline at end of file |
