var mongoose = require('mongoose'); var Schema = mongoose.Schema; module.exports.schema = new Schema({ code: {type: String, required: true, unique: true, index: true}, numAllowedUses: {type: Number, required: true, default: 1}, uses: [{type: Schema.Types.ObjectId, required: true, ref: 'Cart'}], expires: {type: Number, required: true, default: 0}, flatDiscount: {type: Number, required: true, default: 0}, percentDiscount: {type: Number, required: true, default:0}, socksFree: {type: Number, required: true, default: 0}, perSockDiscount: {type: Number, required: false, default: 0}, freeShipping: {type: Boolean, required: true, default: false} }, { usePushEach: true }); module.exports.model = mongoose.model('Coupon', module.exports.schema);