"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*
API endpoint to stop a project running.

This requires the user to be signed in so they are allowed to use this project.
*/
const get_account_1 = __importDefault(require("lib/account/get-account"));
const control_1 = require("@cocalc/server/projects/control");
const misc_1 = require("@cocalc/util/misc");
const is_collaborator_1 = __importDefault(require("@cocalc/server/projects/is-collaborator"));
const get_params_1 = __importDefault(require("lib/api/get-params"));
async function handle(req, res) {
    const account_id = await (0, get_account_1.default)(req);
    const { project_id } = (0, get_params_1.default)(req);
    try {
        if (!(0, misc_1.isValidUUID)(project_id)) {
            throw Error("project_id must be a valid uuid");
        }
        if (!account_id) {
            throw Error("must be signed in");
        }
        if (!(0, is_collaborator_1.default)({ account_id, project_id })) {
            throw Error("must be a collaborator to stop project");
        }
        const project = (0, control_1.getProject)(project_id);
        await project.stop();
        res.json({});
    }
    catch (err) {
        res.json({ error: err.message });
    }
}
exports.default = handle;
//# sourceMappingURL=stop.js.map