-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.js
62 lines (51 loc) · 1.16 KB
/
schema.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs'); // encrypt user/pws
var Schema = mongoose.Schema;
// SCHEMA for Posts
var PostSchema = new Schema({
author: String,
content: String,
pTitle: String,
date: Date
}, {
timestamps: { createdAt: 'created_at'}
});
var Post = mongoose.model('Post', PostSchema);
// SCHEMA for Portfolio
var portfolioSchema = new Schema({
portTitle: String,
portDescription: String,
portImage: String
})
var Portfolio = mongoose.model('Postfolio', portfolioSchema);
// SCHEMA for Profiles / Accounts
var userSchema = new Schema({
local: {
email: String,
password: String,
personal: {
fn: String,
ln: String,
age: {
type: Number,
min: 15,
max: 85
},
loc: String
}
}
});
// generate hash
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
// check if pw is valid
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
};
var Profile = mongoose.model('Profile', userSchema);
module.exports = {
Post: Post,
Profile: Profile,
Portfolio: Portfolio
};