samoulla-backend / models /stockSubscriptionModel.js
Samoulla Sync Bot
Auto-deploy Samoulla Backend: 8574a71f0fc617aeb1ce9b5e35dac24c5319a12a
59c49c1
const mongoose = require('mongoose');
const stockSubscriptionSchema = new mongoose.Schema(
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: [true, 'Subscription must belong to a user'],
index: true,
},
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product',
required: [true, 'Subscription must reference a product'],
index: true,
},
notifiedAt: {
type: Date,
default: null,
// Set when the user has been notified; null means still waiting
},
},
{
timestamps: true,
},
);
// Prevent duplicate subscriptions per user+product
stockSubscriptionSchema.index({ user: 1, product: 1 }, { unique: true });
const StockSubscription = mongoose.model(
'StockSubscription',
stockSubscriptionSchema,
);
module.exports = StockSubscription;