mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
71 lines
1.6 KiB
7 years ago
|
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()
|
||
|
}
|
||
|
}
|