Commit 58e43f53 authored by zhouzihao's avatar zhouzihao

fix-修改保存问题

parent 39c8506b
......@@ -11,14 +11,14 @@ var saveJsonToDb = (json, table, key) => {
return new Promise((resovle, reject) => {
var sql = "";
if (_.has(json, key) && _.get(json, key, 0) > 0) {
var id = _.get(json, key);
_.unset(json, key);
var jsonClone = Object.assign({},json);
_.unset(jsonClone, key);
var where = {};
where[key] = id;
where[key] = _.get(json, key);;
// update
sql = db.sql.$update({
$table: table,
$set: json,
$set: jsonClone,
$where: where
});
} else {
......@@ -32,7 +32,9 @@ var saveJsonToDb = (json, table, key) => {
db.query(sql.sql, sql.values)
.then((rows) => {
// console.log(JSON.stringify(rows));
json[key] = rows.insertId;
if (rows.insertId > 0) {
json[key] = rows.insertId;
}
resovle(json);
}).catch((err) => {
reject(JSON.stringify(err));
......@@ -114,7 +116,7 @@ var countByJson = (json, table, key) => {
* @param {*} page
* @param {*} pageSize
*/
var pagedDbByJson = (json, table, items, key, page = 1, pageSize = 10,orderby="") => {
var pagedDbByJson = (json, table, items, key, page = 1, pageSize = 10, orderby = "") => {
return new Promise((resovle, reject) => {
countByJson(json, table, key)
.then((len) => {
......@@ -123,7 +125,7 @@ var pagedDbByJson = (json, table, items, key, page = 1, pageSize = 10,orderby=""
$limit: pageSize,
$offset: (page - 1) * pageSize,
}
if (!_.isEmpty){
if (!_.isEmpty) {
extra['$orderby'] = orderby;
}
return listDbByJson(json, table, items, extra).then((data) => {
......
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