UNPKG

@cocalc/server

Version:

CoCalc server functionality: functions used by either the hub and the next.js server

29 lines (28 loc) 1.4 kB
"use strict"; /* Get items that you recently purchased. This is used for congratulating you, providing links, etc. We don't just give the last purchase so things are more stateless, and so for now more than one item in the cart can be handled as multiple purchases. Also, it seems generally useful to see all your recent purchases. The client can sort from oldest to newest and clearly display the most recent in a separate group. */ 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")); const misc_2 = require("@cocalc/util/misc"); async function getRecentPurchases({ account_id, recent, }) { if (!(0, misc_1.isValidUUID)(account_id)) { throw Error("account_id is invalid"); } const pool = (0, pool_1.default)(); const { rows } = await pool.query(`SELECT * FROM shopping_cart_items WHERE account_id=$1 AND purchased IS NOT NULL AND (purchased#>>'{time}')::timestamptz >= NOW() - $2::interval`, [account_id, recent ?? "1 week"]); rows.sort((a, b) => -(0, misc_2.cmp)(a.purchased?.time, b.purchased?.time)); return rows; } exports.default = getRecentPurchases; //# sourceMappingURL=recent-purchases.js.map