feat: expenses, report and day log commands

This commit is contained in:
2025-01-18 21:21:26 +01:00
parent a28d392342
commit 8681914be2
30 changed files with 5614 additions and 1 deletions

58
utils/handler.ts Normal file
View File

@@ -0,0 +1,58 @@
import { ShortcutsRequest, ShortcutsResponse } from './types';
import { CommandRegistry } from './registry';
export class ShortcutsHandler {
private registry: CommandRegistry;
constructor() {
this.registry = new CommandRegistry();
}
validateRequest(req: ShortcutsRequest): boolean {
try {
const isValidUser = req.apiKey === process.env.API_KEY;
return !!isValidUser;
} catch (error) {
console.error('Error validating request:', error);
return false;
}
}
async processCommand(
command: string,
parameters?: Record<string, string>
): Promise<ShortcutsResponse> {
if (command === 'expense') {
const handler = this.registry.getCommand(command);
if (!handler) {
return {
success: false,
message: `Unknown command: ${command}`
};
}
return handler(parameters);
}
const handler = this.registry.getCommand(command);
if (!handler) {
return {
success: false,
message: `Unknown command: ${command}`
};
}
try {
return await handler(parameters);
} catch (error) {
console.error(`Error processing command ${command}:`, error);
return {
success: false,
message:
error instanceof Error
? error.message
: 'An error occurred while processing your command'
};
}
}
}