@nextage/nx-frame-be 1.0.11 → 1.0.13

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.
@@ -64,6 +64,20 @@ export declare abstract class BaseController<TAttrs, TDoc extends BaseMongoDoc,
64
64
  * @param item
65
65
  * @param context
66
66
  */
67
+ protected parseCreateItem(item: TAttrs, context: NxContext): Promise<void>;
68
+ /**
69
+ *
70
+ * @param id
71
+ * @param item
72
+ * @param context
73
+ */
74
+ protected parseUpdateItem(id: string, item: TAttrs, context: NxContext): Promise<void>;
75
+ /**
76
+ *
77
+ * @param item
78
+ * @param context
79
+ * @returns
80
+ */
67
81
  protected parseItem(item: TAttrs, context: NxContext): Promise<void>;
68
82
  /**
69
83
  *
@@ -57,8 +57,31 @@ class BaseController {
57
57
  * @param item
58
58
  * @param context
59
59
  */
60
+ parseCreateItem(item, context) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ this.parseItem(item, context);
63
+ });
64
+ }
65
+ /**
66
+ *
67
+ * @param id
68
+ * @param item
69
+ * @param context
70
+ */
71
+ parseUpdateItem(id, item, context) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ this.parseItem(item, context);
74
+ });
75
+ }
76
+ /**
77
+ *
78
+ * @param item
79
+ * @param context
80
+ * @returns
81
+ */
60
82
  parseItem(item, context) {
61
83
  return __awaiter(this, void 0, void 0, function* () {
84
+ return;
62
85
  });
63
86
  }
64
87
  /**
@@ -78,7 +101,7 @@ class BaseController {
78
101
  */
79
102
  create(item, context) {
80
103
  return __awaiter(this, void 0, void 0, function* () {
81
- yield this.parseItem(item, context);
104
+ yield this.parseCreateItem(item, context);
82
105
  return this.model.create(item, context);
83
106
  });
84
107
  }
@@ -91,7 +114,7 @@ class BaseController {
91
114
  */
92
115
  update(id, item, context) {
93
116
  return __awaiter(this, void 0, void 0, function* () {
94
- yield this.parseItem(item, context);
117
+ yield this.parseUpdateItem(id, item, context);
95
118
  return this.model.update(id, item, this.mergeUpdate, context);
96
119
  });
97
120
  }
@@ -432,8 +432,13 @@ class BaseModel extends events_1.EventEmitter {
432
432
  if (!itemDoc)
433
433
  throw new errors_1.AppError('messages.notFound');
434
434
  // complete merge
435
- if (mergeItem)
436
- item = (0, utils_1.merge)(itemDoc.toObject(), item); // Merge with existing doc
435
+ if (mergeItem) {
436
+ // item = merge (itemDoc.toObject(), item); // Merge with existing doc
437
+ item = (0, utils_1.merge)(itemDoc.toObject(), item, (objValue, srcValue) => {
438
+ if (Array.isArray(objValue))
439
+ return srcValue; // sovrascrivi invece di mergiare
440
+ });
441
+ }
437
442
  itemDoc === null || itemDoc === void 0 ? void 0 : itemDoc.set(item);
438
443
  const res = yield itemDoc.save();
439
444
  if (context)
@@ -336,7 +336,7 @@ export declare function uniqBy(arr: any[], iteratee: Function): any[];
336
336
  * @param {*} obj2
337
337
  * @returns
338
338
  */
339
- export declare function merge(obj1: any, obj2: any): any;
339
+ export declare function merge(obj1: any, obj2: any, mergeFnc?: Function): any;
340
340
  /**
341
341
  *
342
342
  * @param data
@@ -709,10 +709,10 @@ exports.uniqBy = uniqBy;
709
709
  * @param {*} obj2
710
710
  * @returns
711
711
  */
712
- function merge(obj1, obj2) {
712
+ function merge(obj1, obj2, mergeFnc) {
713
713
  if (!isObject(obj1) || !isObject(obj2))
714
714
  return;
715
- return lodash_1.default.merge(obj1, obj2);
715
+ return mergeFnc ? lodash_1.default.mergeWith(obj1, obj2, mergeFnc) : lodash_1.default.merge(obj1, obj2);
716
716
  }
717
717
  exports.merge = merge;
718
718
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextage/nx-frame-be",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",