Your IP : 216.73.216.43


Current Path : /proc/thread-self/root/home/deltalab/PMS/sms-connector/models/mongoose/
Upload File :
Current File : //proc/thread-self/root/home/deltalab/PMS/sms-connector/models/mongoose/category.js

const mongoose = require('mongoose');

// SCHEMA ============================================
const LocalizationSchema = new mongoose.Schema(
  {
    code: String,
    label: String,
  },
  {
    _id: false,
    versionKey: false,
  },
);

const AttributeSchema = new mongoose.Schema(
  {
    name: String,
    type: String,
    required: Boolean,
  },
  {
    _id: false,
    versionKey: false,
  },
);

const CategorySchema = new mongoose.Schema(
  {
    name: [LocalizationSchema],
    parentId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Category',
    },
    childrenId: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Category' }],
    googleId: String,
    isLeaf: Boolean,
    isRoot: Boolean,
    attributes: [AttributeSchema],
  },
  {
    timestamps: true,
    versionKey: false,
  },
);

// MODELS ============================================
const categoryModel = mongoose.model('Category', CategorySchema);
const attributeModel = mongoose.model('Attribute', AttributeSchema);

// EXPORTS ===========================================
module.exports = {
  attributeModel,
  categoryModel,
  CategorySchema,
  AttributeSchema,
};