const DBModule = require('./DBModule');

class News extends DBModule {

  get table() {
    return 'news'
  }

  get primary() {
    return 'id'
  }

  get fields() {
    return [
      'id', 'title', 'content', 'cover', 'label',
      'date', 'sort', 'address', 'hide', 'user_id', 'origin',
      'english_id', 'chinese_id', 'language', 'redire'
    ]
  }

  paging(page, limit, keyword = '', language) {
    let joinSql = '';

    language && (joinSql += `and language = '${language}'`);
    let sql = `select {{header}} from \`news\` where title like '%${keyword}%' and hide=${this.hide} ${joinSql} order by \`sort\` asc`
    return super.paging({
      page,
      limit,
      start: page * limit,
      sql,
      paging: 1,
      headers: '*'
    })
  }
}

module.exports = exports = News;