Add Note delete command to CLI

This commit is contained in:
Jesse Wierzbinski 2023-11-29 09:08:09 -10:00
parent a92b45da41
commit 128827cee4
No known key found for this signature in database

36
cli.ts
View file

@ -68,6 +68,11 @@ ${chalk.bold("Commands:")}
`bun cli user search admin` `bun cli user search admin`
)} )}
${alignDots(chalk.blue("note"), 24)} Manage notes ${alignDots(chalk.blue("note"), 24)} Manage notes
${alignDots(chalk.blue("delete"))} Delete a note
${alignDotsSmall(chalk.green("id"))} ID of the note
${chalk.bold("Example:")} ${chalk.bgGray(
`bun cli note delete 018c1838-6e0b-73c4-a157-a91ea4e25d1d`
)}
${alignDots(chalk.blue("search"))} Search for a status ${alignDots(chalk.blue("search"))} Search for a status
${alignDotsSmall(chalk.green("query"))} Query to search for ${alignDotsSmall(chalk.green("query"))} Query to search for
${alignDotsSmall( ${alignDotsSmall(
@ -352,6 +357,37 @@ switch (command) {
break; break;
case "note": { case "note": {
switch (args[3]) { switch (args[3]) {
case "delete": {
const id = args[4];
if (!id) {
console.log(`${chalk.red(``)} Missing ID`);
process.exit(1);
}
const note = await client.status.findFirst({
where: {
id: id,
},
});
if (!note) {
console.log(`${chalk.red(``)} Note not found`);
process.exit(1);
}
await client.status.delete({
where: {
id: note.id,
},
});
console.log(
`${chalk.green(``)} Deleted note ${chalk.blue(note.id)}`
);
break;
}
case "search": { case "search": {
const argsWithoutFlags = args.filter( const argsWithoutFlags = args.filter(
arg => !arg.startsWith("--") arg => !arg.startsWith("--")