update-purchase.tool.ts•1.46 kB
import { updateQuickbooksPurchase } from "../handlers/update-quickbooks-purchase.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
// Define the tool metadata
const toolName = "update_purchase";
const toolTitle = "Update Purchase";
const toolDescription = "Update a purchase in QuickBooks Online.";
// Define the expected input schema for updating a purchase
const inputSchema = {
purchase: 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 updateQuickbooksPurchase(params.purchase);
if (response.isError) {
return {
content: [
{ type: "text" as const, text: `Error updating purchase: ${response.error}` },
],
};
}
return {
content: [
{ type: "text" as const, text: `Purchase updated:` },
{ type: "text" as const, text: JSON.stringify(response.result) },
],
};
};
export const UpdatePurchaseTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};