fix:优化匹配规则

This commit is contained in:
2025-11-13 13:50:20 +08:00
parent fd442c2f8b
commit 53f5cf479d
9 changed files with 317 additions and 21 deletions

View File

@@ -0,0 +1,31 @@
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);