locales.js 813 Bytes
Newer Older
1 2 3 4 5
const Model = require('objection').Model

/**
 * Locales model
 */
6
module.exports = class Locale extends Model {
7
  static get tableName() { return 'locales' }
8
  static get idColumn() { return 'code' }
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

  static get jsonSchema () {
    return {
      type: 'object',
      required: ['code', 'name'],

      properties: {
        code: {type: 'string'},
        isRTL: {type: 'boolean', default: false},
        name: {type: 'string'},
        nativeName: {type: 'string'},
        createdAt: {type: 'string'},
        updatedAt: {type: 'string'}
      }
    }
  }

26 27 28 29
  static get jsonAttributes() {
    return ['strings']
  }

30 31 32 33 34 35 36 37
  $beforeUpdate() {
    this.updatedAt = new Date().toISOString()
  }
  $beforeInsert() {
    this.createdAt = new Date().toISOString()
    this.updatedAt = new Date().toISOString()
  }
}