Merge branch 'master' of github.com:rts-cmk/dyrevelfaerd-api

This commit is contained in:
Brian Emilius
2021-02-10 14:56:48 +01:00
3 changed files with 24 additions and 2 deletions

View File

@@ -14,3 +14,6 @@ npm start
## Documentation
http://localhost:4000
## Configuration
Edit `.env` with the appropriate values for each variable.

View File

@@ -34,8 +34,26 @@ async function getSingleAsset(req, res, next) {
}
}
async function updateSingleAsset(req, res, next) {
try {
let asset = await Asset.findByPk(req.params.id);
if (asset) {
asset.url = req.fields.url;
asset.save();
res.json(asset);
} else {
res.status(404).end();
}
} catch(error) {
console.error(error);
res.status(500).end();
}
}
module.exports = {
createSingleAsset,
getAllAssets,
getSingleAsset
getSingleAsset,
updateSingleAsset
};

View File

@@ -1,8 +1,9 @@
var { createSingleAsset, getAllAssets, getSingleAsset } = require("../controllers/asset.controller");
var { createSingleAsset, getAllAssets, getSingleAsset, updateSingleAsset } = require("../controllers/asset.controller");
var { isAuthorized } = require("../middleware/auth");
module.exports = function(router) {
router.post("/api/v1/assets", isAuthorized, createSingleAsset);
router.get("/api/v1/assets", getAllAssets);
router.get("/api/v1/assets/:id", getSingleAsset);
router.patch("/api/v1/assets/:id", updateSingleAsset);
};