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:
2026-11-06 00:58:51 +03:00
parent 6de6d07c66
commit 3fa1e949e2
10 changed files with 1179 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
import { model, models, Schema, type InferSchemaType, type Model } from "mongoose";
/**
* Aylık bütçe (Bölüm 6.9): hane × bütçe ayı ("YYYY-MM") başına kategori limitleri.
* Ayın sınırları hane ayarı `budgetMonthStartDay`'e göre hesaplanır (belgede saklanmaz).
*/
const limitSchema = new Schema(
{
categoryId: { type: Schema.Types.ObjectId, required: true },
amountMinor: { type: Number, required: true, min: 0 },
},
{ _id: false },
);
const budgetSchema = new Schema(
{
householdId: { type: Schema.Types.ObjectId, required: true },
month: { type: String, required: true, match: /^\d{4}-(0[1-9]|1[0-2])$/ },
limits: { type: [limitSchema], default: [] },
seedRef: { type: String, default: null },
createdBy: { type: Schema.Types.ObjectId, required: true },
updatedBy: { type: Schema.Types.ObjectId, required: true },
},
{ timestamps: true, collection: "budgets" },
);
budgetSchema.index({ householdId: 1, month: 1 }, { unique: true });
export type Budget = InferSchemaType<typeof budgetSchema>;
export const BudgetModel: Model<Budget> =
(models.Budget as Model<Budget> | undefined) ?? model<Budget>("Budget", budgetSchema);