@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
31 lines • 1.38 kB
JavaScript
;
/*
Get shopping cart items. By default gets the current shopping cart,
but you can also get all items that have been removed from the cart,
and also all items that were purchased.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getItem = void 0;
const misc_1 = require("@cocalc/util/misc");
const pool_1 = __importDefault(require("@cocalc/database/pool"));
async function getCart({ account_id, purchased, removed, }) {
(0, misc_1.assertValidAccountID)(account_id);
const pool = (0, pool_1.default)();
const { rows } = await pool.query(`SELECT * FROM shopping_cart_items WHERE account_id=$1 AND purchased IS ${purchased ? " NOT " : ""} NULL AND removed IS ${removed ? " NOT " : ""} NULL ORDER BY id DESC`, [account_id]);
return rows;
}
exports.default = getCart;
async function getItem({ account_id, id, }) {
(0, misc_1.assertValidAccountID)(account_id);
const pool = (0, pool_1.default)();
const { rows } = await pool.query("SELECT * FROM shopping_cart_items WHERE account_id=$1 AND id=$2", [account_id, id]);
if (rows.length == 0) {
throw Error(`no item with id ${id}`);
}
return rows[0];
}
exports.getItem = getItem;
//# sourceMappingURL=get.js.map