@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
27 lines • 1.2 kB
JavaScript
;
/*
Remove an item from the given user's shopping cart.
*/
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 "removed", which on success is 0 or 1.
// 0 - item with that id wasn't in the cart
// 1 - item was changed.
// You can't remove an item more than once from a cart.
async function removeFromCart(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("UPDATE shopping_cart_items SET removed=NOW() WHERE account_id=$1 AND id=$2 AND removed IS NULL AND purchased IS NULL", [account_id, id]);
return rowCount;
}
exports.default = removeFromCart;
//# sourceMappingURL=remove.js.map