Advertisement
EiEich

Untitled

Jun 16th, 2021
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require('mongoose');
  2. var Schema = mongoose.Schema({
  3.     name: String,
  4.     balance: {},
  5.     description: String,
  6.     author: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
  7.     moderators: [{type: mongoose.Schema.Types.ObjectId, sparse: true, ref: 'User'}],
  8.     url: {type: String, unique: true, sparse: true, trim: true},
  9.     avatarUrl: {type: String, default: '/assets/img/groups/avatar.png'},
  10. });
  11.  
  12. Schema.methods.create = function(obj, user, sd) {
  13.     this.author = user._id;
  14.     this.balance = {};
  15.     this.moderators = [user._id];
  16.     this.name = obj.name;
  17.     this.balance[user._id] = [];
  18.     this.avatarUrl = obj.avatarUrl || '/assets/img/groups/avatar.png'
  19.     this.balance['item'] = 0
  20. }
  21.  
  22. module.exports = mongoose.model('Group', Schema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement