forked from dresende/node-orm2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
123 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
module.exports = { | ||
home : require('./home_controller'), | ||
messages : require('./messages_controller'), | ||
comments : require('./comments_controller') | ||
messages : require('./messages_controller'), | ||
comments : require('./comments_controller') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
var moment = require('moment'); | ||
|
||
module.exports = function (orm, db) { | ||
var Comment = db.define('comment', { | ||
body : { type: 'text', required: true }, | ||
createdAt : { type: 'date', required: true, time: true } | ||
}, | ||
{ | ||
hooks: { | ||
beforeValidation: function () { | ||
this.createdAt = new Date(); | ||
} | ||
}, | ||
validations: { | ||
body : orm.enforce.ranges.length(1, 1024) | ||
}, | ||
methods: { | ||
serialize: function () { | ||
return { | ||
body : this.body, | ||
createdAt : moment(this.createdAt).fromNow() | ||
} | ||
} | ||
} | ||
}); | ||
var Comment = db.define('comment', { | ||
body : { type: 'text', required: true }, | ||
createdAt : { type: 'date', required: true, time: true } | ||
}, | ||
{ | ||
hooks: { | ||
beforeValidation: function () { | ||
this.createdAt = new Date(); | ||
} | ||
}, | ||
validations: { | ||
body : orm.enforce.ranges.length(1, 1024) | ||
}, | ||
methods: { | ||
serialize: function () { | ||
return { | ||
body : this.body, | ||
createdAt : moment(this.createdAt).fromNow() | ||
} | ||
} | ||
} | ||
}); | ||
|
||
Comment.hasOne('message', db.models.message, { required: true, reverse: 'comments', autoFetch: true }); | ||
Comment.hasOne('message', db.models.message, { required: true, reverse: 'comments', autoFetch: true }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
var moment = require('moment'); | ||
|
||
module.exports = function (orm, db) { | ||
var Message = db.define('message', { | ||
title : { type: 'text', required: true }, | ||
body : { type: 'text', required: true, big: true }, | ||
createdAt : { type: 'date', required: true, time: true } | ||
}, | ||
{ | ||
hooks: { | ||
beforeValidation: function () { | ||
this.createdAt = new Date(); | ||
} | ||
}, | ||
validations: { | ||
title: [ | ||
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"), | ||
orm.enforce.ranges.length(undefined, 96, "cannot be longer than 96 letters") | ||
], | ||
body: [ | ||
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"), | ||
orm.enforce.ranges.length(undefined, 32768, "cannot be longer than 32768 letters") | ||
] | ||
}, | ||
methods: { | ||
serialize: function () { | ||
var comments; | ||
var Message = db.define('message', { | ||
title : { type: 'text', required: true }, | ||
body : { type: 'text', required: true, big: true }, | ||
createdAt : { type: 'date', required: true, time: true } | ||
}, | ||
{ | ||
hooks: { | ||
beforeValidation: function () { | ||
this.createdAt = new Date(); | ||
} | ||
}, | ||
validations: { | ||
title: [ | ||
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"), | ||
orm.enforce.ranges.length(undefined, 96, "cannot be longer than 96 letters") | ||
], | ||
body: [ | ||
orm.enforce.ranges.length(1, undefined, "must be atleast 1 letter long"), | ||
orm.enforce.ranges.length(undefined, 32768, "cannot be longer than 32768 letters") | ||
] | ||
}, | ||
methods: { | ||
serialize: function () { | ||
var comments; | ||
|
||
if (this.comments) { | ||
comments = this.comments.map(function (c) { return c.serialize(); }); | ||
} else { | ||
comments = []; | ||
} | ||
if (this.comments) { | ||
comments = this.comments.map(function (c) { return c.serialize(); }); | ||
} else { | ||
comments = []; | ||
} | ||
|
||
return { | ||
id : this.id, | ||
title : this.title, | ||
body : this.body, | ||
createdAt : moment(this.createdAt).fromNow(), | ||
comments : comments | ||
}; | ||
} | ||
} | ||
}); | ||
return { | ||
id : this.id, | ||
title : this.title, | ||
body : this.body, | ||
createdAt : moment(this.createdAt).fromNow(), | ||
comments : comments | ||
}; | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
var path = require('path'); | ||
|
||
var settings = { | ||
path : path.normalize(path.join(__dirname, '..')), | ||
port : process.env.NODE_PORT || 3000, | ||
database : { | ||
protocol : "postgresql", // or "mysql" | ||
query : { pool: true }, | ||
host : "127.0.0.1", | ||
database : "anontxt_dev", | ||
user : "anontxt", | ||
password : "apassword" | ||
} | ||
path : path.normalize(path.join(__dirname, '..')), | ||
port : process.env.NODE_PORT || 3000, | ||
database : { | ||
protocol : "postgresql", // or "mysql" | ||
query : { pool: true }, | ||
host : "127.0.0.1", | ||
database : "anontxt_dev", | ||
user : "anontxt", | ||
password : "apassword" | ||
} | ||
}; | ||
|
||
module.exports = settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters