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.
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
const pg = require('../pg')
|
|
const joinjs = require('join-js').default;
|
|
const debug = require('debug')('sos:db:cart')
|
|
const mappings = require('../mappings')
|
|
|
|
const cart = module.exports = {}
|
|
|
|
cart.create = async session_uuid => {
|
|
const query = {
|
|
text: 'select * from sos.create_cart($1)',
|
|
values: [
|
|
session_uuid
|
|
]
|
|
}
|
|
|
|
debug(query);
|
|
|
|
const {rows} = await pg.query(query)
|
|
return joinjs.map(rows, mappings, 'cartMap', 'cart_')[0];
|
|
}
|
|
|
|
cart.addItemToCart = async (cart_uuid, item_uuid, amount) => {
|
|
const query = {
|
|
text: 'select * from sos.add_item_to_cart($1, $2, $3)',
|
|
values: [
|
|
cart_uuid,
|
|
item_uuid,
|
|
amount
|
|
]
|
|
}
|
|
|
|
debug(query);
|
|
|
|
const {rows} = await pg.query(query)
|
|
return joinjs.map(rows, mappings, 'cartMap', 'cart_')[0];
|
|
}
|
|
|
|
cart.removeItemFromCart = async (cart_uuid, item_uuid, amount) => {
|
|
const query = {
|
|
text: 'select * from sos.remove_item_from_cart($1, $2, $3)',
|
|
values: [
|
|
cart_uuid,
|
|
item_uuid,
|
|
amount
|
|
]
|
|
}
|
|
|
|
debug(query);
|
|
|
|
const {rows} = await pg.query(query)
|
|
return joinjs.map(rows, mappings, 'cartMap', 'cart_')[0];
|
|
}
|