@chevre/domain 21.8.0-alpha.46 → 21.8.0-alpha.47
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.
|
@@ -8,19 +8,28 @@ async function main() {
|
|
|
8
8
|
|
|
9
9
|
const aggregateOfferRepo = new chevre.repository.AggregateOffer(mongoose.connection);
|
|
10
10
|
|
|
11
|
-
const offers = await aggregateOfferRepo.search(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
const offers = await aggregateOfferRepo.search(
|
|
12
|
+
{
|
|
13
|
+
limit: 10,
|
|
14
|
+
// page: 1,
|
|
15
|
+
project: { id: { $eq: String(process.env.PROJECT_ID) } },
|
|
16
|
+
availability: { $eq: chevre.factory.itemAvailability.InStock },
|
|
17
|
+
itemOffered: { typeOf: { $eq: chevre.factory.product.ProductType.EventService } },
|
|
18
|
+
// identifier: { $eq: '901' },
|
|
19
|
+
sort: {
|
|
20
|
+
'priceSpecification.price': 1,
|
|
21
|
+
identifier: 1
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 1,
|
|
26
|
+
identifier: 1,
|
|
27
|
+
name: 1,
|
|
28
|
+
priceSpecification: 1
|
|
21
29
|
}
|
|
22
|
-
|
|
30
|
+
);
|
|
23
31
|
console.log(offers);
|
|
32
|
+
console.log(offers[0]?.offers);
|
|
24
33
|
console.log(offers.map((offer) => {
|
|
25
34
|
return `${offer.project.id} ${(<any>offer).offerCount} ${offer.offers[0].identifier} ${offer.offers[0].name.ja} ${offer.offers[0].priceSpecification.price}`;
|
|
26
35
|
}));
|
|
@@ -391,7 +391,7 @@ class MongoRepository {
|
|
|
391
391
|
return matchStages;
|
|
392
392
|
}
|
|
393
393
|
static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
|
|
394
|
-
|
|
394
|
+
let projectStage = {
|
|
395
395
|
_id: 0,
|
|
396
396
|
id: '$_id',
|
|
397
397
|
typeOf: '$typeOf',
|
|
@@ -406,16 +406,21 @@ class MongoRepository {
|
|
|
406
406
|
const negativeProjectionFields = Object.keys(params)
|
|
407
407
|
.filter((key) => params[key] === 0);
|
|
408
408
|
if (positiveProjectionFields.length > 0) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
409
|
+
projectStage = {
|
|
410
|
+
_id: 0,
|
|
411
|
+
id: '$_id',
|
|
412
|
+
typeOf: '$typeOf',
|
|
413
|
+
project: '$project',
|
|
414
|
+
// offers: [{ $first: '$offers' }],
|
|
415
|
+
highPrice: { $max: '$offers.priceSpecification.price' },
|
|
416
|
+
lowPrice: { $min: '$offers.priceSpecification.price' },
|
|
417
|
+
offerCount: { $size: '$offers' }
|
|
418
|
+
};
|
|
419
|
+
const offersProjection = {};
|
|
420
|
+
positiveProjectionFields.forEach((field) => {
|
|
421
|
+
offersProjection[field] = { $first: `$offers.${field}` };
|
|
422
|
+
});
|
|
423
|
+
projectStage.offers = [offersProjection];
|
|
419
424
|
}
|
|
420
425
|
else if (negativeProjectionFields.length > 0) {
|
|
421
426
|
negativeProjectionFields.forEach((field) => {
|
package/package.json
CHANGED