-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-handler.js
More file actions
42 lines (32 loc) · 1.02 KB
/
db-handler.js
File metadata and controls
42 lines (32 loc) · 1.02 KB
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
var mongoose = require('mongoose'),
config = require('./config/config_heroku');
mongoose.connect(config.db);
var db = mongoose.connection;
db.on('error', function (err) {
console.log('connection error:', err.message);
});
db.once('open', function callback () {
console.log("Connected to DB!");
});
var Schema = mongoose.Schema;
var User = new Schema({
login: { type: String, required: true },
pass: { type: String, required: true },
session: { type: String, required: true },
modified: { type: Date, default: Date.now },
data: Schema.Types.Mixed
})
var Session = new Schema({
session: { type: String, required: true },
login: {type: String, required: true}
})
User.path('login').validate(function (v) {
return v.length > 2 && v.length < 70;
});
User.statics.validateUser = function (name, cb) {
this.find({ login: name}, cb);
}
UserModel = mongoose.model('User', User);
SessionModel = mongoose.model('Session', Session);
module.exports.UserModel = UserModel;
module.exports.connection = db;