hola-server 0.3.8 → 0.3.10

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/core/meta.js CHANGED
@@ -74,7 +74,7 @@ const validate_field = (meta, field) => {
74
74
  const keys = Object.keys(field);
75
75
  keys.forEach(key => {
76
76
  if (!field_attrs.includes(key)) {
77
- throw new Error("The attribute [" + key + "] isn't supported now for field:" + field + " and meta:" + meta.collection);
77
+ throw new Error("The attribute [" + key + "] isn't supported now for field:" + JSON.stringify(field) + " and meta:" + meta.collection);
78
78
  }
79
79
  });
80
80
  }
package/db/db.js CHANGED
@@ -27,7 +27,7 @@ const log_msg = (category, level, msg) => {
27
27
  const path = req ? req.originalUrl : "";
28
28
  const user = req && req.session && req.session.user ? req.session.user.id : "";
29
29
 
30
- db.create(col_log, { time: time, category: category, level: level, msg: msg, user: user, path: path }).then(() => {});
30
+ db.create(col_log, { time: time, category: category, level: level, msg: msg, user: user, path: path }).then(() => { });
31
31
  };
32
32
 
33
33
  const is_log_debug = () => {
@@ -124,6 +124,7 @@ const bulk_update = async (col, items, attrs) => {
124
124
  attrs.forEach(function (attr) {
125
125
  query[attr] = item[attr];
126
126
  });
127
+ delete item["_id"];
127
128
  bulk.find(query).upsert().update({ $set: item }, true);
128
129
  }
129
130
  return await bulk.execute();
@@ -152,6 +153,7 @@ class DB {
152
153
  */
153
154
  create(code, obj) {
154
155
  const col = this.db[code];
156
+ delete obj["_id"];
155
157
  return col.insert(obj, { checkKeys: false });
156
158
  }
157
159
 
@@ -168,6 +170,7 @@ class DB {
168
170
  }
169
171
 
170
172
  const col = this.db[code];
173
+ delete obj["_id"];
171
174
  return col.update(query, { $set: obj }, { upsert: true, multi: true });
172
175
  }
173
176
 
package/db/entity.js CHANGED
@@ -297,7 +297,7 @@ class Entity {
297
297
  * @param {param obj from user input} param_obj
298
298
  * @returns object with code and err
299
299
  */
300
- async clone_entity(param_obj) {
300
+ async clone_entity(_id, param_obj) {
301
301
  const fields = this.meta.clone_fields
302
302
  const { obj, error_field_names } = convert_type(param_obj, fields);
303
303
  if (error_field_names.length > 0) {
@@ -309,7 +309,7 @@ class Entity {
309
309
  }
310
310
 
311
311
  if (this.meta.before_clone) {
312
- const { code, err } = await this.meta.before_clone(this, obj);
312
+ const { code, err } = await this.meta.before_clone(_id, this, obj);
313
313
  if (err || code != SUCCESS) {
314
314
  if (is_log_error()) {
315
315
  log_error(LOG_ENTITY, "before_clone error:" + JSON.stringify(err) + ", with code:" + code);
@@ -342,7 +342,7 @@ class Entity {
342
342
  }
343
343
 
344
344
  if (this.meta.clone) {
345
- const { code, err } = await this.meta.clone(this, obj);
345
+ const { code, err } = await this.meta.clone(_id, this, obj);
346
346
  if (err || code != SUCCESS) {
347
347
  if (is_log_error()) {
348
348
  log_error(LOG_ENTITY, "clone error:" + JSON.stringify(err) + ", with code:" + code);
@@ -360,7 +360,7 @@ class Entity {
360
360
  }
361
361
 
362
362
  if (this.meta.after_clone) {
363
- const { code, err } = await this.meta.after_clone(this, obj);
363
+ const { code, err } = await this.meta.after_clone(_id, this, obj);
364
364
  if (err || code != SUCCESS) {
365
365
  if (is_log_error()) {
366
366
  log_error(LOG_ENTITY, "after_clone error:" + JSON.stringify(err) + ", with code:" + code);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hola-server",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/router/clone.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const { set_file_fields, save_file_fields_to_db } = require('../db/gridfs');
2
- const { SUCCESS } = require('../http/code');
2
+ const { SUCCESS, NO_PARAMS } = require('../http/code');
3
3
  const { get_session_userid } = require('../http/session');
4
4
  const { wrap_http } = require('../http/error');
5
- const { post_params } = require('../http/params');
5
+ const { post_params, required_post_params } = require('../http/params');
6
6
  const { has_value } = require('../core/validate');
7
7
  const { Entity } = require('../db/entity');
8
8
 
@@ -19,6 +19,12 @@ const init_clone_router = function (router, meta) {
19
19
  const cp_upload = meta.upload_fields.length > 0 ? upload_file.fields(meta.upload_fields) : upload_file.none();
20
20
 
21
21
  router.post('/clone', cp_upload, wrap_http(async function (req, res) {
22
+ let params = required_post_params(req, ["_id"]);
23
+ if (params === null) {
24
+ res.json({ code: NO_PARAMS, err: '[_id] checking params are failed!' });
25
+ return;
26
+ }
27
+
22
28
  const param_obj = post_params(req, meta.field_names);
23
29
  set_file_fields(meta, req, param_obj);
24
30
 
@@ -30,7 +36,7 @@ const init_clone_router = function (router, meta) {
30
36
  param_obj[meta.user_field] = user_id;
31
37
  }
32
38
 
33
- const { code, err } = await entity.clone_entity(param_obj);
39
+ const { code, err } = await entity.clone_entity(params["_id"], param_obj);
34
40
  if (!has_value(code)) {
35
41
  throw new Error("the method should return code");
36
42
  }