示例#1
0
文件: team.js 项目: catHD/FOTM
                    });
                    //затем удалим сами тимы
                    popTeam.remove(function(err){
                        if (err) return callback(err);
                        callback(null);
                    });
                });
            });
        }
        else {
            callback(new CustomError("Team For deletion not found"));
        }
    });
};

exports.Team = mongoose.model('Team', schema);

function CustomError(message) {
    Error.apply(this, arguments);
    Error.captureStackTrace(this, CustomError);

    this.message = message;
}

util.inherits(CustomError, Error);

CustomError.prototype.name = 'CustomError';

exports.CustomError = CustomError;

示例#2
0
var mongoose = require('lib/mongoose');

var linkSchema = mongoose.Schema({
    text: {
        type:     String,
        required: true
    },
    url: {
        type:     String,
        required: true
    },
    createdAt: {
        type:    Date,
        default: Date.now
    }
}, { id: false });

var Link = mongoose.model('Link', linkSchema);

linkSchema.virtual('id').get(function() {
    return this._id;
});

module.exports = Link;
示例#3
0
文件: User.js 项目: temadev/ik
      User.findOne({ email: email }, callback)
    },
    function (user, callback) {
      if (user) {
        if (user.checkPassword(password)) {
          callback(null, user);
        } else {
          callback(new AuthError("Пароль неверен"));
        }
      } else {
        callback(new AuthError("Ошибка авторизации"));
      }
    }
  ], callback);
};

module.exports = mongoose.model('User', userSchema);


function AuthError(message) {
  Error.apply(this, arguments);
  Error.captureStackTrace(this, AuthError);

  this.message = message;
}

util.inherits(AuthError, Error);

AuthError.prototype.name = 'HttpError';

exports.AuthError = AuthError;
示例#4
0
var mongoose = require('lib/mongoose');

var requestSchema = mongoose.Schema({
    text:      {
        type:     String,
        required: true
    },
    createdAt: {
        type:    Date,
        default: Date.now
    }
}, { id: false });

requestSchema.virtual('id').get(function() {
    return this._id;
});

var Request = mongoose.model('Request', requestSchema);

module.exports = Request;
示例#5
0
文件: template.js 项目: lutaev/chat
var mongoose = require('lib/mongoose');
var BaseSchema = require('models/base');

var schema = new BaseSchema({
    name: {
        type: String,
        unique: true,
        required: true
    },
    template: {
        type: String,
        required: true
    }
}, {
    cacheKey: 'Template'
});

module.exports = mongoose.model('Template', schema);
示例#6
0
/*
 ** User's and associated models
 */

var mongoose = require('lib/mongoose');

Schema = mongoose.Schema;

/* ======= Schemas ======= */

var Subscription = new Schema({
    mail: {
        required: true,
        unique: true,
        type: String
    },
    date: {
        type: Date,
        default: Date.now(),
        required: true
    }
})

module.exports.Subscription = mongoose.model('Subscription', Subscription);
示例#7
0
文件: user.js 项目: TrYuPet/Chat
                if (user.checkPassword(password)) {
                    callback(null, user);
                } else {
                    callback(new AuthError("Пароль неверен"));
                }
            } else {
                var user = new User({username: username, password: password});
                user.save(function(err) {
                    if (err) return callback(err);
                    callback(null, user);
                });
            }
        }
    ], callback);
};

exports.User = mongoose.model('User', schema);


function AuthError(message) {
    Error.apply(this, arguments);
    Error.captureStackTrace(this, AuthError);

    this.message = message;
}

util.inherits(AuthError, Error);

AuthError.prototype.name = 'AuthError';

exports.AuthError = AuthError;
示例#8
0
文件: user.js 项目: iPhaeton/chat
            } else {
                callback(new errors.AuthError("Wrong login or password"));
            };
        }
    ], onResult);
};

schema.statics.signup = function (username, password, onResult) {
    var User = this;

    waterfall([
        function (callback) {
            User.findOne({username: username}, callback);
        },
        function (user, callback) {
            if(user){
                callback(new errors.AuthError("This user already exists"));
            } else {
                var user = new User ({username: username, password: password});
                user.save (function (err) {
                    if (err) callback(err);
                    else callback(null, user);
                });
            };
        }
    ], onResult);
};


exports.User = mongoose.model ("User", schema);
var config = require('config');
var path = require('path');

var schema = new Schema({
  // Введение в JavaScript
  title: {
    type: String,
    required: true
  },

  // 2015_05_05_1930.zip
  filename: {
    type: String,
    required: true
  },

  comment: {
    type: String,
    trim: true
  },

  created: {
    type:    Date,
    default: Date.now
  }

});


module.exports = mongoose.model('CourseMaterial', schema);
示例#10
0
  isBot:    {
    type:     Boolean,
    required: true
  }
}, {
  timestamps: true
});


schema.index({userId: 1, teamId: 1}, {unique: true});

schema.statics.readSlack = function(user) {
  return {
    userId:   user.id,
    teamId:   user.team_id,
    name:     user.name,
    deleted:  user.deleted,
    email:    user.profile.email,
    realName: user.real_name,
    isAdmin:  user.is_admin,
    isBot:    user.is_bot
  };
};
  
schema.statics.fromSlack = function(user) {
  return new this(this.readSlack(user));
};

module.exports = mongoose.model('SlackUser', schema);

示例#11
0
文件: note.js 项目: GuryevAV/Notes
var mongoose = require('lib/mongoose'),
    Schema = mongoose.Schema;

var schema = new Schema({
    username: {
        type: String,
        required: true
    },
    text: {
        type: String,
        required: true
    },
    created: {
        type: Date,
        default: Date.now
    }
});


exports.Note = mongoose.model("Note", schema);
示例#12
0
var mongoose = require('lib/mongoose');
var moment = require('moment');
var Schema = mongoose.Schema;

var SpamSchema = new Schema({
    id: {
        type: Number,
        required: true
    },
    tweet_id: {
        type: Number,
        unique: true
    },
    hashtag: {
        type: String
    },
    date: {
        type: Number,
        "default": moment().unix()
    },
    count_of_tweets: {
        type:Number,
        "default": 0
    }
});

exports.Spam = mongoose.model('Spam', SpamSchema);
示例#13
0
文件: data.js 项目: Andy82/bingo_game
var mongoose = require('lib/mongoose');

  var Schema = mongoose.Schema,
      ObjectId = Schema.ObjectId;

  Data = new Schema({
  chosenNumber: {
    type: String
  }
  
});
exports.Data = mongoose.model('Data', Data);
示例#14
0
文件: session.js 项目: iPhaeton/chat
        httpOnly: {
            type: Boolean,
            default: true
        },
        path: {
            type: String,
            default: "/"
        },
        signed: {
            type: Boolean,
            default: true
        },
        overwrite: {
            type: Boolean,
            default: true
        }
    }, 
    created: Date,
    data: Object

});

schema.methods.writeData = function (property, value) {
    this.set("data."+property, value);
    this.save(function (err) {
        if (err) handleError(err);
    })
};

exports.Session = mongoose.model ("Session", schema);
示例#15
0
var mongoose = require('lib/mongoose');
var BaseSchema = require('models/base');

var schema = new BaseSchema({
    name: {
        type: String,
        required: true,
        unique: true
    },
    key: {
        type: String,
        unique: true
    },
    price: {
        type: Number,
        default: null
    },
    visibility: {
        type: Boolean,
        default: true
    }
}, {
    cacheKey: 'ShipmentType'
});

module.exports = mongoose.model('ShipmentType', schema);
示例#16
0
  });


schema.statics.signup = function(username, email, password, done) {
  var User = this;

  User.create({
    username: username,
    email: email,
    password: password,
    avatar: (Math.random()*42^0) + '.jpg'
  }, done);

};

schema.methods.checkPassword = function(password) {
  return hash.createHash(password, this.salt) == this.hash;
};

schema.path('email').validate(function(value) {
  // wrap in new RegExp instead of /.../, to evade WebStorm validation errors (buggy webstorm)
  return new RegExp('^[\\w-.]+@([\\w-]+\\.)+[\\w-]{2,5}$').test(value);
}, 'Please provide the correct e-mail.');

// all references using mongoose.model for safe recreation
// when I recreate model (for tests) => I can reload it from mongoose.model (single source of truth)
// exports are less convenient to update
mongoose.model('User', schema);


示例#17
0
  },
  isGeneral:  {
    type:     Boolean,
    required: true
  },
  isGroup:    { // is private group?
    type:     Boolean,
    required: true
  }
}, {
  timestamps: true
});


schema.statics.readSlack = function(channel) {
  return {
    channelId:  channel.id,
    name:       channel.name,
    isArchived: channel.is_archived,
    isGeneral:  Boolean(channel.is_general), // not exists for groups
    isGroup:    Boolean(channel.is_group) // not exists for channels
  };
};

schema.statics.fromSlack = function(channel) {
  return new this(this.readSlack(channel));
};

module.exports = mongoose.model('SlackChannel', schema);

示例#18
0
文件: category.js 项目: lutaev/chat
    }).then(function(_categories){
        categories = _categories;
        return Category.delete({
            where: {
                _id: id
            }
        });
    }).then(function(){
        if (categories.length) {
            var promises = [];
            _.each(categories, function(category){
                promises.push(Category.deleteRecursive(category._id));
            });
            return Promise.all(promises);
        } else {
            return Good.refresh({
                where: {
                    categoryId: id
                },
                values: {
                    categoryId: null
                }
            });
        }
    });
};



module.exports = mongoose.model('Category', schema);