server/cli/user/delete.ts
Jesse Wierzbinski 6056a6622c
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 1s
Build Docker Images / lint (push) Failing after 7s
Build Docker Images / check (push) Failing after 7s
Build Docker Images / tests (push) Failing after 7s
Build Docker Images / detect-circular (push) Failing after 7s
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 0s
Test Publish / build (client) (push) Failing after 0s
Test Publish / build (sdk) (push) Failing after 0s
refactor(database): ♻️ Use dates instead of strings in database
2025-12-11 04:03:57 +01:00

60 lines
1.8 KiB
TypeScript

import { defineCommand } from "@clerc/core";
import confirm from "@inquirer/confirm";
import chalk from "chalk";
import { retrieveUser } from "../utils.ts";
export const deleteUserCommand = defineCommand({
name: "user delete",
alias: "user rm",
description: "Delete a user from the database. Can use username or handle.",
parameters: ["<username_or_handle>"],
flags: {
confirm: {
description: "Ask for confirmation before deleting the user",
type: Boolean,
alias: "c",
default: true,
},
},
handler: async (context) => {
const { confirm: confirmFlag } = context.flags;
const { username_or_handle } = context.parameters;
const user = await retrieveUser(username_or_handle);
if (!user) {
throw new Error(
`User ${chalk.gray(username_or_handle)} not found.`,
);
}
console.info(`About to delete user ${chalk.gray(user.data.username)}!`);
console.info(`Username: ${chalk.blue(user.data.username)}`);
console.info(`Display Name: ${chalk.blue(user.data.displayName)}`);
console.info(
`Created At: ${chalk.blue(user.data.createdAt.toISOString())}`,
);
console.info(
`Instance: ${chalk.blue(user.data.instance?.baseUrl || "Local")}`,
);
if (confirmFlag) {
const choice = await confirm({
message: `Are you sure you want to delete this user? ${chalk.red(
"This is irreversible.",
)}`,
});
if (!choice) {
throw new Error("Operation aborted.");
}
}
await user.delete();
console.info(
`User ${chalk.gray(user.data.username)} has been deleted.`,
);
},
});