feat: comments - default provider create (wip) + permissions
This commit is contained in:
55
server/models/comments.js
Normal file
55
server/models/comments.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const Model = require('objection').Model
|
||||
|
||||
/**
|
||||
* Comments model
|
||||
*/
|
||||
module.exports = class Comment extends Model {
|
||||
static get tableName() { return 'comments' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: [],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
content: {type: 'string'},
|
||||
render: {type: 'string'},
|
||||
name: {type: 'string'},
|
||||
email: {type: 'string'},
|
||||
ip: {type: 'string'},
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
return {
|
||||
author: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./users'),
|
||||
join: {
|
||||
from: 'comments.authorId',
|
||||
to: 'users.id'
|
||||
}
|
||||
},
|
||||
page: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: require('./pages'),
|
||||
join: {
|
||||
from: 'comments.pageId',
|
||||
to: 'pages.id'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$beforeUpdate() {
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
$beforeInsert() {
|
||||
this.createdAt = new Date().toISOString()
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user