forked from TheDahv/BeerAndCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.js
89 lines (77 loc) · 2.29 KB
/
models.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var MD5 = require('./MD5'),
conf = require('./conf'),
// Model name declarations
PersonSchema,
JobPostSchema,
JobRequestSchema;
exports.defineModels = function (
mongoose,
Project,
Person,
JobPost,
JobRequest,
cb) {
Schema = mongoose.Schema;
Project = new Schema({
name : String,
project_url : String,
description : String
});
PersonSchema = new Schema({
name : String,
password : String,
email : String,
gravatar : String, // MD5 hash based on email
irc : String,
twitter_nick : String,
github_nick : String,
bio : String,
url_slug : String,
languages : [String],
projects : [Project],
active : Boolean
});
PersonSchema.pre('save', function (next) {
/*
* Generate an MD5 hash of the supplied email
* and save that as the gravatar string before saving
*/
if (this.email) {
this.gravatar = require('./MD5').toMD5(this.email);
}
/*
* Remove spaces and weirdo characters to make an addressable
* slug for this person. Hope people don't have the same names...
*/
this.url_slug = this.name.toLowerCase().replace(/\s/g, '-').replace(/[^a-z0-9\-]/g, '');
next();
});
JobPostSchema = new Schema({
headline : String,
company_name : String,
description : String,
category : {type: String, enum: ['ft', 'pt', 'fl', 'ct']}, /* full-time, part-time, freelance, contract */
info_url : String,
contact_email : String,
technologies : [String],
date_created : Date
});
JobPostSchema.pre('save', function (next) {
this.date_created = this.date_created || new Date();
next();
});
JobRequestSchema = new Schema({
headline : String,
category : {type: String, enum: ['ft', 'pt', 'fl', 'ct']}, /* full-time, part-time, freelance, contract */
technologies : [String],
date_created : Date
});
JobRequestSchema.pre('save', function (next) {
this.date_created = this.date_created || new Date();
});
// Add to Mongoose
Person = mongoose.model('Person', PersonSchema);
JobPost = mongoose.model('JobPost', JobPostSchema);
JobRequest = mongoose.model('JobRequest', JobRequestSchema);
cb();
};