71 lines
1.6 KiB
JavaScript
71 lines
1.6 KiB
JavaScript
const Model = require('objection').Model
|
|
|
|
/**
|
|
* Pages model
|
|
*/
|
|
module.exports = class Page extends Model {
|
|
static get tableName() { return 'pages' }
|
|
|
|
static get jsonSchema () {
|
|
return {
|
|
type: 'object',
|
|
required: ['path', 'title'],
|
|
|
|
properties: {
|
|
id: {type: 'integer'},
|
|
path: {type: 'string'},
|
|
title: {type: 'string'},
|
|
description: {type: 'string'},
|
|
isPublished: {type: 'boolean'},
|
|
publishStartDate: {type: 'string'},
|
|
publishEndDate: {type: 'string'},
|
|
content: {type: 'string'},
|
|
|
|
createdAt: {type: 'string'},
|
|
updatedAt: {type: 'string'}
|
|
}
|
|
}
|
|
}
|
|
|
|
static get relationMappings() {
|
|
return {
|
|
tags: {
|
|
relation: Model.ManyToManyRelation,
|
|
modelClass: require('./tags'),
|
|
join: {
|
|
from: 'pages.id',
|
|
through: {
|
|
from: 'pageTags.pageId',
|
|
to: 'pageTags.tagId'
|
|
},
|
|
to: 'tags.id'
|
|
}
|
|
},
|
|
author: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: require('./users'),
|
|
join: {
|
|
from: 'pages.authorId',
|
|
to: 'users.id'
|
|
}
|
|
},
|
|
locale: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: require('./locales'),
|
|
join: {
|
|
from: 'users.locale',
|
|
to: 'locales.code'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$beforeUpdate() {
|
|
this.updatedAt = new Date().toISOString()
|
|
}
|
|
$beforeInsert() {
|
|
this.createdAt = new Date().toISOString()
|
|
this.updatedAt = new Date().toISOString()
|
|
}
|
|
}
|