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

50
app/api/command/route.ts Normal file
View File

@@ -0,0 +1,50 @@
import { ShortcutsHandler } from '@utils/handler';
import { RequestSchema } from '@utils/types';
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
try {
const body = await req.json();
const result = RequestSchema.safeParse(body);
if (!result.success) {
return NextResponse.json(
{
success: false,
message: 'Invalid request format.',
errors: result.error.errors
},
{ status: 400 }
);
}
const shortcutsHandler = new ShortcutsHandler();
const isValid = shortcutsHandler.validateRequest(result.data);
if (!isValid) {
return NextResponse.json(
{
success: false,
message: 'Unauthorized.'
},
{ status: 401 }
);
}
const response = await shortcutsHandler.processCommand(
result.data.command,
result.data.parameters
);
return NextResponse.json(response);
} catch (error) {
console.error('Error processing shortcuts request:', error);
return NextResponse.json(
{
success: false,
message: 'An error occurred while processing your request.'
},
{ status: 500 }
);
}
}