File tree Expand file tree Collapse file tree 1 file changed +22
-7
lines changed
Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ const path = require("path")
88const 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
1415app . 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 ;
You can’t perform that action at this time.
0 commit comments