Your IP : 216.73.216.220


Current Path : /home/deltalab/PMS/partner-manager-backend/models/mongoose/
Upload File :
Current File : //home/deltalab/PMS/partner-manager-backend/models/mongoose/offer.js

const mongoose = require('mongoose');

const { Schema } = mongoose;
const { AttributeSchema } = require('./category');

const OfferAttributeValueSchema = new mongoose.Schema(
  {
    attribute: AttributeSchema,
    value: Schema.Types.Mixed,
  },
  {
    _id: false,
  },
);

// SCHEMA ============================================
/**
* The OfferSchema model represents a product sold on a specific channel, with some customizable data (like price).
*/
const OfferSchema = new mongoose.Schema(
  {
    title: String,
    description: String,
    channelId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Channel',
      required: true,
    },
    sku: String,
    price: Number,
    originalPrice: Number,
    urlKey: String,
    imsCategories: [String],
    deleted: { type: Boolean, required: true, default: false },
    imsEnabled: Boolean,
    isValidFrom: Boolean,
    validFrom: Date,
    isValidUntil: Boolean,
    validUntil: Date,
    attributes: [OfferAttributeValueSchema],
  },
  {
    timestamps: true,
    versionKey: false,
  },
);

// MODELS ============================================
const offerModel = mongoose.model('OfferModule', OfferSchema);

// EXPORTS ===========================================
module.exports = {
  offerModel,
  OfferSchema,
};