@chevre/domain 21.8.0 → 21.9.0-alpha.0
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.
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const offerRepo = new chevre.repository.Offer(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const result = await offerRepo.searchAvaialbleAppliesToMovieTicketByOfferCatalogId({
|
|
12
|
+
limit: 10,
|
|
13
|
+
page: 1,
|
|
14
|
+
subOfferCatalog: {
|
|
15
|
+
id: '0001'
|
|
16
|
+
},
|
|
17
|
+
excludeAppliesToMovieTicket: false,
|
|
18
|
+
unacceptedPaymentMethod: []
|
|
19
|
+
});
|
|
20
|
+
console.log(result);
|
|
21
|
+
console.log(result.length);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
main()
|
|
25
|
+
.then(console.log)
|
|
26
|
+
.catch(console.error);
|
|
@@ -18,7 +18,7 @@ export declare class MongoRepository {
|
|
|
18
18
|
private readonly aggregateOfferModel;
|
|
19
19
|
private readonly offerCatalogModel;
|
|
20
20
|
constructor(connection: Connection);
|
|
21
|
-
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: factory.unitPriceOffer.ISearchConditions): IMatchStage[];
|
|
21
|
+
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): IMatchStage[];
|
|
22
22
|
static CREATE_AGGREGATE_OFFERS_PROJECTION(params: IProjection): {
|
|
23
23
|
[field: string]: AnyExpression;
|
|
24
24
|
};
|
|
@@ -92,6 +92,25 @@ export declare class MongoRepository {
|
|
|
92
92
|
*/
|
|
93
93
|
sortedOfferIds: string[];
|
|
94
94
|
}>;
|
|
95
|
+
/**
|
|
96
|
+
* カタログに記載されたオファーにおいて利用可能な決済方法区分を検索する
|
|
97
|
+
*/
|
|
98
|
+
searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params: {
|
|
99
|
+
subOfferCatalog: {
|
|
100
|
+
/**
|
|
101
|
+
* サブカタログID
|
|
102
|
+
*/
|
|
103
|
+
id: string;
|
|
104
|
+
};
|
|
105
|
+
availableAtOrFrom?: {
|
|
106
|
+
id?: string;
|
|
107
|
+
};
|
|
108
|
+
unacceptedPaymentMethod?: string[];
|
|
109
|
+
excludeAppliesToMovieTicket: boolean;
|
|
110
|
+
onlyValid?: boolean;
|
|
111
|
+
limit?: number;
|
|
112
|
+
page?: number;
|
|
113
|
+
}): Promise<Pick<factory.priceSpecification.unitPrice.IAppliesToMovieTicket, 'serviceOutput'>[]>;
|
|
95
114
|
findAggregateOfferById(params: {
|
|
96
115
|
project: {
|
|
97
116
|
id: string;
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -535,6 +535,48 @@ class MongoRepository {
|
|
|
535
535
|
return { offers, sortedOfferIds };
|
|
536
536
|
});
|
|
537
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* カタログに記載されたオファーにおいて利用可能な決済方法区分を検索する
|
|
540
|
+
*/
|
|
541
|
+
searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params) {
|
|
542
|
+
var _a;
|
|
543
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
544
|
+
const searchOffersConditions = Object.assign(Object.assign({ includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
545
|
+
? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
|
|
546
|
+
: undefined), { priceSpecification: {
|
|
547
|
+
appliesToMovieTicket: Object.assign({
|
|
548
|
+
// 基本は適用決済カード区分有のみ検索
|
|
549
|
+
serviceType: { $exists: (!params.excludeAppliesToMovieTicket === true) } }, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
|
|
550
|
+
? { serviceOutput: { typeOf: { $nin: params.unacceptedPaymentMethod } } }
|
|
551
|
+
: undefined)
|
|
552
|
+
}, onlyValid: params.onlyValid === true });
|
|
553
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(searchOffersConditions);
|
|
554
|
+
const aggregate = this.aggregateOfferModel.aggregate([
|
|
555
|
+
{ $unwind: { path: '$offers' } },
|
|
556
|
+
{ $unwind: { path: '$offers.priceSpecification.appliesToMovieTicket' } },
|
|
557
|
+
...matchStages,
|
|
558
|
+
{
|
|
559
|
+
$group: {
|
|
560
|
+
_id: '$offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf',
|
|
561
|
+
appliesToMovieTicket: { $first: '$offers.priceSpecification.appliesToMovieTicket' }
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
{ $sort: { _id: factory.sortType.Ascending } },
|
|
565
|
+
{
|
|
566
|
+
$project: {
|
|
567
|
+
_id: 0,
|
|
568
|
+
serviceOutput: { typeOf: '$_id' }
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
]);
|
|
572
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
573
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
574
|
+
aggregate.limit(params.limit * page)
|
|
575
|
+
.skip(params.limit * (page - 1));
|
|
576
|
+
}
|
|
577
|
+
return aggregate.exec();
|
|
578
|
+
});
|
|
579
|
+
}
|
|
538
580
|
findAggregateOfferById(params) {
|
|
539
581
|
return __awaiter(this, void 0, void 0, function* () {
|
|
540
582
|
const doc = yield this.aggregateOfferModel.findOne({
|
package/package.json
CHANGED