Path: blob/master/src/packages/next/pages/api/v2/compute/delete-server.ts
1452 views
/*1Delete a compute server. This deprovisions the VM and sets the2deleted flag on the compute server entry in the database.3*/45import getAccountId from "lib/account/get-account";6import deleteServer from "@cocalc/server/compute/delete-server";7import getParams from "lib/api/get-params";89import { apiRoute, apiRouteOperation } from "lib/api";10import { OkStatus } from "lib/api/status";11import {12DeleteComputeServerInputSchema,13DeleteComputeServerOutputSchema,14} from "lib/api/schema/compute/delete-server";1516async function handle(req, res) {17try {18res.json(await get(req));19} catch (err) {20res.json({ error: `${err.message}` });21return;22}23}2425async function get(req) {26const account_id = await getAccountId(req);27if (!account_id) {28throw Error("must be signed in");29}30const { id } = getParams(req);31await deleteServer({32account_id,33id,34});35return OkStatus;36}3738export default apiRoute({39deleteServer: apiRouteOperation({40method: "POST",41openApiOperation: {42tags: ["Compute"],43},44})45.input({46contentType: "application/json",47body: DeleteComputeServerInputSchema,48})49.outputs([50{51status: 200,52contentType: "application/json",53body: DeleteComputeServerOutputSchema,54},55])56.handler(handle),57});585960