From 1bb05a1baf9e82f41661d20bcd8bafd44e08fcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Mon, 14 Jun 2021 20:54:54 +0200 Subject: [PATCH] BETTERZON-143: Fixing API endpoints that didn't return a json --- .../models/contact_persons/contact_persons.router.ts | 8 ++++---- .../models/crawling_status/crawling_status.router.ts | 2 +- Backend/src/models/prices/prices.router.ts | 4 ++-- Backend/src/models/products/products.router.ts | 2 +- Backend/src/models/users/users.router.ts | 4 ++-- Backend/src/models/vendors/vendors.router.ts | 12 ++++++------ 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Backend/src/models/contact_persons/contact_persons.router.ts b/Backend/src/models/contact_persons/contact_persons.router.ts index 85c8035..b06f62d 100644 --- a/Backend/src/models/contact_persons/contact_persons.router.ts +++ b/Backend/src/models/contact_persons/contact_persons.router.ts @@ -89,9 +89,9 @@ contactpersonsRouter.post('/', async (req: Request, res: Response) => { const success = await ContactPersonService.createContactEntry(user.user_id, vendor_id, first_name, last_name, gender, email, phone); if (success) { - res.sendStatus(201); + res.status(201).send({}); } else { - res.sendStatus(500); + res.status(500).send({}); } } catch (e) { console.log('Error handling a request: ' + e.message); @@ -118,9 +118,9 @@ contactpersonsRouter.put('/:id', async (req: Request, res: Response) => { const success = await ContactPersonService.updateContactEntry(user.user_id, contact_person_id, vendor_id, first_name, last_name, gender, email, phone); if (success) { - res.sendStatus(200); + res.status(200).send({}); } else { - res.sendStatus(500); + res.status(500).send({}); } } catch (e) { console.log('Error handling a request: ' + e.message); diff --git a/Backend/src/models/crawling_status/crawling_status.router.ts b/Backend/src/models/crawling_status/crawling_status.router.ts index b442c26..4ca0b89 100644 --- a/Backend/src/models/crawling_status/crawling_status.router.ts +++ b/Backend/src/models/crawling_status/crawling_status.router.ts @@ -28,7 +28,7 @@ crawlingstatusRouter.get('/', async (req: Request, res: Response) => { const user = await UserService.checkSessionWithCookie(req.cookies.betterauth, user_ip); if (!user.is_admin) { - res.sendStatus(403); + res.status(403).send({}); return; } diff --git a/Backend/src/models/prices/prices.router.ts b/Backend/src/models/prices/prices.router.ts index 6d3d389..16bc5ba 100644 --- a/Backend/src/models/prices/prices.router.ts +++ b/Backend/src/models/prices/prices.router.ts @@ -117,9 +117,9 @@ pricesRouter.post('/', async (req: Request, res: Response) => { const success = await PriceService.createPriceEntry(user.user_id, vendor_id, product_id, price_in_cents); if (success) { - res.sendStatus(201); + res.status(201).send({}); } else { - res.sendStatus(500); + res.status(500).send({}); } } catch (e) { console.log('Error handling a request: ' + e.message); diff --git a/Backend/src/models/products/products.router.ts b/Backend/src/models/products/products.router.ts index 115d655..a30e8ef 100644 --- a/Backend/src/models/products/products.router.ts +++ b/Backend/src/models/products/products.router.ts @@ -120,7 +120,7 @@ productsRouter.post('/', async (req: Request, res: Response) => { const result: boolean = await ProductService.addNewProduct(asin); if (result) { - res.sendStatus(201); + res.status(201).send({}); } else { res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); } diff --git a/Backend/src/models/users/users.router.ts b/Backend/src/models/users/users.router.ts index fe67f1b..79c3034 100644 --- a/Backend/src/models/users/users.router.ts +++ b/Backend/src/models/users/users.router.ts @@ -50,7 +50,7 @@ usersRouter.post('/register', async (req: Request, res: Response) => { res.cookie('betterauth', JSON.stringify({ id: session.session_id, key: session.session_key - }), {expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)}).sendStatus(201); + }), {expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)}).status(201).send({}); } catch (e) { console.log('Error handling a request: ' + e.message); res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); @@ -83,7 +83,7 @@ usersRouter.post('/login', async (req: Request, res: Response) => { res.cookie('betterauth', JSON.stringify({ id: session.session_id, key: session.session_key - }), {expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)}).sendStatus(200); + }), {expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)}).status(200).send({}); } catch (e) { console.log('Error handling a request: ' + e.message); res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); diff --git a/Backend/src/models/vendors/vendors.router.ts b/Backend/src/models/vendors/vendors.router.ts index 20d2086..7888cae 100644 --- a/Backend/src/models/vendors/vendors.router.ts +++ b/Backend/src/models/vendors/vendors.router.ts @@ -100,9 +100,9 @@ vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Respons const success = await VendorService.deactivateListing(user.user_id, vendor_id, product_id); if (success) { - res.sendStatus(200); + res.status(200).send({}); } else { - res.sendStatus(500); + res.status(500).send({}); } } catch (e) { console.log('Error handling a request: ' + e.message); @@ -123,9 +123,9 @@ vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Respo const success = await VendorService.setShopStatus(user.user_id, vendor_id, false); if (success) { - res.sendStatus(200); + res.status(200).send({}); } else { - res.sendStatus(500); + res.status(500).send({}); } } catch (e) { console.log('Error handling a request: ' + e.message); @@ -146,9 +146,9 @@ vendorsRouter.put('/manage/shop/activate/:id', async (req: Request, res: Respons const success = await VendorService.setShopStatus(user.user_id, vendor_id, true); if (success) { - res.sendStatus(200); + res.status(200).send({}); } else { - res.sendStatus(500); + res.status(500).send({}); } } catch (e) { console.log('Error handling a request: ' + e.message);