@bee.js/node 0.0.84 → 0.0.85

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/beehive.js CHANGED
@@ -372,8 +372,6 @@ module.exports = function hive(req = {}, res = {}, model = null) {
372
372
  },
373
373
 
374
374
  insert: async function (_data, params = {}) {
375
- //data = beeORM.forceData(data, req)
376
-
377
375
  if (model.relations && params.relations)
378
376
  await Promise.all(
379
377
  Object.keys(model.relations).map(async (field) => {
@@ -401,10 +399,10 @@ module.exports = function hive(req = {}, res = {}, model = null) {
401
399
  })
402
400
  );
403
401
 
404
- let onlyFields = script[0].fields.concat(
402
+ const onlyFields = script[0].fields.concat(
405
403
  (req.onlyFields || {})[model.table] || []
406
404
  );
407
- let sql = beeORM.sqlInsertUpdate(model, _data, onlyFields, "INSERT");
405
+ const sql = beeORM.sqlInsertUpdate(model, _data, onlyFields, "INSERT");
408
406
 
409
407
  _data = await dbExec(sql.SQL, sql.binds);
410
408
 
@@ -415,21 +413,17 @@ module.exports = function hive(req = {}, res = {}, model = null) {
415
413
  },
416
414
 
417
415
  update: async function (data, ids = []) {
418
- // TODO criar auditoria
419
-
420
- //data = beeORM.forceData(data, req)
421
-
422
- let onlyFields = script[0].fields.concat(
416
+ const onlyFields = script[0].fields.concat(
423
417
  (req.onlyFields || {})[model.table] || []
424
418
  );
425
- let sql = beeORM.sqlInsertUpdate(model, data, onlyFields, "UPDATE");
419
+ const sql = beeORM.sqlInsertUpdate(model, data, onlyFields, "UPDATE");
426
420
 
427
421
  sql.SQL += beeORM.modelSqlWhere(model, ids, req.middleware);
428
422
  sql.SQL += script[0]["where"].length
429
423
  ? (!ids.length ? " WHERE " : " AND ") + script[0]["where"].join(" AND ")
430
424
  : "";
431
425
 
432
- data = await dbExec(sql.SQL, script[0]["binds"]);
426
+ data = await dbExec(sql.SQL, sql.binds);
433
427
 
434
428
  return { ...this, result: { ...sql.result, ...data } };
435
429
  },
package/lib/ORM/beeORM.js CHANGED
@@ -216,6 +216,15 @@ module.exports = {
216
216
 
217
217
  data = data[0] ? data : [data];
218
218
 
219
+ const sanitizeString = (val) => {
220
+ return typeof val === "string" ? val.replace(/\0/g, "") : val;
221
+ };
222
+
223
+ const normalizeDate = (val) => {
224
+ if (!val || val === "" || isNaN(new Date(val).getTime())) return null;
225
+ return val;
226
+ };
227
+
219
228
  Object.keys(data).map((key) => {
220
229
  for (let field in model.schema) {
221
230
  field = { ...model.schema[field], name: field };
@@ -242,26 +251,24 @@ module.exports = {
242
251
  switch (type) {
243
252
  case "guid":
244
253
  case "uuid":
245
- value = `UUID_TO_BIN('${value}')`; //TODO mssql
246
- break;
247
- case "binary":
248
- value = value;
249
- break;
250
- case "file":
251
254
  binds.push(value);
252
- value = "?";
255
+ value = `UUID_TO_BIN(?)`;
253
256
  break;
254
257
  case "date":
255
258
  case "datetime":
256
259
  case "time":
257
260
  case "timestamp":
258
- value = value ? q(value, "''") : "null";
261
+ binds.push(normalizeDate(value));
262
+ value = "?";
259
263
  break;
264
+ case "binary":
265
+ case "file":
260
266
  default:
261
- value = q(value, "''");
267
+ binds.push(value);
268
+ value = "?";
262
269
  }
263
270
 
264
- if (field.onInput) value = field.onInput + "(" + value + ")";
271
+ if (field.onInput) value = `${field.onInput}(${value})`; //example md5()
265
272
 
266
273
  if (statement === "INSERT") {
267
274
  if (key == 0) fields.push(q(field.name));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.84",
3
+ "version": "0.0.85",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {