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.
- package/dist/flow/SearchFlow.js +5 -1
- package/dist/flow/item/BuildPipelineToCountJoinFlowItem.d.ts +6 -0
- package/dist/flow/item/BuildPipelineToCountJoinFlowItem.js +39 -0
- package/dist/flow/item/BuildPipelineToJoinFlowItem.d.ts +6 -0
- package/dist/flow/item/BuildPipelineToJoinFlowItem.js +26 -0
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +5 -1
- package/src/flow/item/BuildPipelineToCountJoinFlowItem.ts +37 -0
- package/src/flow/item/BuildPipelineToJoinFlowItem.ts +24 -0
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -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
|
-
|
|
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,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,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
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -253,7 +253,11 @@ abstract class SearchFlow {
|
|
|
253
253
|
|
|
254
254
|
for (const key in originalObject) {
|
|
255
255
|
if (key.startsWith('metadata-')) {
|
|
256
|
-
|
|
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
|