const Express = require("express");
const Router = Express.Router();
const JSONMiddleware= require("express-json-object-middleware");
const ProjectsController = require("../controllers/projects-controller");
Router.get("/", JSONMiddleware.parse, ProjectsController.editByQuery);
Router.delete("/", JSONMiddleware.parse, ProjectsController.removeByQuery);
module.exports = Router;
const Express = require("express");
const Router = Express.Router();
const ProjectRouter = require("./project");
Router.use("/projects", ProjectRouter);
Express().use("/", Router);
const axios = require("axios").default;
try {
const results = await axios.get("/projects", {filter: {_id: 1}});
console.log(results);
} catch(err) {
console.log(err)
}
parse(req, res, next){
parse(req, res, next) {
if ((req.query === undefined) || (req.query.params === undefined)) {
return next()
};
const JSONQuery = {};
const query = typeof(req.query.params) === "string"
? JSON.parse(req.query.params)
: req.query.params;
Object.keys(query).map(key => {
JSONQuery[key] = query[key];
})
req.query = JSONQuery;
return next();
}
}
req.query = JSONQuery;
return next();
}