forked from thesentinelproject/threatwiki_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
61 lines (52 loc) · 1.94 KB
/
model.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
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
function createModel() {
var DataPoint = new Schema ({
title: { type: String, required: true }
, description: { type: String, required: true }
, Location: {
title: { type: String, required: true }
, latitude: { type: String, required: true }
, longitude: { type: String, required: true }
}
, soc: { type: String, required: true }
, modified: { type: Date, required: true }
, created: { type: Date, required: true }
// foreign key
, tags : [{ type: ObjectId, ref: 'Tag' }]
, createdBy : { type: ObjectId, ref: 'User' }
});
var Soc = new Schema ({
title: { type: String, required: true }
, modified: { type: Date, required: true }
, created: { type: Date, required: true }
, createdBy : { type: ObjectId, ref: 'User' }
});
var Tag = new Schema ({
title: { type: String, required: true }
, description: { type: String, required: false }
, modified: { type: Date, required: true }
, created: { type: Date, required: true }
, soc: { type: String, required: true }
, createdBy : { type: ObjectId, ref: 'User' }
});
//used for user authentication, can't have more than 1 user with same email
var User = new Schema ({
name: { type: String, required: true }
, email: { type: String, required: true, unique: true }
, modified: { type: Date, required: true }
, created: { type: Date, required: true }
});
// model definitions
var SocModel = mongoose.model('Soc', Soc);
var DataPointModel = mongoose.model('DataPoint', DataPoint);
var TagModel = mongoose.model('Tag', Tag);
var UserModel = mongoose.model('User', User);
// model exports
exports.SocModel = SocModel;
exports.DataPointModel = DataPointModel;
exports.TagModel = TagModel;
exports.UserModel = UserModel;
}
exports.createModel = createModel;