update-journal-entry.tool.ts•1.51 kB
import { updateQuickbooksJournalEntry } from "../handlers/update-quickbooks-journal-entry.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
// Define the tool metadata
const toolName = "update_journal_entry";
const toolTitle = "Update Journal Entry";
const toolDescription = "Update a journal entry in QuickBooks Online.";
// Define the expected input schema for updating a journal entry
const inputSchema = {
journalEntry: z.any(),
};
const outputSchema = {
success: z.boolean().describe("Whether the operation was successful"),
data: z.any().optional().describe("The result data"),
error: z.string().optional().describe("Error message if operation failed"),
};
// Define the tool handler
const toolHandler = async (params: z.infer<z.ZodObject<typeof inputSchema>>) => {
const response = await updateQuickbooksJournalEntry(params.journalEntry);
if (response.isError) {
return {
content: [
{ type: "text" as const, text: `Error updating journal entry: ${response.error}` },
],
};
}
return {
content: [
{ type: "text" as const, text: `Journal entry updated:` },
{ type: "text" as const, text: JSON.stringify(response.result) },
],
};
};
export const UpdateJournalEntryTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};