36 lines
970 B
JavaScript
36 lines
970 B
JavaScript
const mongoose = require('mongoose')
|
|
const timestamp = require('mongoose-timestamp')
|
|
|
|
/**
|
|
* A saved "find a partner" search — kept active indefinitely (per product
|
|
* decision) so the searcher keeps getting notified on every new matching
|
|
* user, not just once. `notified_user_ids` dedupes so the same matched user
|
|
* doesn't trigger a repeat notification for the same alert.
|
|
*/
|
|
const partnerSearchAlertSchema = new mongoose.Schema({
|
|
user_id: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'User',
|
|
required: true,
|
|
index: true
|
|
},
|
|
criteria: {
|
|
type: mongoose.Schema.Types.Mixed,
|
|
required: true
|
|
},
|
|
notified_user_ids: {
|
|
type: [mongoose.Schema.Types.ObjectId],
|
|
default: []
|
|
},
|
|
active: {
|
|
type: Boolean,
|
|
default: true,
|
|
index: true
|
|
}
|
|
})
|
|
|
|
partnerSearchAlertSchema.plugin(timestamp)
|
|
|
|
const PartnerSearchAlertModel = mongoose.model('PartnerSearchAlert', partnerSearchAlertSchema)
|
|
module.exports = PartnerSearchAlertModel
|