@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
42 lines • 1.43 kB
JavaScript
;
/*
Edit an item in the 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"));
async function editCart({ account_id, id, product, description, }) {
if (!(0, misc_1.isValidUUID)(account_id)) {
throw Error("account_id is invalid");
}
const pool = (0, pool_1.default)();
let query;
const params = [account_id, id];
if (product && description) {
query =
"UPDATE shopping_cart_items SET product=$3, description=$4 WHERE account_id=$1 AND id=$2";
params.push(product);
params.push(description);
}
else if (product) {
query =
"UPDATE shopping_cart_items SET product=$3 WHERE account_id=$1 AND id=$2";
params.push(product);
}
else if (description) {
query =
"UPDATE shopping_cart_items SET description=$3 WHERE account_id=$1 AND id=$2";
params.push(description);
}
else {
return 0; //nothing to change
}
query += " AND purchased IS NULL";
const { rowCount } = await pool.query(query, params);
return rowCount;
}
exports.default = editCart;
//# sourceMappingURL=edit.js.map