Commit b88e5275 authored by ganjingcun's avatar ganjingcun

deckinfo

parent 3caa8a15
......@@ -16,17 +16,17 @@ app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
//allow custom header and CORS
// app.all('*', function (req, res, next) {
// res.header('Access-Control-Allow-Origin', '*');
// // res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
// res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
// if (req.method == 'OPTIONS') {
// res.send(200);
// }
// else {
// next();
// }
// });
app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
// res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
res.sendStatus(200);
}
else {
next();
}
});
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
......
......@@ -13,6 +13,7 @@
"eventproxy": "^0.3.5",
"express": "~4.14.0",
"jade": "~1.11.0",
"moment": "^2.18.1",
"morgan": "~1.7.0",
"pg": "^6.1.0",
"serve-favicon": "~2.3.0",
......
......@@ -7,6 +7,7 @@ var pg = require('pg')
var eventproxy = require('eventproxy')
var utils = require('../utils/utils')
var sqlite3 = require('sqlite3').verbose();
var moment = require('moment')
var config = require('../db.config')
var cardinfo = require('../cardinfo')
......@@ -325,7 +326,7 @@ router.get('/cardinfo', function (req, res) {
if (row.level <= 12) {
result.level = row.level
}else {
} else {
//转化为16位,0x01010004,前2位是左刻度,2-4是右刻度,末2位是等级
var levelHex = parseInt(row.level, 10).toString(16);
cardLevel = parseInt(levelHex.slice(-2), 16);
......@@ -349,6 +350,98 @@ router.get('/cardinfo', function (req, res) {
});
});
router.get('/deckinfo', function (req, res) {
var name = req.query.name
if (!name) {
return res.status(404).send('deck name is required!')
}
// to run a query we can acquire a client from the pool,
// run a query on the client, and then return the client to the pool
pool.connect(function (err, client, done) {
if (err) {
return console.error('error fetching client from pool', err);
}
var sql = `SELECT * from deck_info where name = '${name}'`
console.log(sql);
client.query(sql, function (err, result) {
done()
var response = {};
if (!result || result.rowCount === 0) {
response.code = 404
} else {
response.code = 200
response.data = result.rows[0]
}
res.json(response);
});
});
});
router.post('/deckinfo', function (req, res) {
let user = req.body.user;
let name = req.body.name;
let desc = req.body.desc;
let img_url = req.body.url;
let isNew = req.body.isNew;
console.log("user is", user)
console.log("name is", name)
console.log("desc is", desc)
console.log("img_url is", img_url)
console.log("isNew is", isNew)
console.log("isNew is", typeof isNew)
if (!name) {
return res.status(404).send('deck name is required!')
}
// to run a query we can acquire a client from the pool,
// run a query on the client, and then return the client to the pool
pool.connect(function (err, client, done) {
if (err) {
return console.error('error fetching client from pool', err);
}
var sql;
if (isNew === "true") {
var start_time = moment().format('YYYY-MM-DD HH:mm')
sql = `insert into deck_info (name, content, url, start_time) values (
'${name}',
'${desc}',
'${img_url}',
'${start_time}'
)`;
} else {
var end_time = moment().format('YYYY-MM-DD HH:mm')
sql = `update deck_info set
content = '${desc}',
url = '${img_url}',
end_time = '${end_time}'
where name = '${name}'`;
}
console.log(sql);
client.query(sql, function (err, result) {
var response = {};
if (err) {
response.code = 500;
} else {
response.code = 200;
}
res.json(response);
});
});
});
router.get('/history', function (req, res) {
// to run a query we can acquire a client from the pool,
// run a query on the client, and then return the client to the pool
......
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