Skip to content

Commit 3e9b49b

Browse files
committed
added query for single or multiple documents
1 parent ae06666 commit 3e9b49b

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

mongodb/node/api_docs_server.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const path = require("path")
88
const mongodb = require("mongodb");
99

1010
// Services
11-
const mongoDBService = require("./services/mongodb")
11+
const mongoDBService = require("./services/mongodb");
12+
const { resolveSoa } = require("dns");
1213

1314
// Middleware
1415
app.use(express.json());
@@ -26,9 +27,19 @@ app.use(express.json());
2627
*
2728
* @apiSuccessExample Success-Response:
2829
* HTTP/1.1 200 OK
29-
* {
30-
* "result": "success"
31-
* }
30+
* [
31+
* {
32+
* "_id": STRING,
33+
* "name": STRING,
34+
* "health": NUMBER,
35+
* "stamina": NUMBER,
36+
* "mana": NUMBER,
37+
* "atk": NUMBER,
38+
* "items": STRING[],
39+
* "canFight": BOOL,
40+
* "canCast": BOOL
41+
* }
42+
* ]
3243
*
3344
* @apiError Unable_To_Query Failed to query documents in collection.
3445
*
@@ -38,14 +49,18 @@ app.use(express.json());
3849
* "result": "failure"
3950
* }
4051
*/
41-
app.get("/document", async (req, res, next) => {
52+
app.get("/documents", async (req, res, next) => {
4253

4354
let query = req.body;
4455

4556
try {
46-
let heroes = await mongoDBService.HeroesDb.Get(query);
57+
let documents = await mongoDBService.HeroesDb.Get(query);
4758

48-
console.log("FINISHED");
59+
if (documents.length > 0) {
60+
res.json(documents);
61+
} else {
62+
res.status(404).json({"result": "failure"});
63+
}
4964

5065
} catch(e) {
5166
e.httpStatusCode = 500;

0 commit comments

Comments
 (0)