Commit c253b6ac authored by wty's avatar wty

更改后端代码所有接口字段

parent a85fb623
......@@ -26,22 +26,22 @@ const pkg = require('./package.json')
// 获取配置的端口号
const port = 3000
const dockerApp = new DockerApp({
app,
appType: 'express',
port
})
// 注册Eureka
global.eureka = new Eureka({
port, // 应用端口号
appName: pkg.name, // 应用名称
services: ['KJY-WEB'] // 依赖服务名
})
global.eureka.start().then(() => {
dockerApp.startServer()
})
// const dockerApp = new DockerApp({
// app,
// appType: 'express',
// port
// })
//
// // 注册Eureka
// global.eureka = new Eureka({
// port, // 应用端口号
// appName: pkg.name, // 应用名称
// services: ['KJY-WEB'] // 依赖服务名
// })
//
// global.eureka.start().then(() => {
// dockerApp.startServer()
// })
app.use((req, res, next) => {
const url = req.url
......
......@@ -4,10 +4,10 @@ const Mysql = require("../SQLPool");
const router = express.Router()
router.get('/addToolBox', (req, res) => {
const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, typeId, childTypeId} = req.query
const SQL = 'INSERT INTO toolbox (toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl,sortId) VALUES (?,?,?,?,?)'
const {toolbox_name, toolbox_icon, toolbox_desc, toolbox_url, type_id, child_type_id} = req.query
const SQL = 'INSERT INTO toolbox (toolbox_name, toolbox_icon, toolbox_desc, toolbox_url,sortId) VALUES (?,?,?,?,?)'
Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl, 0], (err, result) => {
Mysql.query(SQL, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -17,9 +17,9 @@ router.get('/addToolBox', (req, res) => {
}
request(domain + '/query/queryToolBox', {}, (a, b, body) => {
const data = JSON.parse(body).data
const lastToolBoxId = data[data.length - 1].toolBoxId
const SQL = 'INSERT INTO type_childtype_toolbox (toolBoxId,typeId,childTypeId) VALUES (?,?,?)'
Mysql.query(SQL, [lastToolBoxId,typeId,childTypeId], (err, result) => {
const lastToolBoxId = data[data.length - 1].toolbox_id
const SQL = 'INSERT INTO type_childtype_toolbox (toolbox_id,type_id,child_type_id) VALUES (?,?,?)'
Mysql.query(SQL, [lastToolBoxId,type_id,child_type_id], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -36,16 +36,16 @@ router.get('/addToolBox', (req, res) => {
})
router.get('/addType', (req, res) => {
const {typeName, childTypeName, typeId} = req.query
const {type_name, child_type_name, type_id} = req.query
console.log(req.query)
let SQL = 'INSERT INTO type (typeName) VALUES (?)'
let SQL = 'INSERT INTO type (type_name) VALUES (?)'
const values = []
if (childTypeName && typeId) {
SQL = 'INSERT INTO child_type (childTypeName, typeId) VALUES (?,?)'
values.push(childTypeName)
values.push(typeId)
if (child_type_name && type_id) {
SQL = 'INSERT INTO child_type (child_type_name, type_id) VALUES (?,?)'
values.push(child_type_name)
values.push(type_id)
} else {
values.push(typeName)
values.push(type_name)
}
console.log(values)
try {
......
......@@ -4,10 +4,10 @@ const Mysql = require("../SQLPool");
const router = express.Router()
router.get('/deleteToolBoxById', (req, res) => {
const {toolBoxId} = req.query
const SQL = 'DELETE FROM toolbox WHERE toolBoxId = ?'
const {toolbox_id} = req.query
const SQL = 'DELETE FROM toolbox WHERE toolbox_id = ?'
try {
Mysql.query(SQL, [toolBoxId], (err, result) => {
Mysql.query(SQL, [toolbox_id], (err, result) => {
if (err) {
res.send({
success: false,
......
......@@ -7,11 +7,11 @@ const router = express.Router();
router.post('/addPage', (req, res) => {
const {pageName, code} = req.body
const {page_name, code} = req.body
const SQL = `INSERT INTO page (pageName) VALUES (?)`
const SQL = `INSERT INTO page (page_name) VALUES (?)`
Mysql.query(SQL, [pageName], (err, result) => {
Mysql.query(SQL, [page_name], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -24,7 +24,7 @@ router.post('/addPage', (req, res) => {
try {
request(domain + '/page/queryPage', {}, (a, b, body) => {
const data = JSON.parse(body).data
const id = data[data.length - 1]['pageId']
const id = data[data.length - 1]['page_id']
const fileName = 'page' + id + '.html'
try {
console.log('path:', path.join(__dirname, '../static/' + fileName))
......@@ -63,7 +63,7 @@ router.get('/queryPage', (req, res) => {
}
const _result = result.map(v => {
const url = 'http://172.16.130.180:3001/static/' + 'page' + v['pageId'] + '.html'
const url = 'http://172.16.130.180:3001/static/' + 'page' + v['page_id'] + '.html'
return {
...v,
pageUrl: url
......@@ -78,9 +78,9 @@ router.get('/queryPage', (req, res) => {
})
router.post('/updatePage', (req, res) => {
const {pageId, pageName, code} = req.body
const SQL = 'UPDATE page SET pageName=? WHERE pageId = ?'
Mysql.query(SQL, [pageName, pageId], (err, result) => {
const {page_id, page_name, code} = req.body
const SQL = 'UPDATE page SET page_name=? WHERE page_id = ?'
Mysql.query(SQL, [page_name, page_id], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -88,7 +88,7 @@ router.post('/updatePage', (req, res) => {
})
} else {
try{
const fileName = 'page' + pageId + '.html'
const fileName = 'page' + page_id + '.html'
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
......
......@@ -20,9 +20,9 @@ router.get('/queryType', (req, res) => {
});
router.get('/queryChildType', (req, res) => {
const {typeId} = req.query
const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId FROM child_type INNER JOIN type ON child_type.typeId = type.typeId WHERE type.typeId = ?'
Mysql.query(SQL,[typeId], (err, result) => {
const {type_id} = req.query
const SQL = 'SELECT child_type.child_type_id, child_type.child_type_name, child_type.type_id FROM child_type INNER JOIN type ON child_type.type_id = type.type_id WHERE type.type_id = ?'
Mysql.query(SQL,[type_id], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -38,16 +38,16 @@ router.get('/queryChildType', (req, res) => {
router.get('/queryToolBox', (req, res) => {
let {isFollow, typeId} = req.query
let SQL = `SELECT toolbox.*, type_childtype_toolbox.childTypeId FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolBoxId = toolbox.toolBoxId WHERE type_childtype_toolbox.typeId = ?`
if (!isFollow && !typeId){
SQL = `SELECT * FROM toolBox`
let {isFollow, type_id} = req.query
let SQL = `SELECT toolbox.*, type_childtype_toolbox.child_type_id FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolbox_id = toolbox.toolbox_id WHERE type_childtype_toolbox.type_id = ?`
if (!isFollow && !type_id){
SQL = `SELECT * FROM toolbox`
}
if (isFollow) {
typeId = JSON.parse(typeId)
SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)'
type_id = JSON.parse(type_id)
SQL = 'SELECT * FROM toolbox WHERE toolbox_id IN (?)'
}
Mysql.query(SQL, [typeId], (err, result) => {
Mysql.query(SQL, [type_id], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -64,7 +64,7 @@ router.get('/queryToolBox', (req, res) => {
});
// router.get('/queryToolBoxSortId', (req, res) => {
// const SQL = 'SELECT sortId FROM toolBox'
// const SQL = 'SELECT sortId FROM toolbox'
// Mysql.query(SQL, (err, result) => {
// if (err) {
// res.send({
......
......@@ -38,18 +38,18 @@ router.get('/queryChildType', (req, res) => {
})
router.get('/queryTypeForManage', (req, res) => {
const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId, type.typeName FROM child_type INNER JOIN type ON child_type.typeId = type.typeId'
const SQL = 'SELECT child_type.child_type_id, child_type.child_type_name, child_type.type_id, type.type_name FROM child_type INNER JOIN type ON child_type.type_id = type.type_id'
Mysql.query(SQL, [], (err, result) => {
const dataArr = []
const combineType = (value) => {
if (dataArr.filter(v => v.typeId === value.typeId).length) return
const childType = result.filter(v => v.typeId === value.typeId).map(v => ({
childTypeId: v.childTypeId,
childTypeName: v.childTypeName
if (dataArr.filter(v => v.type_id === value.type_id).length) return
const childType = result.filter(v => v.type_id === value.type_id).map(v => ({
child_type_id: v.child_type_id,
child_type_name: v.child_type_name
}))
dataArr.push({
typeId: value.typeId,
typeName: value.typeName,
type_id: value.type_id,
type_name: value.type_name,
children: childType
})
}
......@@ -65,12 +65,12 @@ router.get('/queryTypeForManage', (req, res) => {
})
router.get('/deleteChildType', ((req, res) => {
const {childTypeId} = req.query
const {child_type_id} = req.query
let SQL = 'DELETE FROM child_type WHERE childTypeId = ?;'
let SQL2 = 'DELETE FROM type_childtype_toolbox WHERE childTypeId = ?;'
let SQL = 'DELETE FROM child_type WHERE child_type_id = ?;'
let SQL2 = 'DELETE FROM type_childtype_toolbox WHERE child_type_id = ?;'
Mysql.query(SQL, [childTypeId], (err, result) => {
Mysql.query(SQL, [child_type_id], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -78,7 +78,7 @@ router.get('/deleteChildType', ((req, res) => {
})
return
}
Mysql.query(SQL2, [childTypeId], (err, result) => {
Mysql.query(SQL2, [child_type_id], (err, result) => {
res.send({
success: true,
})
......@@ -88,17 +88,17 @@ router.get('/deleteChildType', ((req, res) => {
}))
router.get('/updateType', (req, res) => {
const {typeId, typeName, childTypeId, childTypeName} = req.query
const {type_id, type_name, child_type_id, child_type_name} = req.query
let SQL
const values = []
if (typeId) {
SQL = 'UPDATE type SET typeName = ? WHERE typeId = ?'
values.push(typeName)
values.push(typeId)
if (type_id) {
SQL = 'UPDATE type SET type_name = ? WHERE type_id = ?'
values.push(type_name)
values.push(type_id)
} else {
SQL = 'UPDATE child_type SET childTypeName = ? WHERE childTypeId = ?'
values.push(childTypeName)
values.push(childTypeId)
SQL = 'UPDATE child_type SET child_type_name = ? WHERE child_type_id = ?'
values.push(child_type_name)
values.push(child_type_id)
}
Mysql.query(SQL, values, (err, result) => {
if (err) {
......
......@@ -3,10 +3,10 @@ const router = express.Router()
const Mysql = require('../SQLPool')
router.get('/updateToolBox', (req, res) => {
const {toolBoxName, toolBoxIcon, toolBoxUrl, toolBoxDesc, toolBoxId} = req.query
const SQL = 'UPDATE toolbox SET toolBoxName= ?, toolBoxIcon=?, toolBoxUrl=?, toolBoxDesc=? WHERE toolBoxId = ?'
const {toolbox_name, toolbox_icon, toolbox_url, toolbox_desc, toolbox_id} = req.query
const SQL = 'UPDATE toolbox SET toolbox_name= ?, toolbox_icon=?, toolbox_url=?, toolbox_desc=? WHERE toolbox_id = ?'
Mysql.query(SQL, [toolBoxName, toolBoxIcon, toolBoxUrl, toolBoxDesc, toolBoxId], (err, result) => {
Mysql.query(SQL, [toolbox_name, toolbox_icon, toolbox_url, toolbox_desc, toolbox_id], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -20,35 +20,13 @@ router.get('/updateToolBox', (req, res) => {
})
})
router.get('/updateToolBoxSort',(req, res) => {
const {sortArr} = req.query
console.log(sortArr)
res.send({
success: true,
data: sortArr
})
})
router.get('/updateChildType', (req, res) => {
const childrenTypeArr = [{id: 1, name: '运营'},{id: 2, name: '测试'},]
const SQL = 'UPDATE type SET typeContent = ? WHERE typeId = 2'
try {
Mysql.query(SQL, [JSON.stringify(childrenTypeArr)], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
})
})
} catch (e) {
console.error(e)
}
})
// router.get('/updateToolBoxSort',(req, res) => {
// const {sortArr} = req.query
// console.log(sortArr)
// res.send({
// success: true,
// data: sortArr
// })
// })
module.exports = router
......@@ -9,11 +9,11 @@ const ErrorCode = {
/* GET users listing. */
router.get('/getUser', function (req, res, next) {
let {userId} = req.cookies
if (!userId){
userId = req.query.userId
let {uid} = req.cookies
if (!uid){
uid = req.query.uid
}
// if (!userId) {
// if (!uid) {
// res.send({
// success: false,
// code: ErrorCode.USER_NOT_LOGIN,
......@@ -22,7 +22,7 @@ router.get('/getUser', function (req, res, next) {
// return
// }
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [userId], (err, result) => {
Mysql.query(SQL, [uid], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -46,9 +46,9 @@ router.get('/getUser', function (req, res, next) {
});
router.get('/login', (req, res) => {
const {userId} = req.query
const {uid} = req.query
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [userId], (err, result) => {
Mysql.query(SQL, [uid], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -57,7 +57,7 @@ router.get('/login', (req, res) => {
throw err
}
if (result[0]?.uid) {
res.cookie('userId', result[0].uid)
res.cookie('uid', result[0].uid)
res.send({
success: true,
data: '登录成功!'
......@@ -72,9 +72,9 @@ router.get('/login', (req, res) => {
})
router.get('/follow', (req, res) => {
const {follow, userId} = req.query
const {follow, uid} = req.query
const SQL = 'UPDATE user SET follow = ? WHERE uid = ?'
Mysql.query(SQL, [follow, userId], (err, result) => {
Mysql.query(SQL, [follow, uid], (err, result) => {
if (err) {
res.send({
success: false,
......
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