From 073b270d34886f76cbf9c934f221920f19a5789b Mon Sep 17 00:00:00 2001 From: versx Date: Sat, 29 May 2021 13:58:35 -0700 Subject: [PATCH] Add missing edit location endpoint --- src/routes/api.js | 30 +++++++++++++++++++++++++++--- src/views/locations/edit.mustache | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/routes/api.js b/src/routes/api.js index 986981a..1788e62 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -1137,10 +1137,10 @@ router.post('/location/new', async (req, res) => { longitude: split[1], }); } else { - exists.name = name, - exists.latitude = split[0], - exists.longitude = split[1], + exists.name = name; exists.distance = distance; + exists.latitude = split[0]; + exists.longitude = split[1]; } const results = await exists.save(); if (results) { @@ -1153,6 +1153,30 @@ router.post('/location/new', async (req, res) => { res.redirect('/locations'); }); +router.post('/location/edit/:id', async (req, res) => { + const id = req.params.id; + const { name, location, distance, } = req.body; + const loc = await Location.getById(id); + if (loc) { + const split = location.split(','); + if (split.length !== 2) { + // TODO: Failed to parse selected location + } + loc.name = name; + loc.distance = distance; + loc.latitude = split[0]; + loc.longitude = split[1]; + const result = loc.save(); + if (result) { + // Success + console.log('Location subscription', id, 'updated successfully.'); + } else { + showError(res, 'locations/locations', `Failed to update Location subscription ${id}`); + } + } + res.redirect('/locations'); +}); + router.post('/locations/delete/:id', async (req, res) => { const id = req.params.id; const exists = await Location.getById(id); diff --git a/src/views/locations/edit.mustache b/src/views/locations/edit.mustache index ef5d8de..9469b7f 100644 --- a/src/views/locations/edit.mustache +++ b/src/views/locations/edit.mustache @@ -11,7 +11,7 @@

{{Edit Location}} {{name}}


-
+
{{Location Name}}