fix:优化匹配规则
This commit is contained in:
31
apps/backend/src/models/notification-rule.model.ts
Normal file
31
apps/backend/src/models/notification-rule.model.ts
Normal 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);
|
||||
|
||||
Reference in New Issue
Block a user