Skip to content

Commit

Permalink
Include section information in API response
Browse files Browse the repository at this point in the history
Centralize information
  • Loading branch information
danielfdsilva committed Sep 11, 2018
1 parent 7c3f173 commit 2a19bae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/routes/projects--source-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ProjectStatusError
} from '../utils/errors';
import { parseFormData, getPropInsensitive } from '../utils/utils';
import { getOSRMProfileDefaultSpeedSettings, renderProfileFile } from '../utils/osrm-profile';
import { getOSRMProfileDefaultSpeedSettings, renderProfileFile, getOSRMProfileDefaultSpeedMeta } from '../utils/osrm-profile';

const profileValidationSchema = Object.keys(getOSRMProfileDefaultSpeedSettings())
.reduce((acc, setting) => {
Expand Down Expand Up @@ -243,7 +243,10 @@ export default [
.where('name', 'profile')
.first();

return reply(sourceData.data.settings);
return reply({
sections: getOSRMProfileDefaultSpeedMeta(),
settings: sourceData.data.settings
});
} catch (err) {
console.log('err', err);
return reply(Boom.badImplementation(err));
Expand Down
18 changes: 18 additions & 0 deletions app/utils/osrm-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ export function toLua (element) {
}
}

// How the profile edit works:
// Section are gorups of speeds that can be edited (ex: "Surface Speeds",
// "Tracktype Speeds", "Smoothness Speeds", etc) These are required by the api
// and defined on the server alongside the labels.
// A section can have the `multi` flag set, which means that two levels are
// allowed.

export function getOSRMProfileDefaultSpeedMeta () {
return [
{ key: 'speed_profile', label: 'Speeds' },
{ key: 'surface_speeds', label: 'Surface Speeds' },
{ key: 'tracktype_speeds', label: 'Tracktype Speeds' },
{ key: 'smoothness_speeds', label: 'Smoothness Speeds' },
{ key: 'maxspeed_table_default', label: 'Maxspeed Default' },
{ key: 'maxspeed_table', label: 'Maxspeed' }
];
}

export function getOSRMProfileDefaultSpeedSettings () {
return {
speed_profile: {
Expand Down
7 changes: 5 additions & 2 deletions test/test-projects-source-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import db from '../app/db';
import { setupStructure as setupDdStructure } from '../app/db/structure';
import { setupStructure as setupStorageStructure } from '../app/s3/structure';
import { fixMeUp } from './utils/data';
import { getOSRMProfileDefaultSpeedSettings, toLua } from '../app/utils/osrm-profile';
import { getOSRMProfileDefaultSpeedSettings, toLua, getOSRMProfileDefaultSpeedMeta } from '../app/utils/osrm-profile';

var options = {
connection: {port: 2000, host: '0.0.0.0'}
Expand Down Expand Up @@ -509,7 +509,10 @@ describe('Projects source data', function () {
}).then(res => {
assert.equal(res.statusCode, 200, 'Status code is 200');
var result = res.result;
assert.deepEqual(result, getOSRMProfileDefaultSpeedSettings());
assert.deepEqual(result, {
sections: getOSRMProfileDefaultSpeedMeta(),
settings: getOSRMProfileDefaultSpeedSettings()
});
});
});
});
Expand Down

0 comments on commit 2a19bae

Please sign in to comment.