UNPKG

@cocalc/database

Version:

CoCalc: code for working with our PostgreSQL database

37 lines 1.41 kB
"use strict"; /* * This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ Object.defineProperty(exports, "__esModule", { value: true }); exports.record_user_tracking = void 0; const misc_1 = require("@cocalc/util/misc"); const async_utils_1 = require("@cocalc/util/async-utils"); async function record_user_tracking(db, account_id, event, value) { /* Right now this function is called from outside typescript (e.g., api from user), so we have to do extra type checking. Also, the input is uuid's, which typescript can't check. */ if (!(0, misc_1.is_valid_uuid_string)(account_id)) { throw Error("invalid account_id"); } if (event == null || event.length == 0) { throw Error("evt must be specified"); } if (event.length > 80) { throw Error("event must have length at most 80"); } if (value == null) { throw Error("value must be specified"); } await (0, async_utils_1.callback2)(db._query, { query: "INSERT INTO user_tracking", values: { "account_id :: UUID": account_id, "time :: TIMESTAMP": "NOW()", "event :: TEXT": event, "value :: JSONB": value, }, }); } exports.record_user_tracking = record_user_tracking; //# sourceMappingURL=user-tracking.js.map