Files
AI-Bill/apps/backend/src/models/budget.model.ts

19 lines
723 B
TypeScript
Raw Normal View History

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 },
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: false }
},
{ timestamps: true }
);
export type BudgetDocument = InferSchemaType<typeof budgetSchema>;
export const BudgetModel = mongoose.models.Budget ?? mongoose.model('Budget', budgetSchema);