You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
const pg = require('../pg')
|
|
const joinjs = require('join-js').default;
|
|
const debug = require('debug')('sos:db:order')
|
|
const mappings = require('../mappings')
|
|
|
|
const order = module.exports = {}
|
|
|
|
order.create = async function(cart_uuid){
|
|
const query = {
|
|
text: 'select * from sos.create_order($1)',
|
|
values: [cart_uuid]
|
|
}
|
|
|
|
debug(query);
|
|
|
|
const {rows} = await pg.query(query)
|
|
return joinjs.map(rows, mappings, 'orderMap', 'order_')[0];
|
|
}
|
|
|
|
order.findForCart = async function(cart_uuid) {
|
|
const query = {
|
|
text: 'select * from sos.find_order_for_cart($1)',
|
|
values: [cart_uuid]
|
|
}
|
|
|
|
debug(query)
|
|
|
|
const {rows} = await pg.query(query)
|
|
return joinjs.map(rows, mappings, 'orderMap', 'order_')[0];
|
|
}
|
|
|
|
|
|
order.addAddress = async function (order_uuid, address_uuid){
|
|
const query = {
|
|
text: 'select * from sos.add_address_to_order($1, $2)',
|
|
values: [order_uuid, address_uuid]
|
|
}
|
|
|
|
debug(query)
|
|
|
|
// TODO: Update shipping and tax
|
|
|
|
const {rows} = await pg.query(query)
|
|
return joinjs.map(rows, mappings, 'orderMap', 'order_')[0];
|
|
}
|