"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 create a new project.

This requires the user to be signed in so they are allowed to create a project.
*/
const get_account_1 = __importDefault(require("lib/account/get-account"));
const create_1 = __importDefault(require("@cocalc/server/projects/create"));
const get_params_1 = __importDefault(require("lib/api/get-params"));
async function handle(req, res) {
    const { title, description, image, license, public_path_id } = (0, get_params_1.default)(req);
    const account_id = await (0, get_account_1.default)(req);
    try {
        const project_id = await createProject(account_id, title, description, image, license, public_path_id);
        res.json({ project_id });
    }
    catch (err) {
        res.json({ error: err.message });
    }
}
exports.default = handle;
async function createProject(account_id, title, description, image, license, public_path_id) {
    if (!account_id) {
        throw Error("user must be signed in");
    }
    if (!title) {
        throw Error("project title is required");
    }
    return await (0, create_1.default)({
        account_id,
        title,
        description,
        image,
        license,
        public_path_id,
    });
}
//# sourceMappingURL=create.js.map