all files / backend/models/ weapon.js

64.29% Statements 9/14
0% Branches 0/2
50% Functions 1/2
69.23% Lines 9/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                                     
'use strict'
 
let mongoose = require('mongoose')
let Schema = mongoose.Schema
const RESTRICTED = new Set()
 
/**
 * Weapon Schema
 */
var WeaponSchema = new Schema({
  title: {
    type: String,
    required: true
  },
  description: String,
  createdOn: {
    type: Date,
    default: Date.now
  },
  updatedOn: {
    type: Date,
    default: Date.now
  }
})
 
WeaponSchema.pre('save', function (next) {
  // Update the timestamp
  this.updatedOn = Date.now()
 
  return next()
})
 
// Convert from 'firstName,lastName' to
// { firstName: 1, lastName: 1}
WeaponSchema.statics.reduceFields = function (fields) {
  return fields.split(',').reduce((memo, field) => {
    if (RESTRICTED.has(field)) return memo
    memo[field] = 1
    return memo
  }, {})
}
 
module.exports = mongoose.model('Weapon', WeaponSchema, 'weapons')