36 lines
807 B
JavaScript
36 lines
807 B
JavaScript
|
import * as Kinto from 'kinto';
|
||
|
|
||
|
const DB = new Kinto({
|
||
|
bucket: 'magellan'
|
||
|
});
|
||
|
|
||
|
const LOCATIONS = DB.collection('locations');
|
||
|
|
||
|
const syncOptions = { remote: 'https://kinto.b.delire.party/v1' };
|
||
|
|
||
|
export async function getAll() {
|
||
|
let locations = await LOCATIONS.list();
|
||
|
return locations.data;
|
||
|
}
|
||
|
|
||
|
function checkNotMissing(obj, field) {
|
||
|
if (typeof obj[field] === 'undefined') {
|
||
|
console.warn(`missing field ${field} on object in ${new Error().stack}`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export async function create(loc) {
|
||
|
checkNotMissing(loc, 'label');
|
||
|
checkNotMissing(loc, 'coordinates');
|
||
|
|
||
|
let result = await LOCATIONS.create({
|
||
|
label: loc.label,
|
||
|
coordinates: loc.coordinates,
|
||
|
});
|
||
|
return result.data;
|
||
|
}
|
||
|
|
||
|
export async function sync() {
|
||
|
await LOCATIONS.sync(syncOptions);
|
||
|
}
|