2025-11-01 09:24:26 +08:00
|
|
|
import mongoose, { type InferSchemaType } from 'mongoose';
|
|
|
|
|
|
|
|
|
|
const budgetSchema = new mongoose.Schema(
|
|
|
|
|
{
|
|
|
|
|
category: { type: String, required: true },
|
|
|
|
|
amount: { type: Number, required: true, min: 0 },
|
|
|
|
|
currency: { type: String, default: 'CNY' },
|
|
|
|
|
period: { type: String, enum: ['monthly', 'weekly'], default: 'monthly' },
|
|
|
|
|
threshold: { type: Number, min: 0, max: 1, default: 0.8 },
|
|
|
|
|
usage: { type: Number, min: 0, default: 0 },
|
2025-11-10 13:58:06 +08:00
|
|
|
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }
|
2025-11-01 09:24:26 +08:00
|
|
|
},
|
|
|
|
|
{ timestamps: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type BudgetDocument = InferSchemaType<typeof budgetSchema>;
|
|
|
|
|
|
|
|
|
|
export const BudgetModel = mongoose.models.Budget ?? mongoose.model('Budget', budgetSchema);
|