-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add cancel command to CLI #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { eq } from "drizzle-orm"; | ||
| import { db } from "../db"; | ||
| import { type Intent, intents } from "../db/schema"; | ||
| import { findActiveIntent } from "./findActiveIntent"; | ||
|
|
||
| export async function cancel({ | ||
| branchId, | ||
| }: { | ||
| branchId: string; | ||
| }): Promise<Intent> { | ||
| try { | ||
| const activeIntent = await findActiveIntent({ branchId }); | ||
|
|
||
| if (!activeIntent) { | ||
| throw new Error("No active intent found for this branch"); | ||
| } | ||
|
|
||
| return db | ||
| .update(intents) | ||
| .set({ | ||
| status: "cancelled", | ||
| }) | ||
| .where(eq(intents.id, activeIntent.id)) | ||
| .returning() | ||
| .get(); | ||
| } catch (error) { | ||
| console.error("Failed to cancel intent: ", error); | ||
| throw new Error( | ||
| `Failed to cancel intent: ${error instanceof Error ? error.message : "Unknown error"}`, | ||
| ); | ||
| } | ||
| } | ||
|
Comment on lines
+6
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
By removing the export async function cancel({
branchId,
}: {
branchId: string;
}): Promise<Intent> {
const activeIntent = await findActiveIntent({ branchId });
if (!activeIntent) {
throw new Error("No active intent found for this branch");
}
return db
.update(intents)
.set({
status: "cancelled",
})
.where(eq(intents.id, activeIntent.id))
.returning()
.get();
} |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from "./cancel"; | ||
| export * from "./findActiveIntent"; | ||
| export * from "./finish"; | ||
| export * from "./list"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status
"cancelled"is hardcoded here. The database schema (src/core/db/schema.ts) refers to anINTENT_STATUSconstant for thestatuscolumn, which suggests a centralized place for these values. Using a hardcoded string here can lead to inconsistencies and maintenance issues if the status values ever change.To improve maintainability and type safety, it would be better to use a shared constant or enum for intent statuses throughout the application, instead of raw strings. This would apply here and in other places like
findActiveIntent.ts.