ekantin

model katin

Apr 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose    = require('mongoose')
  2. const idvalidator = require('mongoose-id-validator')
  3. const Schema      = mongoose.Schema
  4.  
  5. const kantinSchema = new Schema({
  6.   _id: {
  7.     type: String,
  8.     required: true,
  9.     maxlength: 5
  10.   },
  11.   tanggal_register: {
  12.     type: Date,
  13.     required: true
  14.   },
  15.   nama_kantin: {
  16.     type: String,
  17.     required: true,
  18.     maxlength: 50
  19.   },
  20.   no_telepon: {
  21.     type: String,
  22.     required: true,
  23.     maxlength: 14
  24.   },
  25.   foto_kantin: {
  26.     type: String,
  27.     required: true
  28.   }
  29. },{
  30.   toObject: {
  31.     virtuals: true
  32.   },
  33.   timestamps: {
  34.     createdAt: 'created_at',
  35.     updatedAt: 'updated_at'
  36.   }
  37. })
  38.  
  39. kantinSchema.plugin(idvalidator)
  40.  
  41. kantinSchema.virtual('kode_kantin').get(() => {
  42.   return this._id
  43. })
  44.  
  45. const Model = mongoose.model('Kantin', kantinSchema)
  46. module.exports = Model
Advertisement
Add Comment
Please, Sign In to add comment