feat: add -date flag
This commit is contained in:
@@ -5,7 +5,7 @@ import { NextResponse } from 'next/server';
|
|||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
try {
|
try {
|
||||||
if (!process.env.API_KEY) {
|
if (!process.env.API_KEY) {
|
||||||
throw new Error('API KEY environment variable is not set')
|
throw new Error('API KEY environment variable is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
|
|||||||
@@ -36,14 +36,16 @@ export async function diaryCommand(
|
|||||||
|
|
||||||
switch (parsedCommand.command) {
|
switch (parsedCommand.command) {
|
||||||
case 'add': {
|
case 'add': {
|
||||||
const categoryName = (parsedCommand.flags.cat as string) || process.env.DEFAULT_CATEGORY
|
const categoryName =
|
||||||
|
(parsedCommand.flags.cat as string) || process.env.DEFAULT_CATEGORY;
|
||||||
if (!categoryName) {
|
if (!categoryName) {
|
||||||
throw new Error('DEFAULT_CATEGORY environment variable is not set')
|
throw new Error('DEFAULT_CATEGORY environment variable is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
date: (parsedCommand.flags.date as Date) || new Date(),
|
||||||
categoryName
|
categoryName
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ export const diaryCommands: CommandDefinition[] = [
|
|||||||
flags: [
|
flags: [
|
||||||
{ name: 'desc', type: 'string', required: true },
|
{ name: 'desc', type: 'string', required: true },
|
||||||
{ name: 'cost', type: 'number', required: true },
|
{ name: 'cost', type: 'number', required: true },
|
||||||
{ name: 'cat', type: 'string', required: false }
|
{ name: 'cat', type: 'string', required: false },
|
||||||
|
{ name: 'date', type: 'date', required: false }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export const createExpense = async (data: ExpenseType) => {
|
|||||||
data: {
|
data: {
|
||||||
description: data.description,
|
description: data.description,
|
||||||
cost: data.cost,
|
cost: data.cost,
|
||||||
|
createdAt: data.date,
|
||||||
categoryId: category.id,
|
categoryId: category.id,
|
||||||
deleted: false
|
deleted: false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ export interface ShortcutsResponse {
|
|||||||
const ExpenseSchema = z.object({
|
const ExpenseSchema = z.object({
|
||||||
description: z.string().min(1),
|
description: z.string().min(1),
|
||||||
cost: z.number().positive(),
|
cost: z.number().positive(),
|
||||||
categoryName: z.string()
|
categoryName: z.string(),
|
||||||
|
date: z.date()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ExpenseType = z.infer<typeof ExpenseSchema>;
|
export type ExpenseType = z.infer<typeof ExpenseSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user