forked from jpotts18/json-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.js
56 lines (43 loc) · 1.55 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
var Sequelize = require('sequelize');
var Config = require('./config');
var user = Config.dbUser;
var database = Config.dbName;
var password = Config.dbPassword;
var sequelize = new Sequelize(database , user, password );
//************* USER **************//
exports.User = sequelize.define('users',{
first : { type: Sequelize.STRING, validate : {isAlpha : true}}
, last : { type: Sequelize.STRING, validate : {isAlpha : true}}
, username : { type: Sequelize.STRING, validate : { max : 15, min : 5 , unique : true}}
, password : { type: Sequelize.STRING, validate : { min : 6}}
, email : { type: Sequelize.STRING, validate : { isEmail : true }}
, apiKey : { type: Sequelize.STRING, validate : { unique : true}}
});
exports.Page = sequelize.define('pages',{
isPublished : Sequelize.BOOLEAN
, slug : Sequelize.STRING
, isDraft : Sequelize.BOOLEAN
, title : Sequelize.STRING
});
exports.Block = sequelize.define('blocks',{
tag : Sequelize.STRING
, content : Sequelize.TEXT
, isMobile : Sequelize.BOOLEAN
});
exports.Comment = sequelize.define('comments',{
title : Sequelize.STRING
, content : Sequelize.TEXT
, author : Sequelize.STRING
, email : Sequelize.STRING
});
exports.Block.belongsTo(exports.Page);
exports.Page.hasMany(exports.Block);
exports.Comment.belongsTo(exports.Page);
exports.Page.hasMany(exports.Comment);
exports.synchronize = function(fn){
sequelize.sync({force: true});
//wait 2 seconds to make sure that the database has been built
setTimeout(function(){
fn(true);
}, 2000);
};