浏览代码

Handling the get request params using query and not body

master
kj1352 4 年前
父节点
当前提交
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) => { libraryRoutes.get('/search/', jwtAuthentication, async (request, response) => {
const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words');


if (!request.body.name) {
if (!request.query.name) {
response.status(400); response.status(400);
response.send("Fill in the word to search for"); response.send("Fill in the word to search for");
return; return;
} }


const allWords = await wordCollection.find({ const allWords = await wordCollection.find({
name: {'$regex':'^' + request.body.name.toString().toUpperCase() + '*'}
name: {'$regex':'^' + request.query.name.toString().toUpperCase() + '*'}
}).toArray(); }).toArray();


response.status(200); 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) => { categoryRoutes.get('/details/', jwtAuthentication, async (request, response) => {
const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); 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({ const currentCategory = await categoryCollection.findOne({
_id: new ObjectId(request.body._id),
_id: new ObjectId(request.query._id.toString()),
}); });


if (currentCategory) { 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 shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves');


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


if (!currentShelf) { if (!currentShelf) {


正在加载...
取消
保存