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