feat: use more default values

This commit is contained in:
Riccardo Senica
2025-01-21 05:36:43 +00:00
parent 26cfc526d1
commit 6589e8a815
4 changed files with 13 additions and 10 deletions

View File

@@ -17,3 +17,4 @@ POSTGRES_USER=
RECIPIENT_EMAIL=
RESEND_API_KEY=
SENDER_EMAIL=
DEFAULT_CATEGORY=

View File

@@ -4,6 +4,10 @@ import { NextResponse } from 'next/server';
export async function POST(req: Request) {
try {
if(!process.env.API_KEY){
throw new Error('API KEY environment variable is not set')
}
const body = await req.json();
const result = RequestSchema.safeParse(body);

View File

@@ -25,7 +25,7 @@ export async function diaryCommand(
if (!parameters || !parameters['instruction']) {
return {
success: false,
message: 'Message parameter is missing.'
message: 'Instruction parameter is missing.'
};
}
@@ -36,17 +36,15 @@ export async function diaryCommand(
switch (parsedCommand.command) {
case 'add': {
if (!parsedCommand.flags.cat) {
return {
success: false,
message: 'Category is required'
};
const categoryName = (parsedCommand.flags.cat as string) || process.env.DEFAULT_CATEGORY
if(!categoryName){
throw new Error('DEFAULT_CATEGORY environment variable is not set')
}
const expense = await createExpense({
description: parsedCommand.flags.desc as string,
cost: parsedCommand.flags.cost as number,
categoryName: parsedCommand.flags.cat as string
categoryName
});
const formatted = formatResponse(expense);
@@ -102,7 +100,7 @@ export async function diaryCommand(
try {
const reporter = new ExpenseReporter();
const from = parsedCommand.flags.from as Date;
const to = parsedCommand.flags.to as Date;
const to = (parsedCommand.flags.to as Date) || new Date();
const includeJson = (parsedCommand.flags.export as boolean) || false;
await reporter.sendReport(from, to, includeJson);

View File

@@ -134,7 +134,7 @@ export const diaryCommands: CommandDefinition[] = [
name: 'report',
flags: [
{ name: 'from', type: 'date', required: true },
{ name: 'to', type: 'date', required: true },
{ name: 'to', type: 'date', required: false },
{ name: 'export', type: 'boolean', required: false }
]
},