Commit aa36d917 authored by wty's avatar wty

上线test8

parent ab684289
......@@ -4,51 +4,33 @@ const getMysql = require('../SQLPool')
const router = express.Router()
const query = require('../lib/query')
getMysql.then(Mysql => {
// router.get('/addToolBox', async (req, res) => {
// const {toolbox_name, toolbox_icon, toolbox_desc, toolbox_url, type_id, child_type_id} = req.query
// const SQL1 = 'INSERT INTO toolbox (toolbox_name, toolbox_icon, toolbox_desc, toolbox_url,sort_id) VALUES (?,?,?,?,?)'
// const SQL2 = 'INSERT INTO type_childtype_toolbox (toolbox_id,type_id,child_type_id) VALUES (?,?,?)'
// const SQL3 = 'SELECT * FROM toolbox'
// const addToolBox = await query(SQL1, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0])
// const queryToolBox = await query(SQL3)
// const addRelation = await query(SQL2, [])
// Mysql.query(SQL, , (err, result) => {
// if (err) {
// res.send({
// success: false,
// err
// })
// return
// }
// request(domain + '/query/queryToolBox', {}, (error, response, body) => {
// if (error) {
// console.error(error)
// res.send({success: false,err : error})
// return
// }
// console.log(domain + '/query/queryToolBox')
// console.log('body:', body)
// const data = JSON.parse(body).data
// const lastToolBoxId = data[data.length - 1].toolbox_id
//
// const params = [lastToolBoxId, type_id]
// if (typeof child_type_id !== 'number') params.push(null)
// else params.push(child_type_id)
// Mysql.query(SQL, params, (err, result) => {
// if (err) {
// res.send({
// success: false,
// err
// })
// return
// }
// res.send({
// success: true
// })
// })
// })
// })
// })
router.get('/addToolBox', async (req, res) => {
const {toolbox_name, toolbox_icon, toolbox_desc, toolbox_url, type_id, child_type_id} = req.query
const SQL1 = 'INSERT INTO toolbox (toolbox_name, toolbox_icon, toolbox_desc, toolbox_url,sort_id) VALUES (?,?,?,?,?)'
const SQL2 = 'INSERT INTO type_childtype_toolbox (toolbox_id,type_id,child_type_id) VALUES (?,?,?)'
const SQL3 = 'SELECT * FROM toolbox'
try{
const addToolBox = await query(SQL1, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0])
if (!addToolBox) throw 'addToolBox异常'
const queryToolBox = await query(SQL3)
if (!queryToolBox) throw '没有toolbox信息'
const lastToolBoxId = queryToolBox[queryToolBox.length - 1].toolbox_id
const params = [lastToolBoxId, type_id]
if (typeof child_type_id !== 'number') params.push(null)
else params.push(child_type_id)
const addRelation = await query(SQL2, params)
if (addRelation) res.send({success: true})
else throw 'addRelation异常'
}catch (e){
console.error(e)
res.send({
success: false,
err: e
})
}
})
router.get('/addType', (req, res) => {
const {type_name, child_type_name, type_id} = req.query
......
......@@ -66,8 +66,7 @@ getMysql.then(Mysql => {
res.send({
success: true,
data: {
result,
toolbox_url: decodeURIComponent(result['toolbox_url'])
...result.map(v => ({...v,toolbox_url : v['toolbox_url']})),
}
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment