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

32 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-11-13 13:50:20 +08:00
import mongoose, { type InferSchemaType } from 'mongoose';
const notificationRuleSchema = new mongoose.Schema(
{
name: { type: String, required: true },
enabled: { type: Boolean, default: true },
priority: { type: Number, default: 50 },
// Match scope
packageName: { type: String }, // optional: limit to a package/channel
keywords: { type: [String], default: [] }, // any keyword match in title/body
pattern: { type: String }, // optional regex string
// Action
action: { type: String, enum: ['record', 'ignore'], default: 'record' },
category: { type: String }, // override category when action is record
type: { type: String, enum: ['income', 'expense'] }, // override type
amountPattern: { type: String }, // custom regex for extracting amount
// Telemetry
matchCount: { type: Number, default: 0 },
lastMatchedAt: { type: Date }
},
{ timestamps: true }
);
export type NotificationRuleDocument = InferSchemaType<typeof notificationRuleSchema>;
export const NotificationRuleModel =
mongoose.models.NotificationRule ?? mongoose.model('NotificationRule', notificationRuleSchema);