19 lines
723 B
TypeScript
19 lines
723 B
TypeScript
|
|
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);
|