Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/projects/delete.ts
5796 views
1
/*
2
API endpoint to delete a project, which sets the "delete" flag to `true` in the database.
3
*/
4
import deleteProject from "@cocalc/server/projects/delete";
5
import getAccountId from "lib/account/get-account";
6
import getParams from "lib/api/get-params";
7
import { apiRoute, apiRouteOperation } from "lib/api";
8
import { OkStatus } from "lib/api/status";
9
import {
10
DeleteProjectInputSchema,
11
DeleteProjectOutputSchema,
12
} from "lib/api/schema/projects/delete";
13
14
async function handle(req, res) {
15
const { project_id } = getParams(req);
16
const account_id = await getAccountId(req);
17
18
try {
19
if (!account_id) {
20
throw Error("must be signed in");
21
}
22
23
await deleteProject({ account_id, project_id });
24
res.json(OkStatus);
25
} catch (err) {
26
res.json({ error: err.message });
27
}
28
}
29
30
export default apiRoute({
31
deleteProject: apiRouteOperation({
32
method: "POST",
33
openApiOperation: {
34
tags: ["Projects", "Admin"],
35
},
36
})
37
.input({
38
contentType: "application/json",
39
body: DeleteProjectInputSchema,
40
})
41
.outputs([
42
{
43
status: 200,
44
contentType: "application/json",
45
body: DeleteProjectOutputSchema,
46
},
47
])
48
.handler(handle),
49
});
50
51