-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.js
53 lines (44 loc) · 1000 Bytes
/
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
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
//es6 promise
mongoose.Promise = global.Promise;
const artistSchema = new Schema({
name: String,
imgUrl: String,
soundCloud: String,
youtubeUrl: String
});
const showSchema = new Schema({
name: String,
date: Date,
stringDate: String,
city: String,
state: String,
venue: String,
eventPage: String,
artistList: [artistSchema]
});
const userSchema = new Schema({
userName: String,
firstName: String,
lastName: String,
email: String,
password: String,
showsList: [showSchema]
});
userSchema.pre('save', (next)=>{
now = new Date();
this.updated_at = now;
if ( !this.create_at) {
this.created_at = now;
}
next();
});
const Artist = mongoose.model('Artist', artistSchema);
const Show = mongoose.model('Event', showSchema);
const User = mongoose.model('User', userSchema);
module.exports = {
Artist,
Show,
User
};