diff --git a/README.md b/README.md index 1925822..a79cd19 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,6 @@ npm start ## Documentation http://localhost:4000 + +## Configuration +Edit `.env` with the appropriate values for each variable. diff --git a/controllers/asset.controller.js b/controllers/asset.controller.js index f2a7c27..348293f 100644 --- a/controllers/asset.controller.js +++ b/controllers/asset.controller.js @@ -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 }; diff --git a/routes/asset.route.js b/routes/asset.route.js index c98ff00..110e1a5 100644 --- a/routes/asset.route.js +++ b/routes/asset.route.js @@ -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); };