'use strict'

const mongoose = require('mongoose')

const wearSchema = new mongoose.Schema({
  name: String,
  color: String,
  size: String,
  quantity: Number,
  detail: String,
  image: String
})

async function getAllItemsByPage (page) {
  return this.find()
    .skip(page * 5)
    .limit(5)
    .select('name')
    .select('price')
    .select('image')
    .lean()
    .exec()
}

async function getTotalNumberOfItems () {
  return this.find().count().exec()
}

async function getItemDetails (id) {
  return this.findOne({ _id: id }).exec()
}

wearSchema.static({
  getAllItemsByPage,
  getItemDetails,
  getTotalNumberOfItems
})

module.exports = wearSchema

@@ -98,102 +98,258 @@
 me: 
-String,%0A  color: String,%0A  size: String,%0A  quantity: Number,%0A  detail: String,%0A  image: String
+%7B type: String, required: true %7D,%0A  color: %7B type: String, required: true %7D,%0A  size: %7B type: String, required: true %7D,%0A  quantity: %7B type: Number, required: true %7D,%0A  detail: %7B type: String, required: true %7D,%0A  image: %7B type: String, required: true %7D
 %0A%7D)%0A

modify wears mongoose schema types