@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
28 lines (27 loc) • 1.22 kB
JavaScript
;
/*
Delete an item from the given user's shopping cart. Item must be not be
already bought, but it can be "saved for later". This is different than
just removing it, which saves it for later.
This really deletes the item from the cart, leaving no trace in the database.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const misc_1 = require("@cocalc/util/misc");
const pool_1 = __importDefault(require("@cocalc/database/pool"));
// we include the account_id to ensure here and in the query below
// to ensure there is an error if user A tries to delete an item
// from user B's shopping cart.
// Returns number of items "deleted".
async function deleteItem(account_id, id) {
if (!(0, misc_1.isValidUUID)(account_id)) {
throw Error("account_id is invalid");
}
const pool = (0, pool_1.default)();
const { rowCount } = await pool.query("DELETE FROM shopping_cart_items WHERE account_id=$1 AND id=$2 AND purchased IS NULL", [account_id, id]);
return rowCount;
}
exports.default = deleteItem;
//# sourceMappingURL=delete.js.map