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

@@ -16,4 +16,5 @@ POSTGRES_URL_NO_SSL=
POSTGRES_USER= POSTGRES_USER=
RECIPIENT_EMAIL= RECIPIENT_EMAIL=
RESEND_API_KEY= RESEND_API_KEY=
SENDER_EMAIL= SENDER_EMAIL=
DEFAULT_CATEGORY=

View File

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

View File

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

View File

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