@chevre/domain 21.8.0-alpha.8 → 21.8.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.
- package/example/src/chevre/countOffers.ts +32 -0
- package/example/src/chevre/findItemListElementByCatalogId.ts +30 -0
- package/example/src/chevre/importOffersFromCOA.ts +7 -1
- package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
- package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
- package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -0
- package/example/src/chevre/optimizeCatalogs.ts +54 -0
- package/example/src/chevre/processPay.ts +3 -4
- package/example/src/chevre/publishPermitOwnershipInfoToken.ts +56 -0
- package/example/src/chevre/pullAddOnsFromOffer.ts +26 -0
- package/example/src/chevre/pushIncludedInDataCatalog.ts +47 -0
- package/example/src/chevre/searchAggregateOffers.ts +48 -0
- package/example/src/chevre/searchEventTicketOffers.ts +5 -1
- package/example/src/chevre/searchEvents.ts +9 -7
- package/example/src/chevre/searchOfferCatalogs.ts +7 -3
- package/example/src/chevre/searchOffers.ts +5 -2
- package/example/src/chevre/searchOffersByCatalog.ts +15 -9
- package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
- package/example/src/chevre/searchOrders.ts +9 -7
- package/example/src/chevre/syncCatalogs2aggregateOffers.ts +85 -0
- package/lib/chevre/emailMessageBuilder.js +6 -5
- package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
- package/lib/chevre/repo/aggregateOffer.js +562 -0
- package/lib/chevre/repo/assetTransaction.d.ts +16 -1
- package/lib/chevre/repo/assetTransaction.js +54 -2
- package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +74 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +189 -0
- package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +3 -3
- package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +3 -3
- package/lib/chevre/repo/mongoose/schemas/event.d.ts +3 -3
- package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +10 -1
- package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/order.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +9 -9
- package/lib/chevre/repo/mongoose/schemas/product.d.ts +3 -3
- package/lib/chevre/repo/mongoose/schemas/project.d.ts +3 -3
- package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
- package/lib/chevre/repo/offer.d.ts +87 -51
- package/lib/chevre/repo/offer.js +513 -283
- package/lib/chevre/repo/offerCatalog.d.ts +32 -3
- package/lib/chevre/repo/offerCatalog.js +97 -10
- package/lib/chevre/repo/order.d.ts +15 -0
- package/lib/chevre/repo/order.js +58 -26
- package/lib/chevre/repo/task.d.ts +6 -2
- package/lib/chevre/repo/task.js +58 -4
- package/lib/chevre/repository.d.ts +3 -0
- package/lib/chevre/repository.js +5 -1
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +3 -41
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.d.ts +2 -0
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -40
- package/lib/chevre/service/aggregation/event/findEventOffers.d.ts +16 -0
- package/lib/chevre/service/aggregation/event/findEventOffers.js +58 -0
- package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
- package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
- package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
- package/lib/chevre/service/assetTransaction/pay.js +65 -46
- package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
- package/lib/chevre/service/assetTransaction/registerService.js +2 -1
- package/lib/chevre/service/assetTransaction/reserve.js +111 -35
- package/lib/chevre/service/offer/event/authorize.js +39 -35
- package/lib/chevre/service/offer/event/factory.d.ts +1 -1
- package/lib/chevre/service/offer/event/factory.js +8 -8
- package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
- package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +3 -0
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +48 -17
- package/lib/chevre/service/offer/event/voidTransaction.js +57 -36
- package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
- package/lib/chevre/service/offer/eventServiceByCOA/factory.js +7 -11
- package/lib/chevre/service/offer/eventServiceByCOA.js +55 -27
- package/lib/chevre/service/offer/factory.d.ts +12 -4
- package/lib/chevre/service/offer/factory.js +9 -11
- package/lib/chevre/service/offer/product/searchProductOffers.d.ts +10 -1
- package/lib/chevre/service/offer/product/searchProductOffers.js +51 -12
- package/lib/chevre/service/offer/product.d.ts +2 -0
- package/lib/chevre/service/offer/product.js +3 -2
- package/lib/chevre/service/offer.d.ts +1 -0
- package/lib/chevre/service/offer.js +7 -1
- package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
- package/lib/chevre/service/order/confirmPayTransaction.js +20 -42
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
- package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
- package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
- package/lib/chevre/service/order/onOrderStatusChanged.js +52 -9
- package/lib/chevre/service/order/payOrder.js +4 -45
- package/lib/chevre/service/order/placeOrder.js +11 -24
- package/lib/chevre/service/order.d.ts +3 -1
- package/lib/chevre/service/order.js +6 -2
- package/lib/chevre/service/payment/any/factory.js +33 -8
- package/lib/chevre/service/payment/any.js +30 -21
- package/lib/chevre/service/payment/creditCard.js +12 -12
- package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
- package/lib/chevre/service/payment/movieTicket.js +10 -11
- package/lib/chevre/service/payment/paymentCard.js +9 -12
- package/lib/chevre/service/project.js +1 -1
- package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
- package/lib/chevre/service/reserve/checkInReservation.js +3 -2
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +4 -5
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +8 -0
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +16 -11
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +3 -5
- package/lib/chevre/service/task/aggregateUseActionsOnEvent.js +2 -0
- package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
- package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
- package/lib/chevre/service/task/onAuthorizationCreated.js +5 -1
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -0
- package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +17 -0
- package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +78 -0
- package/lib/chevre/service/task/onResourceUpdated.js +12 -0
- package/lib/chevre/service/task/returnPayTransaction.js +8 -3
- package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
- package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
- package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
- package/lib/chevre/service/transaction/returnOrder.js +5 -1
- package/lib/chevre/settings.d.ts +3 -3
- package/lib/chevre/settings.js +4 -12
- package/package.json +3 -3
- package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
- package/example/src/chevre/migrateEventOrganizer.ts +0 -154
- package/lib/chevre/repo/mongoose/schemas/offer.d.ts +0 -149
- package/lib/chevre/repo/mongoose/schemas/offer.js +0 -210
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -23,354 +23,459 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.MongoRepository = void 0;
|
|
24
24
|
const uniqid = require("uniqid");
|
|
25
25
|
const factory = require("../factory");
|
|
26
|
-
const
|
|
26
|
+
const aggregateOffer_1 = require("./mongoose/schemas/aggregateOffer");
|
|
27
27
|
const offerCatalog_1 = require("./mongoose/schemas/offerCatalog");
|
|
28
|
-
const
|
|
28
|
+
const OFFERS_ARRAY_INDEX_NAME = 'offerIndex';
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* 単価オファーリポジトリ
|
|
31
31
|
*/
|
|
32
32
|
class MongoRepository {
|
|
33
33
|
constructor(connection) {
|
|
34
|
-
this.
|
|
34
|
+
this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
|
|
35
35
|
this.offerCatalogModel = connection.model(offerCatalog_1.modelName, offerCatalog_1.schema);
|
|
36
36
|
}
|
|
37
37
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
38
|
-
static
|
|
39
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33;
|
|
40
|
-
|
|
41
|
-
const andConditions = [];
|
|
38
|
+
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40;
|
|
40
|
+
const matchStages = [];
|
|
42
41
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
43
42
|
if (typeof projectIdEq === 'string') {
|
|
44
|
-
|
|
45
|
-
'project.id': {
|
|
46
|
-
$eq: projectIdEq
|
|
47
|
-
}
|
|
43
|
+
matchStages.push({
|
|
44
|
+
$match: { 'project.id': { $eq: projectIdEq } }
|
|
48
45
|
});
|
|
49
46
|
}
|
|
50
|
-
const
|
|
47
|
+
const parentOfferIdIn = (_d = (_c = params.parentOffer) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$in;
|
|
48
|
+
if (Array.isArray(parentOfferIdIn)) {
|
|
49
|
+
matchStages.push({ $match: { _id: { $in: parentOfferIdIn } } });
|
|
50
|
+
}
|
|
51
|
+
const includedInDataCatalogIdIn = (_f = (_e = params.includedInDataCatalog) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$in;
|
|
52
|
+
if (Array.isArray(includedInDataCatalogIdIn)) {
|
|
53
|
+
matchStages.push({ $match: { 'offers.includedInDataCatalog.id': { $exists: true, $in: includedInDataCatalogIdIn } } });
|
|
54
|
+
}
|
|
55
|
+
const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
51
56
|
if (typeof idEq === 'string') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
$eq: idEq
|
|
55
|
-
}
|
|
57
|
+
matchStages.push({
|
|
58
|
+
$match: { 'offers.id': { $eq: idEq } }
|
|
56
59
|
});
|
|
57
60
|
}
|
|
58
|
-
const idIn = (
|
|
61
|
+
const idIn = (_h = params.id) === null || _h === void 0 ? void 0 : _h.$in;
|
|
59
62
|
if (Array.isArray(idIn)) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$in: idIn
|
|
63
|
-
}
|
|
63
|
+
matchStages.push({
|
|
64
|
+
$match: { 'offers.id': { $in: idIn } }
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
const identifierEq = (
|
|
67
|
+
const identifierEq = (_j = params.identifier) === null || _j === void 0 ? void 0 : _j.$eq;
|
|
67
68
|
if (typeof identifierEq === 'string') {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
$exists: true,
|
|
71
|
-
$eq: identifierEq
|
|
69
|
+
matchStages.push({
|
|
70
|
+
$match: {
|
|
71
|
+
'offers.identifier': { $exists: true, $eq: identifierEq }
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
const identifierIn = (
|
|
75
|
+
const identifierIn = (_k = params.identifier) === null || _k === void 0 ? void 0 : _k.$in;
|
|
76
76
|
if (Array.isArray(identifierIn)) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$exists: true,
|
|
80
|
-
$in: identifierIn
|
|
77
|
+
matchStages.push({
|
|
78
|
+
$match: {
|
|
79
|
+
'offers.identifier': { $exists: true, $in: identifierIn }
|
|
81
80
|
}
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
|
-
const identifierRegex = (
|
|
83
|
+
const identifierRegex = (_l = params.identifier) === null || _l === void 0 ? void 0 : _l.$regex;
|
|
85
84
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
$exists: true,
|
|
89
|
-
$regex: new RegExp(identifierRegex)
|
|
85
|
+
matchStages.push({
|
|
86
|
+
$match: {
|
|
87
|
+
'offers.identifier': { $exists: true, $regex: new RegExp(identifierRegex) }
|
|
90
88
|
}
|
|
91
89
|
});
|
|
92
90
|
}
|
|
93
|
-
const nameRegex = (
|
|
91
|
+
const nameRegex = (_m = params.name) === null || _m === void 0 ? void 0 : _m.$regex;
|
|
94
92
|
if (typeof nameRegex === 'string' && nameRegex.length > 0) {
|
|
95
93
|
const nameRegexExp = new RegExp(nameRegex);
|
|
96
|
-
|
|
97
|
-
$
|
|
98
|
-
|
|
99
|
-
'name.ja': {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'name.en': {
|
|
106
|
-
$exists: true,
|
|
107
|
-
$regex: nameRegexExp
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
'alternateName.ja': {
|
|
112
|
-
$exists: true,
|
|
113
|
-
$regex: nameRegexExp
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
'alternateName.en': {
|
|
118
|
-
$exists: true,
|
|
119
|
-
$regex: nameRegexExp
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
]
|
|
94
|
+
matchStages.push({
|
|
95
|
+
$match: {
|
|
96
|
+
$or: [
|
|
97
|
+
{ 'offers.name.ja': { $exists: true, $regex: nameRegexExp } },
|
|
98
|
+
{ 'offers.name.en': { $exists: true, $regex: nameRegexExp } },
|
|
99
|
+
{ 'offers.alternateName.ja': { $exists: true, $regex: nameRegexExp } },
|
|
100
|
+
{ 'offers.alternateName.en': { $exists: true, $regex: nameRegexExp } }
|
|
101
|
+
]
|
|
102
|
+
}
|
|
123
103
|
});
|
|
124
104
|
}
|
|
125
|
-
const itemOfferedTypeOfEq = (
|
|
105
|
+
const itemOfferedTypeOfEq = (_p = (_o = params.itemOffered) === null || _o === void 0 ? void 0 : _o.typeOf) === null || _p === void 0 ? void 0 : _p.$eq;
|
|
126
106
|
if (typeof itemOfferedTypeOfEq === 'string') {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
$exists: true,
|
|
130
|
-
$eq: itemOfferedTypeOfEq
|
|
107
|
+
matchStages.push({
|
|
108
|
+
$match: {
|
|
109
|
+
'offers.itemOffered.typeOf': { $exists: true, $eq: itemOfferedTypeOfEq }
|
|
131
110
|
}
|
|
132
111
|
});
|
|
133
112
|
}
|
|
134
|
-
const categoryCodeValueIn = (
|
|
113
|
+
const categoryCodeValueIn = (_r = (_q = params.category) === null || _q === void 0 ? void 0 : _q.codeValue) === null || _r === void 0 ? void 0 : _r.$in;
|
|
135
114
|
if (Array.isArray(categoryCodeValueIn)) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
$exists: true,
|
|
139
|
-
$in: categoryCodeValueIn
|
|
115
|
+
matchStages.push({
|
|
116
|
+
$match: {
|
|
117
|
+
'offers.category.codeValue': { $exists: true, $in: categoryCodeValueIn }
|
|
140
118
|
}
|
|
141
119
|
});
|
|
142
120
|
}
|
|
143
|
-
const eligibleMembershipTypeCodeValueEq = (
|
|
121
|
+
const eligibleMembershipTypeCodeValueEq = (_t = (_s = params.eligibleMembershipType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
|
|
144
122
|
if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
123
|
+
matchStages.push({
|
|
124
|
+
$match: {
|
|
125
|
+
'offers.eligibleMembershipType.codeValue': {
|
|
126
|
+
$exists: true,
|
|
127
|
+
$eq: eligibleMembershipTypeCodeValueEq
|
|
128
|
+
}
|
|
149
129
|
}
|
|
150
130
|
});
|
|
151
131
|
}
|
|
152
|
-
const eligibleMonetaryAmountCurrencyEq = (
|
|
132
|
+
const eligibleMonetaryAmountCurrencyEq = (_v = (_u = params.eligibleMonetaryAmount) === null || _u === void 0 ? void 0 : _u.currency) === null || _v === void 0 ? void 0 : _v.$eq;
|
|
153
133
|
if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
134
|
+
matchStages.push({
|
|
135
|
+
$match: {
|
|
136
|
+
'offers.eligibleMonetaryAmount.currency': {
|
|
137
|
+
$exists: true,
|
|
138
|
+
$eq: eligibleMonetaryAmountCurrencyEq
|
|
139
|
+
}
|
|
158
140
|
}
|
|
159
141
|
});
|
|
160
142
|
}
|
|
161
|
-
const eligibleSeatingTypeCodeValueEq = (
|
|
143
|
+
const eligibleSeatingTypeCodeValueEq = (_x = (_w = params.eligibleSeatingType) === null || _w === void 0 ? void 0 : _w.codeValue) === null || _x === void 0 ? void 0 : _x.$eq;
|
|
162
144
|
if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
145
|
+
matchStages.push({
|
|
146
|
+
$match: {
|
|
147
|
+
'offers.eligibleSeatingType.codeValue': {
|
|
148
|
+
$exists: true,
|
|
149
|
+
$eq: eligibleSeatingTypeCodeValueEq
|
|
150
|
+
}
|
|
167
151
|
}
|
|
168
152
|
});
|
|
169
153
|
}
|
|
170
|
-
const appliesToMovieTicketServiceTypeExist = (
|
|
154
|
+
const appliesToMovieTicketServiceTypeExist = (_0 = (_z = (_y = params.priceSpecification) === null || _y === void 0 ? void 0 : _y.appliesToMovieTicket) === null || _z === void 0 ? void 0 : _z.serviceType) === null || _0 === void 0 ? void 0 : _0.$exists;
|
|
171
155
|
if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
156
|
+
matchStages.push({
|
|
157
|
+
$match: {
|
|
158
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': {
|
|
159
|
+
$exists: appliesToMovieTicketServiceTypeExist
|
|
160
|
+
}
|
|
175
161
|
}
|
|
176
162
|
});
|
|
177
163
|
}
|
|
178
|
-
const appliesToMovieTicketServiceTypeEq = (
|
|
164
|
+
const appliesToMovieTicketServiceTypeEq = (_3 = (_2 = (_1 = params.priceSpecification) === null || _1 === void 0 ? void 0 : _1.appliesToMovieTicket) === null || _2 === void 0 ? void 0 : _2.serviceType) === null || _3 === void 0 ? void 0 : _3.$eq;
|
|
179
165
|
if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
166
|
+
matchStages.push({
|
|
167
|
+
$match: {
|
|
168
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': {
|
|
169
|
+
$exists: true,
|
|
170
|
+
$eq: appliesToMovieTicketServiceTypeEq
|
|
171
|
+
}
|
|
184
172
|
}
|
|
185
173
|
});
|
|
186
174
|
}
|
|
187
|
-
const appliesToMovieTicketServiceOutputTypeOfEq = (
|
|
175
|
+
const appliesToMovieTicketServiceOutputTypeOfEq = (_7 = (_6 = (_5 = (_4 = params.priceSpecification) === null || _4 === void 0 ? void 0 : _4.appliesToMovieTicket) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.typeOf) === null || _7 === void 0 ? void 0 : _7.$eq;
|
|
188
176
|
if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
177
|
+
matchStages.push({
|
|
178
|
+
$match: {
|
|
179
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
180
|
+
$exists: true,
|
|
181
|
+
$eq: appliesToMovieTicketServiceOutputTypeOfEq
|
|
182
|
+
}
|
|
193
183
|
}
|
|
194
184
|
});
|
|
195
185
|
}
|
|
196
|
-
const appliesToMovieTicketServiceOutputTypeOfNin = (
|
|
186
|
+
const appliesToMovieTicketServiceOutputTypeOfNin = (_11 = (_10 = (_9 = (_8 = params.priceSpecification) === null || _8 === void 0 ? void 0 : _8.appliesToMovieTicket) === null || _9 === void 0 ? void 0 : _9.serviceOutput) === null || _10 === void 0 ? void 0 : _10.typeOf) === null || _11 === void 0 ? void 0 : _11.$nin;
|
|
197
187
|
if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
188
|
+
matchStages.push({
|
|
189
|
+
$match: {
|
|
190
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
191
|
+
$nin: appliesToMovieTicketServiceOutputTypeOfNin
|
|
192
|
+
}
|
|
201
193
|
}
|
|
202
194
|
});
|
|
203
195
|
}
|
|
204
196
|
if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
|
|
205
|
-
const priceSpecificationPriceGte = (
|
|
197
|
+
const priceSpecificationPriceGte = (_12 = params.priceSpecification.price) === null || _12 === void 0 ? void 0 : _12.$gte;
|
|
206
198
|
if (typeof priceSpecificationPriceGte === 'number') {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
199
|
+
matchStages.push({
|
|
200
|
+
$match: {
|
|
201
|
+
'offers.priceSpecification.price': {
|
|
202
|
+
$exists: true,
|
|
203
|
+
$gte: priceSpecificationPriceGte
|
|
204
|
+
}
|
|
211
205
|
}
|
|
212
206
|
});
|
|
213
207
|
}
|
|
214
|
-
const priceSpecificationPriceLte = (
|
|
208
|
+
const priceSpecificationPriceLte = (_13 = params.priceSpecification.price) === null || _13 === void 0 ? void 0 : _13.$lte;
|
|
215
209
|
if (typeof priceSpecificationPriceLte === 'number') {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
210
|
+
matchStages.push({
|
|
211
|
+
$match: {
|
|
212
|
+
'offers.priceSpecification.price': {
|
|
213
|
+
$exists: true,
|
|
214
|
+
$lte: priceSpecificationPriceLte
|
|
215
|
+
}
|
|
220
216
|
}
|
|
221
217
|
});
|
|
222
218
|
}
|
|
223
|
-
const accountsReceivableGte = (
|
|
219
|
+
const accountsReceivableGte = (_15 = (_14 = params.priceSpecification.accounting) === null || _14 === void 0 ? void 0 : _14.accountsReceivable) === null || _15 === void 0 ? void 0 : _15.$gte;
|
|
224
220
|
if (typeof accountsReceivableGte === 'number') {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
matchStages.push({
|
|
222
|
+
$match: {
|
|
223
|
+
'offers.priceSpecification.accounting.accountsReceivable': {
|
|
224
|
+
$exists: true,
|
|
225
|
+
$gte: accountsReceivableGte
|
|
226
|
+
}
|
|
229
227
|
}
|
|
230
228
|
});
|
|
231
229
|
}
|
|
232
|
-
const accountsReceivableLte = (
|
|
230
|
+
const accountsReceivableLte = (_17 = (_16 = params.priceSpecification.accounting) === null || _16 === void 0 ? void 0 : _16.accountsReceivable) === null || _17 === void 0 ? void 0 : _17.$lte;
|
|
233
231
|
if (typeof accountsReceivableLte === 'number') {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
232
|
+
matchStages.push({
|
|
233
|
+
$match: {
|
|
234
|
+
'offers.priceSpecification.accounting.accountsReceivable': {
|
|
235
|
+
$exists: true,
|
|
236
|
+
$lte: accountsReceivableLte
|
|
237
|
+
}
|
|
238
238
|
}
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
|
-
const accountingCodeValueEq = (
|
|
241
|
+
const accountingCodeValueEq = (_20 = (_19 = (_18 = params.priceSpecification.accounting) === null || _18 === void 0 ? void 0 : _18.operatingRevenue) === null || _19 === void 0 ? void 0 : _19.codeValue) === null || _20 === void 0 ? void 0 : _20.$eq;
|
|
242
242
|
if (typeof accountingCodeValueEq === 'string') {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
matchStages.push({
|
|
244
|
+
$match: {
|
|
245
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
246
|
+
$exists: true,
|
|
247
|
+
$eq: accountingCodeValueEq
|
|
248
|
+
}
|
|
247
249
|
}
|
|
248
250
|
});
|
|
249
251
|
}
|
|
250
|
-
const accountingCodeValueIn = (
|
|
252
|
+
const accountingCodeValueIn = (_23 = (_22 = (_21 = params.priceSpecification.accounting) === null || _21 === void 0 ? void 0 : _21.operatingRevenue) === null || _22 === void 0 ? void 0 : _22.codeValue) === null || _23 === void 0 ? void 0 : _23.$in;
|
|
251
253
|
if (Array.isArray(accountingCodeValueIn)) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
matchStages.push({
|
|
255
|
+
$match: {
|
|
256
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
257
|
+
$exists: true,
|
|
258
|
+
$in: accountingCodeValueIn
|
|
259
|
+
}
|
|
256
260
|
}
|
|
257
261
|
});
|
|
258
262
|
}
|
|
259
|
-
const referenceQuantityValueEq = (
|
|
263
|
+
const referenceQuantityValueEq = (_25 = (_24 = params.priceSpecification.referenceQuantity) === null || _24 === void 0 ? void 0 : _24.value) === null || _25 === void 0 ? void 0 : _25.$eq;
|
|
260
264
|
if (typeof referenceQuantityValueEq === 'number') {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
+
matchStages.push({
|
|
266
|
+
$match: {
|
|
267
|
+
'offers.priceSpecification.referenceQuantity.value': {
|
|
268
|
+
$exists: true,
|
|
269
|
+
$eq: referenceQuantityValueEq
|
|
270
|
+
}
|
|
265
271
|
}
|
|
266
272
|
});
|
|
267
273
|
}
|
|
268
274
|
}
|
|
269
|
-
const availabilityEq = (
|
|
275
|
+
const availabilityEq = (_26 = params.availability) === null || _26 === void 0 ? void 0 : _26.$eq;
|
|
270
276
|
if (typeof availabilityEq === 'string') {
|
|
271
|
-
|
|
277
|
+
matchStages.push({
|
|
278
|
+
$match: {
|
|
279
|
+
'offers.availability': { $eq: availabilityEq }
|
|
280
|
+
}
|
|
281
|
+
});
|
|
272
282
|
}
|
|
273
|
-
const availableAtOrFromIdEq = (
|
|
283
|
+
const availableAtOrFromIdEq = (_28 = (_27 = params.availableAtOrFrom) === null || _27 === void 0 ? void 0 : _27.id) === null || _28 === void 0 ? void 0 : _28.$eq;
|
|
274
284
|
if (typeof availableAtOrFromIdEq === 'string') {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
285
|
+
matchStages.push({
|
|
286
|
+
$match: {
|
|
287
|
+
'offers.availableAtOrFrom.id': {
|
|
288
|
+
$exists: true,
|
|
289
|
+
$eq: availableAtOrFromIdEq
|
|
290
|
+
}
|
|
279
291
|
}
|
|
280
292
|
});
|
|
281
293
|
}
|
|
282
|
-
const availableAtOrFromIdIn = (
|
|
294
|
+
const availableAtOrFromIdIn = (_30 = (_29 = params.availableAtOrFrom) === null || _29 === void 0 ? void 0 : _29.id) === null || _30 === void 0 ? void 0 : _30.$in;
|
|
283
295
|
if (Array.isArray(availableAtOrFromIdIn)) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
296
|
+
matchStages.push({
|
|
297
|
+
$match: {
|
|
298
|
+
'offers.availableAtOrFrom.id': {
|
|
299
|
+
$exists: true,
|
|
300
|
+
$in: availableAtOrFromIdIn
|
|
301
|
+
}
|
|
288
302
|
}
|
|
289
303
|
});
|
|
290
304
|
}
|
|
291
|
-
const addOnItemOfferedIdEq = (
|
|
305
|
+
const addOnItemOfferedIdEq = (_33 = (_32 = (_31 = params.addOn) === null || _31 === void 0 ? void 0 : _31.itemOffered) === null || _32 === void 0 ? void 0 : _32.id) === null || _33 === void 0 ? void 0 : _33.$eq;
|
|
292
306
|
if (typeof addOnItemOfferedIdEq === 'string') {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
$exists: true,
|
|
296
|
-
|
|
307
|
+
matchStages.push({
|
|
308
|
+
$match: {
|
|
309
|
+
'offers.addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
const addOnItemOfferedIdIn = (_36 = (_35 = (_34 = params.addOn) === null || _34 === void 0 ? void 0 : _34.itemOffered) === null || _35 === void 0 ? void 0 : _35.id) === null || _36 === void 0 ? void 0 : _36.$in;
|
|
314
|
+
if (Array.isArray(addOnItemOfferedIdIn)) {
|
|
315
|
+
matchStages.push({
|
|
316
|
+
$match: {
|
|
317
|
+
'offers.addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
|
|
297
318
|
}
|
|
298
319
|
});
|
|
299
320
|
}
|
|
300
|
-
const hasMerchantReturnPolicyIdEq = (
|
|
321
|
+
const hasMerchantReturnPolicyIdEq = (_38 = (_37 = params.hasMerchantReturnPolicy) === null || _37 === void 0 ? void 0 : _37.id) === null || _38 === void 0 ? void 0 : _38.$eq;
|
|
301
322
|
if (typeof hasMerchantReturnPolicyIdEq === 'string') {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
323
|
+
matchStages.push({
|
|
324
|
+
$match: {
|
|
325
|
+
'offers.hasMerchantReturnPolicy.id': {
|
|
326
|
+
$exists: true,
|
|
327
|
+
$eq: hasMerchantReturnPolicyIdEq
|
|
328
|
+
}
|
|
306
329
|
}
|
|
307
330
|
});
|
|
308
331
|
}
|
|
309
|
-
const additionalPropertyAll = (
|
|
332
|
+
const additionalPropertyAll = (_39 = params.additionalProperty) === null || _39 === void 0 ? void 0 : _39.$all;
|
|
310
333
|
if (Array.isArray(additionalPropertyAll)) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
334
|
+
matchStages.push({
|
|
335
|
+
$match: {
|
|
336
|
+
'offers.additionalProperty': {
|
|
337
|
+
$exists: true,
|
|
338
|
+
$all: additionalPropertyAll
|
|
339
|
+
}
|
|
315
340
|
}
|
|
316
341
|
});
|
|
317
342
|
}
|
|
318
|
-
const additionalPropertyElemMatch = (
|
|
343
|
+
const additionalPropertyElemMatch = (_40 = params.additionalProperty) === null || _40 === void 0 ? void 0 : _40.$elemMatch;
|
|
319
344
|
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
345
|
+
matchStages.push({
|
|
346
|
+
$match: {
|
|
347
|
+
'offers.additionalProperty': {
|
|
348
|
+
$exists: true,
|
|
349
|
+
$elemMatch: additionalPropertyElemMatch
|
|
350
|
+
}
|
|
324
351
|
}
|
|
325
352
|
});
|
|
326
353
|
}
|
|
327
354
|
if (params.onlyValid === true) {
|
|
328
355
|
const now = new Date();
|
|
329
|
-
|
|
330
|
-
$
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
356
|
+
matchStages.push({
|
|
357
|
+
$match: {
|
|
358
|
+
$or: [
|
|
359
|
+
{ 'offers.validFrom': { $exists: false } },
|
|
360
|
+
{ 'offers.validFrom': { $exists: true, $lte: now } }
|
|
361
|
+
]
|
|
362
|
+
}
|
|
334
363
|
}, {
|
|
335
|
-
$
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
364
|
+
$match: {
|
|
365
|
+
$or: [
|
|
366
|
+
{ 'offers.validThrough': { $exists: false } },
|
|
367
|
+
{ 'offers.validThrough': { $exists: true, $gte: now } }
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return matchStages;
|
|
373
|
+
}
|
|
374
|
+
static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
|
|
375
|
+
let projectStage = {
|
|
376
|
+
_id: 0,
|
|
377
|
+
offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
|
|
378
|
+
parentOffer: {
|
|
379
|
+
id: '$_id'
|
|
380
|
+
},
|
|
381
|
+
typeOf: '$offers.typeOf',
|
|
382
|
+
project: '$project',
|
|
383
|
+
id: '$offers.id',
|
|
384
|
+
identifier: '$offers.identifier',
|
|
385
|
+
name: '$offers.name',
|
|
386
|
+
description: '$offers.description',
|
|
387
|
+
category: '$offers.category',
|
|
388
|
+
color: '$offers.color',
|
|
389
|
+
additionalProperty: '$offers.additionalProperty',
|
|
390
|
+
advanceBookingRequirement: '$offers.advanceBookingRequirement',
|
|
391
|
+
alternateName: '$offers.alternateName',
|
|
392
|
+
addOn: '$offers.addOn',
|
|
393
|
+
availability: '$offers.availability',
|
|
394
|
+
availableAtOrFrom: '$offers.availableAtOrFrom',
|
|
395
|
+
hasMerchantReturnPolicy: '$offers.hasMerchantReturnPolicy',
|
|
396
|
+
itemOffered: '$offers.itemOffered',
|
|
397
|
+
priceCurrency: '$offers.priceCurrency',
|
|
398
|
+
priceSpecification: '$offers.priceSpecification',
|
|
399
|
+
eligibleCustomerType: '$offers.eligibleCustomerType',
|
|
400
|
+
eligibleDuration: '$offers.eligibleDuration',
|
|
401
|
+
eligibleMembershipType: '$offers.eligibleMembershipType',
|
|
402
|
+
eligibleMonetaryAmount: '$offers.eligibleMonetaryAmount',
|
|
403
|
+
eligibleQuantity: '$offers.eligibleQuantity',
|
|
404
|
+
eligibleRegion: '$offers.eligibleRegion',
|
|
405
|
+
eligibleSeatingType: '$offers.eligibleSeatingType',
|
|
406
|
+
eligibleSubReservation: '$offers.eligibleSubReservation',
|
|
407
|
+
settings: '$offers.settings',
|
|
408
|
+
validFrom: '$offers.validFrom',
|
|
409
|
+
validThrough: '$offers.validThrough',
|
|
410
|
+
validRateLimit: '$offers.validRateLimit'
|
|
411
|
+
};
|
|
412
|
+
const positiveProjectionFields = Object.keys(params)
|
|
413
|
+
.filter((key) => params[key] !== 0);
|
|
414
|
+
const negativeProjectionFields = Object.keys(params)
|
|
415
|
+
.filter((key) => params[key] === 0);
|
|
416
|
+
if (positiveProjectionFields.length > 0) {
|
|
417
|
+
projectStage = {
|
|
418
|
+
_id: 0,
|
|
419
|
+
offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
|
|
420
|
+
parentOffer: {
|
|
421
|
+
id: '$_id'
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
positiveProjectionFields.forEach((field) => {
|
|
425
|
+
projectStage[field] = `$offers.${field}`;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
else if (negativeProjectionFields.length > 0) {
|
|
429
|
+
negativeProjectionFields.forEach((field) => {
|
|
430
|
+
if (typeof projectStage[field] === 'string') {
|
|
431
|
+
// tslint:disable-next-line:no-dynamic-delete
|
|
432
|
+
delete projectStage[field];
|
|
433
|
+
}
|
|
339
434
|
});
|
|
340
435
|
}
|
|
341
|
-
return
|
|
436
|
+
return projectStage;
|
|
342
437
|
}
|
|
343
438
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
439
|
+
* カタログIDで単価オファーを全て検索する
|
|
440
|
+
* 必ずカタログデータから単価オファーIDを参照する
|
|
346
441
|
*/
|
|
347
|
-
|
|
442
|
+
searchAllByOfferCatalogId(params) {
|
|
443
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
+
const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
|
|
445
|
+
id: params.subOfferCatalog.id
|
|
446
|
+
});
|
|
447
|
+
let offers = [];
|
|
448
|
+
if (sortedOfferIds.length > 0) {
|
|
449
|
+
const searchOffersConditions = {
|
|
450
|
+
parentOffer: { id: { $in: sortedOfferIds } }
|
|
451
|
+
};
|
|
452
|
+
offers = yield this.search(searchOffersConditions, params.projection);
|
|
453
|
+
}
|
|
454
|
+
return { offers };
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* 単価オファーIDとカタログIDで単価オファーを検索する
|
|
459
|
+
* 必ずカタログデータから単価オファーIDを参照する
|
|
460
|
+
*/
|
|
461
|
+
searchByIdsAndOfferCatalogId(params) {
|
|
348
462
|
var _a;
|
|
349
463
|
return __awaiter(this, void 0, void 0, function* () {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (Array.isArray(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
})
|
|
464
|
+
const unitPriceOfferIds = params.ids;
|
|
465
|
+
let aggregateOfferIds; // 集計オファーIDでフィルターする場合
|
|
466
|
+
if (Array.isArray(unitPriceOfferIds)) {
|
|
467
|
+
// 解釈を集計オファーIDに変更する必要がある(2023-09-11~)
|
|
468
|
+
// 単価オファーIDリスト→集計オファーIDに変換→カタログ条件にセット
|
|
469
|
+
const searchDistinctAggregateOfferIdsResult = yield this.aggregateOfferModel.distinct('_id', { 'offers.id': { $in: unitPriceOfferIds } })
|
|
470
|
+
.exec();
|
|
471
|
+
aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
|
|
356
472
|
}
|
|
357
|
-
const
|
|
358
|
-
{ $unwind: '$itemListElement' },
|
|
359
|
-
...matchStages,
|
|
360
|
-
{
|
|
361
|
-
$project: {
|
|
362
|
-
_id: 0,
|
|
363
|
-
id: '$itemListElement.id'
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
]);
|
|
367
|
-
const itemListElements = yield aggregate.exec();
|
|
368
|
-
const sortedOfferIds = (Array.isArray(itemListElements))
|
|
369
|
-
? itemListElements.map((element) => element.id)
|
|
370
|
-
: [];
|
|
473
|
+
const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog(Object.assign({ id: params.subOfferCatalog.id }, (Array.isArray(aggregateOfferIds)) ? { itemListElementIds: aggregateOfferIds } : undefined));
|
|
371
474
|
let offers = [];
|
|
372
475
|
if (sortedOfferIds.length > 0) {
|
|
373
|
-
const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
|
|
476
|
+
const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
|
|
477
|
+
// aggregateOffer.idで検索する(2023-09-09~)
|
|
478
|
+
parentOffer: { id: { $in: sortedOfferIds } } }, (Array.isArray(unitPriceOfferIds)) ? { id: { $in: unitPriceOfferIds } } : undefined), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
374
479
|
? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
|
|
375
480
|
: undefined), { priceSpecification: {
|
|
376
481
|
appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
|
|
@@ -385,116 +490,222 @@ class MongoRepository {
|
|
|
385
490
|
}
|
|
386
491
|
: undefined)
|
|
387
492
|
}, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
|
|
388
|
-
|
|
493
|
+
// 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
|
|
494
|
+
? { sort: { identifier: factory.sortType.Ascending } }
|
|
495
|
+
: undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
|
|
496
|
+
offers = yield this.search(searchOffersConditions, params.projection);
|
|
497
|
+
}
|
|
498
|
+
return { offers };
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* カタログに含まれるオファーを検索する(カタログ内ソートは保証しない)
|
|
503
|
+
* カタログ内ソートインデックスはsortedOfferIdsで判断する
|
|
504
|
+
*/
|
|
505
|
+
searchByOfferCatalogIdWithSortIndex(params) {
|
|
506
|
+
var _a;
|
|
507
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
+
const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
|
|
509
|
+
id: params.subOfferCatalog.id
|
|
510
|
+
});
|
|
511
|
+
let offers = [];
|
|
512
|
+
if (sortedOfferIds.length > 0) {
|
|
513
|
+
const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.useIncludeInDataCatalog)
|
|
514
|
+
? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
|
|
515
|
+
: { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
516
|
+
? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
|
|
517
|
+
: undefined), { priceSpecification: {
|
|
518
|
+
appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
|
|
519
|
+
? {
|
|
520
|
+
serviceOutput: {
|
|
521
|
+
typeOf: { $nin: params.unacceptedPaymentMethod }
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
: undefined), (params.excludeAppliesToMovieTicket)
|
|
525
|
+
? {
|
|
526
|
+
serviceType: { $exists: false }
|
|
527
|
+
}
|
|
528
|
+
: undefined)
|
|
529
|
+
}, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
|
|
530
|
+
// 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
|
|
531
|
+
? { sort: { identifier: factory.sortType.Ascending } }
|
|
389
532
|
: undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
|
|
390
533
|
offers = yield this.search(searchOffersConditions, params.projection);
|
|
391
|
-
if (params.sort) {
|
|
392
|
-
// sorting
|
|
393
|
-
offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
|
|
394
|
-
}
|
|
395
534
|
}
|
|
396
535
|
return { offers, sortedOfferIds };
|
|
397
536
|
});
|
|
398
537
|
}
|
|
399
|
-
|
|
538
|
+
findAggregateOfferById(params) {
|
|
400
539
|
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
-
const doc = yield this.
|
|
540
|
+
const doc = yield this.aggregateOfferModel.findOne({
|
|
541
|
+
_id: { $eq: params.id },
|
|
542
|
+
'project.id': { $eq: params.project.id }
|
|
543
|
+
}, {
|
|
402
544
|
__v: 0,
|
|
403
545
|
createdAt: 0,
|
|
404
546
|
updatedAt: 0
|
|
405
547
|
})
|
|
406
548
|
.exec();
|
|
407
549
|
if (doc === null) {
|
|
408
|
-
throw new factory.errors.NotFound(this.
|
|
550
|
+
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
409
551
|
}
|
|
410
552
|
return doc.toObject();
|
|
411
553
|
});
|
|
412
554
|
}
|
|
413
555
|
count(params) {
|
|
414
556
|
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
557
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
558
|
+
const [{ offerCount }] = yield this.aggregateOfferModel.aggregate([
|
|
559
|
+
{
|
|
560
|
+
$unwind: { path: '$offers' }
|
|
561
|
+
},
|
|
562
|
+
...matchStages,
|
|
563
|
+
{
|
|
564
|
+
$count: 'offerCount'
|
|
565
|
+
}
|
|
566
|
+
])
|
|
418
567
|
.exec();
|
|
568
|
+
return offerCount;
|
|
419
569
|
});
|
|
420
570
|
}
|
|
421
571
|
search(params, projection) {
|
|
422
|
-
var _a;
|
|
572
|
+
var _a, _b;
|
|
423
573
|
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
-
const
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
574
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
575
|
+
const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
|
|
576
|
+
const sortByPrice = (_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price'];
|
|
577
|
+
const sortByIdentifier = (_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier;
|
|
578
|
+
const aggregate = this.aggregateOfferModel.aggregate([
|
|
579
|
+
{
|
|
580
|
+
$unwind: {
|
|
581
|
+
path: '$offers',
|
|
582
|
+
includeArrayIndex: OFFERS_ARRAY_INDEX_NAME
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
...matchStages,
|
|
586
|
+
...(typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number')
|
|
587
|
+
? [
|
|
588
|
+
{
|
|
589
|
+
$sort: Object.assign(Object.assign({}, (typeof sortByPrice === 'number')
|
|
590
|
+
? { 'offers.priceSpecification.price': sortByPrice }
|
|
591
|
+
: undefined), (typeof sortByIdentifier === 'number')
|
|
592
|
+
? { 'offers.identifier': sortByIdentifier }
|
|
593
|
+
: undefined)
|
|
594
|
+
}
|
|
595
|
+
]
|
|
596
|
+
: [],
|
|
597
|
+
{ $project: projectStage }
|
|
598
|
+
]);
|
|
599
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
600
|
+
/* istanbul ignore else */
|
|
432
601
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
433
602
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
434
|
-
|
|
603
|
+
aggregate.limit(params.limit * page)
|
|
435
604
|
.skip(params.limit * (page - 1));
|
|
436
605
|
}
|
|
437
|
-
|
|
438
|
-
/* istanbul ignore else */
|
|
439
|
-
if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) !== undefined) {
|
|
440
|
-
query.sort({ 'priceSpecification.price': params.sort['priceSpecification.price'] });
|
|
441
|
-
}
|
|
442
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
443
|
-
.exec()
|
|
444
|
-
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
606
|
+
return aggregate.exec();
|
|
445
607
|
});
|
|
446
608
|
}
|
|
447
609
|
save(params) {
|
|
448
610
|
return __awaiter(this, void 0, void 0, function* () {
|
|
449
611
|
let doc;
|
|
612
|
+
const { $unset } = params, paramsWithoutUnset = __rest(params, ["$unset"]);
|
|
613
|
+
let savedUnitPriceOffer;
|
|
450
614
|
if (params.id === '') {
|
|
451
615
|
const id = uniqid();
|
|
452
|
-
|
|
616
|
+
savedUnitPriceOffer = Object.assign(Object.assign({}, paramsWithoutUnset), { id });
|
|
617
|
+
const aggregateOffer = {
|
|
618
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
619
|
+
project: params.project,
|
|
620
|
+
offers: [savedUnitPriceOffer]
|
|
621
|
+
};
|
|
622
|
+
doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id: id }));
|
|
453
623
|
}
|
|
454
624
|
else {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
625
|
+
const unitPriceOffers = yield this.search({
|
|
626
|
+
limit: 1,
|
|
627
|
+
page: 1,
|
|
628
|
+
project: { id: { $eq: params.project.id } },
|
|
629
|
+
id: { $eq: params.id }
|
|
630
|
+
}, { id: 1, identifier: 1, project: 1, typeOf: 1 });
|
|
631
|
+
const originalUnitPriceOffer = unitPriceOffers.shift();
|
|
632
|
+
if (originalUnitPriceOffer === undefined) {
|
|
633
|
+
throw new factory.errors.NotFound(factory.offerType.Offer);
|
|
634
|
+
}
|
|
635
|
+
// 上書き禁止属性を除外
|
|
636
|
+
const { id, identifier, project, typeOf } = paramsWithoutUnset, updateFields = __rest(paramsWithoutUnset, ["id", "identifier", "project", "typeOf"]);
|
|
637
|
+
savedUnitPriceOffer = Object.assign(Object.assign({}, updateFields), { id: originalUnitPriceOffer.id, identifier: originalUnitPriceOffer.identifier, project: originalUnitPriceOffer.project, typeOf: originalUnitPriceOffer.typeOf });
|
|
638
|
+
doc = yield this.aggregateOfferModel.findOneAndUpdate({ 'offers.id': params.id }, {
|
|
639
|
+
$set: {
|
|
640
|
+
'offers.$[offer]': savedUnitPriceOffer
|
|
641
|
+
}
|
|
642
|
+
}, {
|
|
643
|
+
upsert: false,
|
|
644
|
+
new: true,
|
|
645
|
+
arrayFilters: [
|
|
646
|
+
{ 'offer.id': { $eq: params.id } }
|
|
647
|
+
]
|
|
648
|
+
})
|
|
458
649
|
.exec();
|
|
459
650
|
}
|
|
460
651
|
if (doc === null) {
|
|
461
|
-
throw new factory.errors.NotFound(this.
|
|
652
|
+
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
462
653
|
}
|
|
463
|
-
return
|
|
654
|
+
return savedUnitPriceOffer;
|
|
464
655
|
});
|
|
465
656
|
}
|
|
657
|
+
/**
|
|
658
|
+
* sskts専用オファー保管
|
|
659
|
+
*/
|
|
660
|
+
// tslint:disable-next-line:max-func-body-length
|
|
466
661
|
saveManyByIdentifier(params) {
|
|
467
662
|
return __awaiter(this, void 0, void 0, function* () {
|
|
468
|
-
const
|
|
663
|
+
const insertBulkWriteOps = [];
|
|
664
|
+
const updateBulkWriteOps = [];
|
|
469
665
|
if (Array.isArray(params)) {
|
|
470
666
|
params.forEach((p) => {
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
667
|
+
const newOfferId = uniqid();
|
|
668
|
+
const unitPriceOffer = Object.assign(Object.assign({}, p.attributes), { id: newOfferId });
|
|
669
|
+
const aggregateOffer = {
|
|
670
|
+
project: p.attributes.project,
|
|
671
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
672
|
+
offers: [unitPriceOffer]
|
|
673
|
+
};
|
|
674
|
+
insertBulkWriteOps.push({
|
|
477
675
|
updateOne: {
|
|
478
676
|
filter: {
|
|
479
|
-
'project.id': {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
677
|
+
'project.id': { $eq: p.attributes.project.id },
|
|
678
|
+
'offers.identifier': { $exists: true, $eq: p.attributes.identifier }
|
|
679
|
+
},
|
|
680
|
+
update: {
|
|
681
|
+
$setOnInsert: Object.assign(Object.assign({}, aggregateOffer), { _id: newOfferId })
|
|
682
|
+
},
|
|
683
|
+
upsert: true
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
const { id } = unitPriceOffer, $set = __rest(unitPriceOffer, ["id"]);
|
|
687
|
+
updateBulkWriteOps.push({
|
|
688
|
+
updateOne: {
|
|
689
|
+
filter: {
|
|
690
|
+
'project.id': { $eq: unitPriceOffer.project.id },
|
|
691
|
+
'offers.identifier': { $exists: true, $eq: unitPriceOffer.identifier }
|
|
486
692
|
},
|
|
487
693
|
update: {
|
|
488
|
-
|
|
489
|
-
$
|
|
694
|
+
// 特定の属性のみ更新する(IDを上書きできないので)
|
|
695
|
+
$set: Object.assign(Object.assign({ 'offers.0.name': $set.name, 'offers.0.description': $set.description, 'offers.0.alternateName': $set.alternateName, 'offers.0.priceSpecification': $set.priceSpecification, 'offers.0.additionalProperty': $set.additionalProperty }, (Array.isArray($set.eligibleMembershipType))
|
|
696
|
+
? { 'offers.0.eligibleMembershipType': $set.eligibleMembershipType }
|
|
697
|
+
: undefined), (Array.isArray($set.eligibleMonetaryAmount))
|
|
698
|
+
? { 'offers.0.eligibleMonetaryAmount': $set.eligibleMonetaryAmount }
|
|
699
|
+
: undefined)
|
|
490
700
|
},
|
|
491
|
-
upsert:
|
|
701
|
+
upsert: false
|
|
492
702
|
}
|
|
493
703
|
});
|
|
494
704
|
});
|
|
495
705
|
}
|
|
496
|
-
if (
|
|
497
|
-
yield this.
|
|
706
|
+
if (insertBulkWriteOps.length > 0) {
|
|
707
|
+
yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
|
|
708
|
+
yield this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
|
|
498
709
|
}
|
|
499
710
|
});
|
|
500
711
|
}
|
|
@@ -506,42 +717,61 @@ class MongoRepository {
|
|
|
506
717
|
if (params.addOn.itemOffered.id.$in.length === 0) {
|
|
507
718
|
return;
|
|
508
719
|
}
|
|
509
|
-
|
|
720
|
+
const conditions = {
|
|
510
721
|
'project.id': { $eq: params.project.id },
|
|
511
|
-
'addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
|
|
512
|
-
}
|
|
722
|
+
'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
|
|
723
|
+
};
|
|
724
|
+
const updatingOffers = yield this.search({
|
|
725
|
+
project: { id: { $eq: params.project.id } },
|
|
726
|
+
addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
|
|
727
|
+
}, { id: 1 });
|
|
728
|
+
const result = yield this.aggregateOfferModel.updateMany(conditions, {
|
|
513
729
|
$pull: {
|
|
514
|
-
addOn: {
|
|
730
|
+
'offers.$[offer].addOn': {
|
|
515
731
|
'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
|
|
516
732
|
}
|
|
517
733
|
}
|
|
734
|
+
}, {
|
|
735
|
+
arrayFilters: [
|
|
736
|
+
{ 'offer.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in } }
|
|
737
|
+
]
|
|
518
738
|
})
|
|
519
739
|
.exec();
|
|
740
|
+
if (updatingOffers.length > 0) {
|
|
741
|
+
// no op
|
|
742
|
+
}
|
|
743
|
+
return result;
|
|
520
744
|
});
|
|
521
745
|
}
|
|
522
746
|
deleteById(params) {
|
|
523
747
|
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
-
yield this.
|
|
525
|
-
.exec();
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
deleteByProject(params) {
|
|
529
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
530
|
-
yield this.offerModel.deleteMany({
|
|
531
|
-
'project.id': { $eq: params.project.id }
|
|
532
|
-
})
|
|
748
|
+
yield this.aggregateOfferModel.findOneAndRemove({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
|
|
533
749
|
.exec();
|
|
534
750
|
});
|
|
535
751
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
unsetUnnecessaryFields(params) {
|
|
752
|
+
/**
|
|
753
|
+
* サブカタログから集計オファーIDリストを検索する
|
|
754
|
+
*/
|
|
755
|
+
searchAggregateOfferIdsBySubOfferCatalog(params) {
|
|
542
756
|
return __awaiter(this, void 0, void 0, function* () {
|
|
543
|
-
|
|
757
|
+
const matchStages = [{ $match: { _id: { $eq: params.id } } }];
|
|
758
|
+
if (Array.isArray(params.itemListElementIds)) {
|
|
759
|
+
matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: params.itemListElementIds } } });
|
|
760
|
+
}
|
|
761
|
+
const itemListElements = yield this.offerCatalogModel.aggregate([
|
|
762
|
+
{ $unwind: '$itemListElement' },
|
|
763
|
+
...matchStages,
|
|
764
|
+
{
|
|
765
|
+
$project: {
|
|
766
|
+
_id: 0,
|
|
767
|
+
id: '$itemListElement.id'
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
])
|
|
544
771
|
.exec();
|
|
772
|
+
return (Array.isArray(itemListElements))
|
|
773
|
+
? itemListElements.map((element) => element.id)
|
|
774
|
+
: [];
|
|
545
775
|
});
|
|
546
776
|
}
|
|
547
777
|
}
|