forked from esstephan/wokesharks
-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.js
56 lines (50 loc) · 1.42 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
//import mongoose and database
var mongoose = require('mongoose');
var db = require('./database.js')
// Users
var userSchema = mongoose.Schema({
// _id: // AUTO-GENERATED
username: String,
password: String,
email: String,
sites: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Site' }]
});
// Sites
var siteSchema = mongoose.Schema({
// _id: // AUTO-GENERATED
_user: { type: mongoose.Schema.ObjectId, ref: 'User' },
url: String,
title: String,
status: String,
date: String,
clicks: [{ type: mongoose.Schema.Types.ObjectId, ref: 'linkClickSchema' }],
views: [{ type: mongoose.Schema.Types.ObjectId, ref: 'pageViewSchema' }]
});
// Link Clicks
var linkClickSchema = mongoose.Schema({
// _id: // AUTO-GENERATED
_site: { type: mongoose.Schema.Types.ObjectId, ref: 'Site' },
url: String,
count: Number,
date: Array
});
// Page Views
var pageViewSchema = mongoose.Schema({
// _id: // AUTO-GENERATED
_site: { type: mongoose.Schema.Types.ObjectId, ref: 'Site' },
title: String,
count: Number,
date: Array
});
//create models for each schema
var User = mongoose.model('User', userSchema);
var Site = mongoose.model('Site', siteSchema);
var linkClickModel = mongoose.model('linkClickSchema', linkClickSchema);
var pageViewModel = mongoose.model('pageViewSchema', pageViewSchema);
//export models
module.exports = {
User: User,
Site: Site,
linkClickModel: linkClickModel,
pageViewModel: pageViewModel
};