// 量表 const util = require('../utils') const db = require('../data') let [sql, rs] = ['', null] /** * 根据单个ID获取量表基本信息 * get: /lb/:id */ exports.Info = async ctx => { const id = ctx.params.id if (!util.isInteger(id)) { throw { code: -2 } } else { const act = ctx.query.act if (act === 'age') { sql = 'select top 1 age_min as min,age_max as max from lb where available=1 and id=' + id } else { sql = `select top 1 name_ch,name_en,name_fr,testtip,questcount,age_min,age_max,intro1,intro2,intro3,picture,money,factor1,chart from lb where available=1 and id=${id}` } rs = await db.select(sql) if (rs) { ctx.body = { code: 0, data: rs } } else { throw { code: 1, message: `量表(${id})未找到` } } } } /** * 只取量表问题 * get /lb/:id/question */ exports.Question = async ctx => { const id = ctx.params.id if (!util.isInteger(id)) { throw { code: -2 } } else { sql = `select sort as no,question from lbquestion where lb=${id} order by sort` rs = await db.select(sql) ctx.body = { code: 0, data: rs || [] } } }