feat(budget): aylık bütçe motoru, limitler ve ay sonu tahmini
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { z } from "zod";
|
||||
import { tr } from "../../i18n/tr";
|
||||
import { nonNegativeMoneySchema } from "./account";
|
||||
|
||||
/** Bütçe ayı "YYYY-MM". */
|
||||
export const budgetMonthSchema = z
|
||||
.string()
|
||||
.regex(/^\d{4}-(0[1-9]|1[0-2])$/, tr.budget.validation.month);
|
||||
|
||||
/**
|
||||
* Limit formu: kategori → tutar metni. Boş veya 0 limit kaldırılır (kategori bütçesiz olur).
|
||||
*/
|
||||
export const budgetLimitsSchema = z.object({
|
||||
month: budgetMonthSchema,
|
||||
limits: z
|
||||
.array(
|
||||
z.object({
|
||||
categoryId: z.string().regex(/^[a-f0-9]{24}$/i, tr.budget.validation.category),
|
||||
amount: nonNegativeMoneySchema,
|
||||
}),
|
||||
)
|
||||
.max(500)
|
||||
.transform((list) =>
|
||||
list
|
||||
.filter((l) => l.amount > 0)
|
||||
.map((l) => ({ categoryId: l.categoryId, amountMinor: l.amount })),
|
||||
),
|
||||
});
|
||||
export type BudgetLimitsForm = z.output<typeof budgetLimitsSchema>;
|
||||
Reference in New Issue
Block a user