From 0ed1477ab7deb9bed76b91c0a498fa2055dd7756 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Fri, 22 Oct 2021 16:22:30 +0530 Subject: [PATCH] Handling the get request params using query and not body --- src/library/library-routes.ts | 4 ++-- src/user-profile/category-routes.ts | 9 ++++++++- src/user-profile/shelf-routes.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/library/library-routes.ts b/src/library/library-routes.ts index 89d080e..544e5de 100644 --- a/src/library/library-routes.ts +++ b/src/library/library-routes.ts @@ -23,14 +23,14 @@ libraryRoutes.get('/all/', jwtAuthentication, async (request, response) => { libraryRoutes.get('/search/', jwtAuthentication, async (request, response) => { const wordCollection = getDatabaseClient().db(DB_NAME).collection('words'); - if (!request.body.name) { + if (!request.query.name) { response.status(400); response.send("Fill in the word to search for"); return; } const allWords = await wordCollection.find({ - name: {'$regex':'^' + request.body.name.toString().toUpperCase() + '*'} + name: {'$regex':'^' + request.query.name.toString().toUpperCase() + '*'} }).toArray(); response.status(200); diff --git a/src/user-profile/category-routes.ts b/src/user-profile/category-routes.ts index 9c6d98b..f74c7b7 100644 --- a/src/user-profile/category-routes.ts +++ b/src/user-profile/category-routes.ts @@ -14,8 +14,15 @@ export const jwtAuthentication = passport.authenticate('jwt', { session: false } categoryRoutes.get('/details/', jwtAuthentication, async (request, response) => { const categoryCollection = getDatabaseClient().db(DB_NAME).collection('categories'); + + if (!request.query._id) { + response.status(400); + response.send("Missing category _id"); + return; + } + const currentCategory = await categoryCollection.findOne({ - _id: new ObjectId(request.body._id), + _id: new ObjectId(request.query._id.toString()), }); if (currentCategory) { diff --git a/src/user-profile/shelf-routes.ts b/src/user-profile/shelf-routes.ts index 3246d86..d6d29d6 100644 --- a/src/user-profile/shelf-routes.ts +++ b/src/user-profile/shelf-routes.ts @@ -17,7 +17,7 @@ shelfRoutes.get('/details/', jwtAuthentication, async (request, response) => { const shelfCollection = getDatabaseClient().db(DB_NAME).collection('shelves'); const currentShelf = await shelfCollection.findOne({ - _id: new ObjectId(request.body._id) + _id: new ObjectId(request.query._id.toString()) }); if (!currentShelf) {