db-vendo-client/p/dbnav/nearby-req.js
2024-12-21 23:04:05 +00:00

29 lines
686 B
JavaScript

import {getHeaders} from './header.js';
const formatNearbyReq = (ctx, location) => {
const {profile, opt} = ctx;
if (opt.distance > 10000) {
throw new Error('maximum supported distance by this endpoint is 10000');
}
// TODO location types
return {
endpoint: profile.nearbyEndpoint,
body: {
area: {
coordinates: {
longitude: location.longitude,
latitude: location.latitude,
},
radius: opt.distance || 10000,
},
maxResults: opt.results,
products: profile.formatProductsFilter(ctx, opt.products || {}, 'dbnav'),
},
headers: getHeaders('application/x.db.vendo.mob.location.v3+json'),
method: 'post',
};
};
export {
formatNearbyReq,
};