case 'create_store':
if(isLoggedIn(ws)) {
if(is(ws, 'god')) {
try {//country match to currency abbreviation?
let fuck = await googleMapsClient.geocode({address: `${parameters.address}, ${parameters.address2}, ${parameters.city}, ${parameters.region}, ${parameters.country}, ${parameters.postal_code}`}).asPromise();
if(fuck.status === 200 && fuck.json.status === 'OK') {
let x = fuck.json.results[0].geometry.location.lat;
let y = fuck.json.results[0].geometry.location.lng;
let fuck2 = await googleMapsClient.timezone({location: fuck.json.results[0].geometry.location}).asPromise();
if(fuck2.status === 200) {
fuck2.json.timeZoneId
//how to determine if store is open?
//also find timezone with api, modify time X because https://stackoverflow.com/questions/40246420/postgresql-handling-of-full-time-zones-for-timetz-data-type
// let store = await pool.query('insert into stores values ($1, $2, $3, $4, $5, $6, $7, $8, $9, point($10, $11), $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26) returning id', [parameters.name, parameters.URL, parameters.address, parameters.address2, parameters.city, parameters.region, parameters.country, parameters.postal_code, parameters.currency_abbreviation, x, y, parameters.monday_open, parameters.monday_close, parameters.tuesday_open, parameters.tuesday_close, parameters.wednesday_open, parameters.wednesday_close, parameters.thursday_open, parameters.thursday_close, parameters.friday_open, parameters.friday_close, parameters.saturday_open, parameters.saturday_close, parameters.sunday_open, parameters.sunday_close]);
// if(Array.isArray(parameters.tax) && parameters.tax.length) {
// let query = 'insert into tax_store values ';
// let params = [];
// for(let i = 0; i < parameters.tax.length; ++i) {
// query += `($${i * 3 + 1}, $${i * 3 + 2}, $${i * 3 + 3}),`;
// params.push(store.rows[0].id);
// params.push(parameters.tax[i].name);
// params.push(parameters.tax[i].tax);
// }
// await pool.query(query.slice(0, -1), params);
// }
ws.send(JSON.stringify({
response_ID: request_ID
}));
//ws.publish(store.rows[0].id)
} else {
throw 'timezone fuckup';
}
} else {
throw 'geocode fuckup';
}
} catch(e) {
let error = 'store already exists';
if(e.constraint !== 'store_url_key') {
console.error(e);
error = 'error';
}
ws.send(JSON.stringify({
response_ID: request_ID,
data: error
}));
}
} else {
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'forbidden'
}));
}
} else {
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'unauthorized'
}));
}
break;