const express = require("express")
var router = express.Router();
const pool = require("../pool.js")
router.get("/details", (req, res) => {
var tid = req.query.tid;
if (!tid || tid == 0) {
var sql1 = `select pid,tid,title,hpic from product`;
} else {
var sql1 = `select pid,tid,title,hpic from product where tid=?`;
}
if (!tid) {
var sql2 = `select tid,name from type`;
} else {
var sql2 = `select tid,name from type where tid=4`;
}
function abc(a, b) {
return new Promise(function (resolve, reject) {
pool.query(a, b, (err, result) => {
if (err) throw err;
resolve(result);
});
});
}
Promise.all([abc(sql1, [tid]), abc(sql2, [tid])])
.then(data => {
let asd = {
product: data[0],
type: data[1]
}
res.send(asd);
// console.log(data);
}).catch(err => {
console.log(err);
})
console.log(tid);
})
module.exports = router;