Skip to content

Commit

Permalink
Merge pull request #554 from rfcx/feature/CE-203-call-arbimon-on-stre…
Browse files Browse the repository at this point in the history
…am-updates

CE-203 add endpoint for site update from Core API
  • Loading branch information
rassokhin-s authored Feb 27, 2021
2 parents 994df18 + bd97556 commit 56426d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ New features:
- PI-574 Default map on the sites page should display sites
- PI-609/PI-252 Get Companions' images and show them for a current site
- PI-563 Fix timezone issue where AudioMoth UTC timezone is not translated
- CE-203 add endpoint for site update from Core API

Resolved issues:
- PI-495 Fix fuzzy images for Pattern Matching boxes in Chrome browser
Expand Down
34 changes: 34 additions & 0 deletions app/routes/data-api/ingest.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ router.post('/project/:id/sites/create', verifyToken(), hasRole(['appUser', 'rfc
}
})

router.patch('/sites/:externalId', verifyToken(), hasRole(['appUser', 'rfcxUser']), async function(req, res) {
try {
const user = await model.users.ensureUserExistFromAuth0(req.user);
const converter = new Converter(req.body, {});
converter.convert('name').optional().toString();
converter.convert('latitude').optional().toFloat().minimum(-90).maximum(90);
converter.convert('longitude').optional().toFloat().minimum(-180).maximum(180);
converter.convert('altitude').optional().toFloat().minimum(0);

const params = await converter.validate();
const site = await model.sites.find({ external_id: req.params.externalId }).get(0);
if (!site) {
// TODO request site from CORE API if not found
throw new EmptyResultError('Site with given external_id not found.');
}
const project = await model.projects.find({id: site.project_id}).get(0);
const projectUsers = await model.projects.getUsersAsync(project.project_id);
const hasPermission = !!projectUsers.find(x => x.id === user.user_id);
if (!hasPermission) {
throw new ForbiddenError(`You don't have permission to manage project sites`);
}
await model.sites.updateAsync({
site_id: site.site_id,
name: params.name,
lat: params.latitude,
lon: params.longitude,
alt: params.altitude
})
res.sendStatus(200);
} catch (e) {
httpErrorHandler(req, res, 'Failed updating a site')(e);
}
})

router.post('/recordings/create', verifyToken(), hasRole(['systemUser']), async function(req, res) {
try {
const convertedParams = {};
Expand Down

0 comments on commit 56426d0

Please sign in to comment.