Wolkendama-API / Model / shopModel.js
shopModel.js
Raw
const mongoose = require("mongoose");
const slugify = require("slugify");

const shopSchema = new mongoose.Schema({
  title: {
    type: String,
    required: [true, "Product must have a title"],
    unique: true,
  },
  descriptions: {
    type: String,
    required: [true, "Producst must have a descriptions"],
  },
  img: [String],
  imgPublicId: [String],
  imgCover: String,
  imgCoverPublicId: String,
  slug: String,
  itemFilter: [
    {
      type: String,
      required: [true, "Item must have a filter"],
      enum: ["hot", "new", "advanced", "basic", "accessories"],
    },
  ],
  rank: {
    type: Number,
    unique: true,
    validate: [(val) => typeof val === "number", "Value must be a number"],
  },
  specification: [String],
  variant: {
    type: Object,
    required: [true, "Item must have a variant"],
  },
  reserveItem: {
    type: Array,
    validate: [(val) => Array.isArray(val), "Value must be an array!"],
  },
  date: {
    type: Date,
    default: Date.now(),
  },
  productionReady: {
    type: Boolean,
    default: false,
  },
});

shopSchema.pre("save", function (next) {
  this.slug = slugify(this.title, { lower: true });
  next();
});

const Shop = mongoose.model("Shop", shopSchema);
module.exports = Shop;