All files / controllers backlink.js

50% Statements 7/14
0% Branches 0/4
25% Functions 1/4
50% Lines 7/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 3815x       15x 15x 15x 15x                     15x                                 15x    
module.exports = function(crowi, app) {
  'use strict'
 
  // var debug = require('debug')('crowi:routes:backlink')
  var Backlink = crowi.model('Backlink')
  var ApiResponse = require('../util/apiResponse')
  var actions = {}
  actions.api = {}
 
  /**
   * @api {list} /backlink.list Get list backlinks of the page
   * @apiName ListBackLink
   * @apiGroup Backlink
   *
   * @apiParam {String} page_id Page Id.
   * @apiParam {Number} limit
   * @apiParam {Number} offset
   */
  actions.api.list = function(req, res) {
    var pageId = req.query.page_id
    var limit = req.query.limit || 10
    var offset = req.query.offset || 0
 
    Backlink.findByPageId(pageId, limit, offset)
      .then(backlinks => {
        var result = {
          data: backlinks,
        }
        return res.json(ApiResponse.success(result))
      })
      .catch(err => {
        return res.json(ApiResponse.error(err))
      })
  }
 
  return actions
}