Procházet zdrojové kódy

Handling the get request params using query and not body

master
kj1352 před 4 roky
rodič
revize
0ed1477ab7
3 změnil soubory, kde provedl 11 přidání a 4 odebrání
  1. +2
    -2
      src/library/library-routes.ts
  2. +8
    -1
      src/user-profile/category-routes.ts
  3. +1
    -1
      src/user-profile/shelf-routes.ts

+ 2
- 2
src/library/library-routes.ts Zobrazit soubor

@@ -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<Word>('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);


+ 8
- 1
src/user-profile/category-routes.ts Zobrazit soubor

@@ -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<MongoCategory>('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) {


+ 1
- 1
src/user-profile/shelf-routes.ts Zobrazit soubor

@@ -17,7 +17,7 @@ shelfRoutes.get('/details/', jwtAuthentication, async (request, response) => {
const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves');

const currentShelf = await shelfCollection.findOne({
_id: new ObjectId(request.body._id)
_id: new ObjectId(request.query._id.toString())
});

if (!currentShelf) {


Načítá se…
Zrušit
Uložit