c2-mongoose 2.1.130 → 2.1.132

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.
@@ -288,7 +288,11 @@ var SearchFlow = /** @class */ (function () {
288
288
  var transformedObject = {};
289
289
  for (var key in originalObject) {
290
290
  if (key.startsWith('metadata-')) {
291
- metadata[key.replace("metadata-", "")] = originalObject[key][0];
291
+ if (originalObject[key].length === 1) {
292
+ metadata[key.replace("metadata-", "")] = originalObject[key][0];
293
+ continue;
294
+ }
295
+ metadata[key.replace("metadata-", "")] = originalObject[key];
292
296
  }
293
297
  else {
294
298
  transformedObject[key] = originalObject[key];
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class BuildPipelineToCountJoinFlowItem {
3
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[];
4
+ }
5
+ declare const _default: BuildPipelineToCountJoinFlowItem;
6
+ export default _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BuildPipelineToCountJoinFlowItem = /** @class */ (function () {
4
+ function BuildPipelineToCountJoinFlowItem() {
5
+ }
6
+ BuildPipelineToCountJoinFlowItem.prototype.build = function (joinWith, fieldTarget) {
7
+ return [
8
+ {
9
+ $lookup: {
10
+ from: joinWith.collection.name,
11
+ let: { localField: '$_id' },
12
+ pipeline: [
13
+ {
14
+ $match: {
15
+ $expr: { $eq: ["$".concat(fieldTarget), '$$localField'] }
16
+ }
17
+ },
18
+ {
19
+ $count: 'totalCount'
20
+ }
21
+ ],
22
+ as: 'matchedDocuments'
23
+ }
24
+ },
25
+ {
26
+ $addFields: {
27
+ totalProducts: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
28
+ }
29
+ },
30
+ {
31
+ $project: {
32
+ matchedDocuments: 0
33
+ }
34
+ }
35
+ ];
36
+ };
37
+ return BuildPipelineToCountJoinFlowItem;
38
+ }());
39
+ exports.default = new BuildPipelineToCountJoinFlowItem;
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class BuildPipelineToJoinFlowItem {
3
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[];
4
+ }
5
+ declare const _default: BuildPipelineToJoinFlowItem;
6
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BuildPipelineToJoinFlowItem = /** @class */ (function () {
4
+ function BuildPipelineToJoinFlowItem() {
5
+ }
6
+ BuildPipelineToJoinFlowItem.prototype.build = function (joinWith, fieldTarget) {
7
+ return [
8
+ {
9
+ $lookup: {
10
+ from: joinWith.collection.name,
11
+ let: { localField: '$_id' },
12
+ pipeline: [
13
+ {
14
+ $match: {
15
+ $expr: { $eq: ["$".concat(fieldTarget), '$$localField'] }
16
+ }
17
+ }
18
+ ],
19
+ as: "".concat(joinWith.collection.name)
20
+ }
21
+ }
22
+ ];
23
+ };
24
+ return BuildPipelineToJoinFlowItem;
25
+ }());
26
+ exports.default = new BuildPipelineToJoinFlowItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.130",
3
+ "version": "2.1.132",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -253,7 +253,11 @@ abstract class SearchFlow {
253
253
 
254
254
  for (const key in originalObject) {
255
255
  if (key.startsWith('metadata-')) {
256
- metadata[key.replace("metadata-", "")] = originalObject[key][0];
256
+ if (originalObject[key].length === 1) {
257
+ metadata[key.replace("metadata-", "")] = originalObject[key][0]
258
+ continue
259
+ }
260
+ metadata[key.replace("metadata-", "")] = originalObject[key]
257
261
  } else {
258
262
  transformedObject[key] = originalObject[key];
259
263
  }
@@ -0,0 +1,37 @@
1
+ import mongoose from "mongoose"
2
+
3
+ class BuildPipelineToCountJoinFlowItem {
4
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[] {
5
+ return [
6
+ {
7
+ $lookup: {
8
+ from: joinWith.collection.name,
9
+ let: { localField: '$_id' },
10
+ pipeline: [
11
+ {
12
+ $match: {
13
+ $expr: { $eq: [`$${fieldTarget}`, '$$localField'] }
14
+ }
15
+ },
16
+ {
17
+ $count: 'totalCount'
18
+ }
19
+ ],
20
+ as: 'matchedDocuments'
21
+ }
22
+ },
23
+ {
24
+ $addFields: {
25
+ totalProducts: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
26
+ }
27
+ },
28
+ {
29
+ $project: {
30
+ matchedDocuments: 0
31
+ }
32
+ }
33
+ ]
34
+ }
35
+ }
36
+
37
+ export default new BuildPipelineToCountJoinFlowItem
@@ -0,0 +1,24 @@
1
+ import mongoose from "mongoose"
2
+
3
+ class BuildPipelineToJoinFlowItem {
4
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[] {
5
+ return [
6
+ {
7
+ $lookup: {
8
+ from: joinWith.collection.name,
9
+ let: { localField: '$_id' },
10
+ pipeline: [
11
+ {
12
+ $match: {
13
+ $expr: { $eq: [`$${fieldTarget}`, '$$localField'] }
14
+ }
15
+ }
16
+ ],
17
+ as: `${joinWith.collection.name}`
18
+ }
19
+ }
20
+ ]
21
+ }
22
+ }
23
+
24
+ export default new BuildPipelineToJoinFlowItem