@less-is-more/less-js 1.2.1 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@less-is-more/less-js",
3
- "version": "1.2.1",
3
+ "version": "1.2.5",
4
4
  "description": "Fast develop kit for nodejs",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/db.js CHANGED
@@ -84,13 +84,15 @@ module.exports = class Db {
84
84
  * @param {*} oldData 旧数据
85
85
  * @param {*} keyColumn 比对列
86
86
  * @param {*} needDelete 是否需要删除多余的
87
+ * @param {*} compareColumn 比较列有没有变化
87
88
  */
88
89
  static async fullUpdate(
89
90
  model,
90
91
  newData = [],
91
92
  oldData = [],
92
93
  keyColumn,
93
- needDelete = false
94
+ needDelete = false,
95
+ compareColumn = []
94
96
  ) {
95
97
  for (let nNewData of newData) {
96
98
  let nOldIndex = oldData.findIndex(
@@ -99,10 +101,24 @@ module.exports = class Db {
99
101
  if (nOldIndex === -1) {
100
102
  await this.add(model, nNewData);
101
103
  } else {
102
- let where = {};
103
- where[keyColumn] = nNewData[keyColumn];
104
- await this.update(model, nNewData, where);
105
- oldData.splice(nOldIndex, 1);
104
+ let needUpdate = false;
105
+ if ( compareColumn.length > 0) {
106
+ const nOldData = oldData[nOldIndex];
107
+ for (let nColumn of compareColumn) {
108
+ if (nOldData[nColumn] !== nNewData[nColumn]) {
109
+ needUpdate = true;
110
+ break;
111
+ }
112
+ }
113
+ } else {
114
+ needUpdate = true;
115
+ }
116
+ if (needUpdate) {
117
+ let where = {};
118
+ where[keyColumn] = nNewData[keyColumn];
119
+ await this.update(model, nNewData, where);
120
+ oldData.splice(nOldIndex, 1);
121
+ }
106
122
  }
107
123
  }
108
124
  // 删除旧剩余的
package/src/gen.js CHANGED
@@ -5,7 +5,6 @@ const ejs = require("ejs");
5
5
  const fs = require("fs");
6
6
  const inquirer = require("inquirer");
7
7
  const fse = require("fs-extra");
8
- const { dirname } = require("path");
9
8
 
10
9
  const modelNames = fs
11
10
  .readdirSync(path.join(process.cwd(), "/src/models"))
package/src/router.js CHANGED
@@ -31,10 +31,18 @@ module.exports = class Router {
31
31
  "queries:",
32
32
  req.queries ? JSON.stringify(req.queries) : ""
33
33
  );
34
+ const isFile = JSON.stringify(req.headers).includes(
35
+ "multipart/form-data"
36
+ );
37
+ console.log("multipart:", isFile);
34
38
  if (req.method == "POST") {
35
39
  let data = await promisify(body)(req);
36
- console.log("body: " + decodeURIComponent(data));
37
- req.body = querystring.parse(decodeURIComponent(data));
40
+ if (isFile) {
41
+ req.body = data.toString();
42
+ } else {
43
+ console.log("body: " + decodeURIComponent(data));
44
+ req.body = querystring.parse(decodeURIComponent(data));
45
+ }
38
46
  }
39
47
  req.params = {};
40
48
  if (!Param.isBlank(req.queries)) {
@@ -42,7 +50,7 @@ module.exports = class Router {
42
50
  (n) => (req.params[n] = req.queries[n])
43
51
  );
44
52
  }
45
- if (!Param.isBlank(req.body)) {
53
+ if (!Param.isBlank(req.body) && !isFile) {
46
54
  Object.keys(req.body).forEach((n) => (req.params[n] = req.body[n]));
47
55
  }
48
56
  // before