Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var mongoose = require('mongoose');
  4. var Schema = mongoose.Schema;
  5.  
  6. var DeviceSchema = new Schema({
  7. name: String,
  8. macAddress: String,
  9. createdBy: {
  10. type: String,
  11. default: 'user'
  12. },
  13. createdAt: {
  14. type: Date
  15. },
  16. updatedAt: {
  17. type: Date
  18. }
  19. });
  20.  
  21. DeviceSchema.pre('save', function(next) {
  22. var now = new Date();
  23. this.updatedAt = now;
  24. if (!this.createdAt) {
  25. this.createdAt = now;
  26. }
  27. next();
  28. });
  29.  
  30. module.exports = mongoose.model('Device', DeviceSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement