Files
butcem/src/models/household.ts
T
2026-11-05 02:14:10 +03:00

53 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
model,
models,
Schema,
type HydratedDocument,
type InferSchemaType,
type Model,
} from "mongoose";
/** Hane ayarları (Faz 0 kararları: bütçe ayı başlangıcı, taksit ve günlük plan tercihleri). */
const householdSettingsSchema = new Schema(
{
/** Bütçe ayının başlangıç günü (1 = takvim ayı). */
budgetMonthStartDay: { type: Number, min: 1, max: 28, default: 1 },
/** Taksitlerin bütçe etkisi: her taksit kendi ayına | tamamı harcama ayına. */
installmentBudgetMode: {
type: String,
enum: ["per_installment", "purchase_month"],
default: "per_installment",
},
/** Günlük plan: değişken bütçe eşit dağıtılır | önceki ayın örüntüsüne göre. */
dailyPlanMode: { type: String, enum: ["even", "previous_month_pattern"], default: "even" },
/** "Yalnızca ben" hesapları hane toplamlarına dahil edilsin mi? */
includePrivateAccountsInTotals: { type: Boolean, default: true },
/** Akıllı mağaza önerisi: ek mağaza ancak tasarruf bu tutarı aşarsa (kuruş). */
extraStoreSavingThresholdMinor: { type: Number, min: 0, default: 10_000 },
},
{ _id: false },
);
const householdSchema = new Schema(
{
name: { type: String, required: true, trim: true, minlength: 2, maxlength: 80 },
currency: { type: String, enum: ["TRY"], default: "TRY" },
timezone: { type: String, default: "Europe/Istanbul" },
settings: { type: householdSettingsSchema, default: () => ({}) },
archivedAt: { type: Date, default: null },
createdBy: { type: Schema.Types.ObjectId, required: true },
updatedBy: { type: Schema.Types.ObjectId, required: true },
},
{ timestamps: true, collection: "households" },
);
householdSchema.index({ name: 1 });
export type Household = InferSchemaType<typeof householdSchema>;
export type HouseholdDoc = HydratedDocument<Household>;
/** HMR'de modelin yeniden derlenmesini önler. */
export const HouseholdModel: Model<Household> =
(models.Household as Model<Household> | undefined) ??
model<Household>("Household", householdSchema);