Просмотр исходного кода

Handling the get request params using query and not body

master
kj1352 4 лет назад
Родитель
Сommit
0ed1477ab7
3 измененных файлов: 11 добавлений и 4 удалений
  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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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) {


Загрузка…
Отмена
Сохранить