Path: blob/master/src/packages/next/pages/api/v2/licenses/get-projects-with-license.ts
1452 views
/*1Get all projects that have a given license applied to them. Signed in user2must be a manager of the given license so they are allowed access to this data.34See docs in @cocalc/server/licenses/get-projects-with-license.ts56Returns [Project1, Project2, ...] on success or {error:'a message'} on failure.7For the fields in the projects, see @cocalc/server/licenses/get-projects.ts8*/910import getProjectsWithLicense, {11Project,12} from "@cocalc/server/licenses/get-projects-with-license";13import { isManager } from "@cocalc/server/licenses/get-license";14import getAccountId from "lib/account/get-account";15import getParams from "lib/api/get-params";16import { isValidUUID } from "@cocalc/util/misc";1718export default async function handle(req, res) {19try {20res.json(await get(req));21} catch (err) {22res.json({ error: `${err.message}` });23return;24}25}2627async function get(req): Promise<Project[]> {28const account_id = await getAccountId(req);29if (account_id == null) {30throw Error("must be signed in as a manager of the license");31}32const { license_id } = getParams(req);33if (!isValidUUID(license_id)) {34throw Error("license_id must be a valid uuid");35}36if (!(await isManager(license_id, account_id))) {37throw Error("signed in user must be a manager of the license");38}39return await getProjectsWithLicense(license_id);40}414243