@chevre/domain 21.8.0-alpha.6 → 21.8.0-alpha.60
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 +23 -0
- package/example/src/chevre/importOffersFromCOA.ts +7 -1
- package/example/src/chevre/migrateAggregateOffers.ts +89 -0
- 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/processPay.ts +3 -4
- package/example/src/chevre/publishPermitOwnershipInfoToken.ts +56 -0
- package/example/src/chevre/pullAddOnsFromOffer.ts +26 -0
- package/example/src/chevre/searchAggregateOffers.ts +48 -0
- package/example/src/chevre/searchEventTicketOffers.ts +3 -1
- package/example/src/chevre/searchEvents.ts +9 -7
- package/example/src/chevre/searchOffersByCatalog.ts +9 -5
- package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
- package/example/src/chevre/searchOrders.ts +9 -7
- package/example/src/chevre/sync2aggregateOffer.ts +27 -0
- package/example/src/chevre/syncAggregateOffer.ts +25 -0
- package/lib/chevre/emailMessageBuilder.js +6 -5
- package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
- package/lib/chevre/repo/aggregateOffer.js +534 -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 +177 -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/offer.d.ts +24 -33
- package/lib/chevre/repo/mongoose/schemas/offer.js +4 -3
- 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 +82 -47
- package/lib/chevre/repo/offer.js +1279 -289
- package/lib/chevre/repo/offerCatalog.d.ts +6 -0
- package/lib/chevre/repo/offerCatalog.js +13 -0
- package/lib/chevre/repo/order.d.ts +15 -0
- package/lib/chevre/repo/order.js +58 -26
- package/lib/chevre/repo/task.d.ts +7 -1
- package/lib/chevre/repo/task.js +100 -0
- package/lib/chevre/repository.d.ts +3 -0
- package/lib/chevre/repository.js +5 -1
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -1
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -1
- 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/delivery.js +17 -0
- 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 +1 -0
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +6 -3
- 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 +8 -1
- package/lib/chevre/service/offer/product/searchProductOffers.js +10 -3
- package/lib/chevre/service/offer/product.d.ts +1 -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 +29 -40
- 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 +81 -54
- package/lib/chevre/service/order/payOrder.d.ts +2 -10
- package/lib/chevre/service/order/payOrder.js +4 -45
- package/lib/chevre/service/order/placeOrder.js +11 -13
- 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/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/onOrderPaymentCompleted.d.ts +6 -0
- package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
- 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 +60 -0
- package/lib/chevre/service/task/onResourceUpdated.js +12 -0
- package/lib/chevre/service/task/returnPayTransaction.js +8 -3
- package/lib/chevre/service/task/syncAggregateOffer.d.ts +7 -0
- package/lib/chevre/service/task/syncAggregateOffer.js +23 -0
- 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 +5 -3
- package/lib/chevre/settings.js +6 -6
- 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/offer.js
CHANGED
|
@@ -23,338 +23,763 @@ 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
|
+
// import { modelName as offerModelName, schema as offerSchema } from './mongoose/schemas/offer';
|
|
27
28
|
const offerCatalog_1 = require("./mongoose/schemas/offerCatalog");
|
|
29
|
+
const task_1 = require("./mongoose/schemas/task");
|
|
30
|
+
const task_2 = require("../eventEmitter/task");
|
|
28
31
|
const settings_1 = require("../settings");
|
|
32
|
+
const OFFERS_ARRAY_INDEX_NAME = 'offerIndex';
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* 単価オファーリポジトリ
|
|
31
35
|
*/
|
|
32
36
|
class MongoRepository {
|
|
33
37
|
constructor(connection) {
|
|
34
|
-
this.
|
|
38
|
+
this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
|
|
39
|
+
// .on('index', (error: any) => {
|
|
40
|
+
// if (error !== undefined) {
|
|
41
|
+
// // tslint:disable-next-line:no-console
|
|
42
|
+
// console.error('index event emitted.', error);
|
|
43
|
+
// }
|
|
44
|
+
// });
|
|
45
|
+
// this.offerModel = connection.model(offerModelName, offerSchema);
|
|
35
46
|
this.offerCatalogModel = connection.model(offerCatalog_1.modelName, offerCatalog_1.schema);
|
|
47
|
+
this.taskModel = connection.model(task_1.modelName, task_1.schema);
|
|
36
48
|
}
|
|
37
49
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
38
|
-
static CREATE_OFFER_MONGO_CONDITIONS(params) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
// public static CREATE_OFFER_MONGO_CONDITIONS(params: factory.unitPriceOffer.ISearchConditions) {
|
|
51
|
+
// // MongoDB検索条件
|
|
52
|
+
// const andConditions: any[] = [];
|
|
53
|
+
// const projectIdEq = params.project?.id?.$eq;
|
|
54
|
+
// if (typeof projectIdEq === 'string') {
|
|
55
|
+
// andConditions.push({
|
|
56
|
+
// 'project.id': {
|
|
57
|
+
// $eq: projectIdEq
|
|
58
|
+
// }
|
|
59
|
+
// });
|
|
60
|
+
// }
|
|
61
|
+
// const parentOfferIdIn = params.parentOffer?.id?.$in;
|
|
62
|
+
// if (Array.isArray(parentOfferIdIn)) {
|
|
63
|
+
// andConditions.push({ _id: { $in: parentOfferIdIn } });
|
|
64
|
+
// }
|
|
65
|
+
// const idEq = params.id?.$eq;
|
|
66
|
+
// if (typeof idEq === 'string') {
|
|
67
|
+
// andConditions.push({
|
|
68
|
+
// _id: {
|
|
69
|
+
// $eq: idEq
|
|
70
|
+
// }
|
|
71
|
+
// });
|
|
72
|
+
// }
|
|
73
|
+
// const idIn = params.id?.$in;
|
|
74
|
+
// if (Array.isArray(idIn)) {
|
|
75
|
+
// andConditions.push({
|
|
76
|
+
// _id: {
|
|
77
|
+
// $in: idIn
|
|
78
|
+
// }
|
|
79
|
+
// });
|
|
80
|
+
// }
|
|
81
|
+
// const identifierEq = params.identifier?.$eq;
|
|
82
|
+
// if (typeof identifierEq === 'string') {
|
|
83
|
+
// andConditions.push({
|
|
84
|
+
// identifier: {
|
|
85
|
+
// $exists: true,
|
|
86
|
+
// $eq: identifierEq
|
|
87
|
+
// }
|
|
88
|
+
// });
|
|
89
|
+
// }
|
|
90
|
+
// const identifierIn = params.identifier?.$in;
|
|
91
|
+
// if (Array.isArray(identifierIn)) {
|
|
92
|
+
// andConditions.push({
|
|
93
|
+
// identifier: {
|
|
94
|
+
// $exists: true,
|
|
95
|
+
// $in: identifierIn
|
|
96
|
+
// }
|
|
97
|
+
// });
|
|
98
|
+
// }
|
|
99
|
+
// const identifierRegex = params.identifier?.$regex;
|
|
100
|
+
// if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
101
|
+
// andConditions.push({
|
|
102
|
+
// identifier: {
|
|
103
|
+
// $exists: true,
|
|
104
|
+
// $regex: new RegExp(identifierRegex)
|
|
105
|
+
// }
|
|
106
|
+
// });
|
|
107
|
+
// }
|
|
108
|
+
// const nameRegex = params.name?.$regex;
|
|
109
|
+
// if (typeof nameRegex === 'string' && nameRegex.length > 0) {
|
|
110
|
+
// const nameRegexExp = new RegExp(nameRegex);
|
|
111
|
+
// andConditions.push({
|
|
112
|
+
// $or: [
|
|
113
|
+
// {
|
|
114
|
+
// 'name.ja': {
|
|
115
|
+
// $exists: true,
|
|
116
|
+
// $regex: nameRegexExp
|
|
117
|
+
// }
|
|
118
|
+
// },
|
|
119
|
+
// {
|
|
120
|
+
// 'name.en': {
|
|
121
|
+
// $exists: true,
|
|
122
|
+
// $regex: nameRegexExp
|
|
123
|
+
// }
|
|
124
|
+
// },
|
|
125
|
+
// {
|
|
126
|
+
// 'alternateName.ja': {
|
|
127
|
+
// $exists: true,
|
|
128
|
+
// $regex: nameRegexExp
|
|
129
|
+
// }
|
|
130
|
+
// },
|
|
131
|
+
// {
|
|
132
|
+
// 'alternateName.en': {
|
|
133
|
+
// $exists: true,
|
|
134
|
+
// $regex: nameRegexExp
|
|
135
|
+
// }
|
|
136
|
+
// }
|
|
137
|
+
// ]
|
|
138
|
+
// });
|
|
139
|
+
// }
|
|
140
|
+
// const itemOfferedTypeOfEq = params.itemOffered?.typeOf?.$eq;
|
|
141
|
+
// if (typeof itemOfferedTypeOfEq === 'string') {
|
|
142
|
+
// andConditions.push({
|
|
143
|
+
// 'itemOffered.typeOf': {
|
|
144
|
+
// $exists: true,
|
|
145
|
+
// $eq: itemOfferedTypeOfEq
|
|
146
|
+
// }
|
|
147
|
+
// });
|
|
148
|
+
// }
|
|
149
|
+
// const categoryCodeValueIn = params.category?.codeValue?.$in;
|
|
150
|
+
// if (Array.isArray(categoryCodeValueIn)) {
|
|
151
|
+
// andConditions.push({
|
|
152
|
+
// 'category.codeValue': {
|
|
153
|
+
// $exists: true,
|
|
154
|
+
// $in: categoryCodeValueIn
|
|
155
|
+
// }
|
|
156
|
+
// });
|
|
157
|
+
// }
|
|
158
|
+
// const eligibleMembershipTypeCodeValueEq = params.eligibleMembershipType?.codeValue?.$eq;
|
|
159
|
+
// if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
|
|
160
|
+
// andConditions.push({
|
|
161
|
+
// 'eligibleMembershipType.codeValue': {
|
|
162
|
+
// $exists: true,
|
|
163
|
+
// $eq: eligibleMembershipTypeCodeValueEq
|
|
164
|
+
// }
|
|
165
|
+
// });
|
|
166
|
+
// }
|
|
167
|
+
// const eligibleMonetaryAmountCurrencyEq = params.eligibleMonetaryAmount?.currency?.$eq;
|
|
168
|
+
// if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
|
|
169
|
+
// andConditions.push({
|
|
170
|
+
// 'eligibleMonetaryAmount.currency': {
|
|
171
|
+
// $exists: true,
|
|
172
|
+
// $eq: eligibleMonetaryAmountCurrencyEq
|
|
173
|
+
// }
|
|
174
|
+
// });
|
|
175
|
+
// }
|
|
176
|
+
// const eligibleSeatingTypeCodeValueEq = params.eligibleSeatingType?.codeValue?.$eq;
|
|
177
|
+
// if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
|
|
178
|
+
// andConditions.push({
|
|
179
|
+
// 'eligibleSeatingType.codeValue': {
|
|
180
|
+
// $exists: true,
|
|
181
|
+
// $eq: eligibleSeatingTypeCodeValueEq
|
|
182
|
+
// }
|
|
183
|
+
// });
|
|
184
|
+
// }
|
|
185
|
+
// const appliesToMovieTicketServiceTypeExist = params.priceSpecification?.appliesToMovieTicket?.serviceType?.$exists;
|
|
186
|
+
// if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
|
|
187
|
+
// andConditions.push({
|
|
188
|
+
// 'priceSpecification.appliesToMovieTicket.serviceType': {
|
|
189
|
+
// $exists: appliesToMovieTicketServiceTypeExist
|
|
190
|
+
// }
|
|
191
|
+
// });
|
|
192
|
+
// }
|
|
193
|
+
// const appliesToMovieTicketServiceTypeEq = params.priceSpecification?.appliesToMovieTicket?.serviceType?.$eq;
|
|
194
|
+
// if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
|
|
195
|
+
// andConditions.push({
|
|
196
|
+
// 'priceSpecification.appliesToMovieTicket.serviceType': {
|
|
197
|
+
// $exists: true,
|
|
198
|
+
// $eq: appliesToMovieTicketServiceTypeEq
|
|
199
|
+
// }
|
|
200
|
+
// });
|
|
201
|
+
// }
|
|
202
|
+
// const appliesToMovieTicketServiceOutputTypeOfEq = params.priceSpecification?.appliesToMovieTicket?.serviceOutput?.typeOf?.$eq;
|
|
203
|
+
// if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
|
|
204
|
+
// andConditions.push({
|
|
205
|
+
// 'priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
206
|
+
// $exists: true,
|
|
207
|
+
// $eq: appliesToMovieTicketServiceOutputTypeOfEq
|
|
208
|
+
// }
|
|
209
|
+
// });
|
|
210
|
+
// }
|
|
211
|
+
// const appliesToMovieTicketServiceOutputTypeOfNin = params.priceSpecification?.appliesToMovieTicket?.serviceOutput?.typeOf?.$nin;
|
|
212
|
+
// if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
|
|
213
|
+
// andConditions.push({
|
|
214
|
+
// 'priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
215
|
+
// $nin: appliesToMovieTicketServiceOutputTypeOfNin
|
|
216
|
+
// }
|
|
217
|
+
// });
|
|
218
|
+
// }
|
|
219
|
+
// if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
|
|
220
|
+
// const priceSpecificationPriceGte = params.priceSpecification.price?.$gte;
|
|
221
|
+
// if (typeof priceSpecificationPriceGte === 'number') {
|
|
222
|
+
// andConditions.push({
|
|
223
|
+
// 'priceSpecification.price': {
|
|
224
|
+
// $exists: true,
|
|
225
|
+
// $gte: priceSpecificationPriceGte
|
|
226
|
+
// }
|
|
227
|
+
// });
|
|
228
|
+
// }
|
|
229
|
+
// const priceSpecificationPriceLte = params.priceSpecification.price?.$lte;
|
|
230
|
+
// if (typeof priceSpecificationPriceLte === 'number') {
|
|
231
|
+
// andConditions.push({
|
|
232
|
+
// 'priceSpecification.price': {
|
|
233
|
+
// $exists: true,
|
|
234
|
+
// $lte: priceSpecificationPriceLte
|
|
235
|
+
// }
|
|
236
|
+
// });
|
|
237
|
+
// }
|
|
238
|
+
// const accountsReceivableGte = params.priceSpecification.accounting?.accountsReceivable?.$gte;
|
|
239
|
+
// if (typeof accountsReceivableGte === 'number') {
|
|
240
|
+
// andConditions.push({
|
|
241
|
+
// 'priceSpecification.accounting.accountsReceivable': {
|
|
242
|
+
// $exists: true,
|
|
243
|
+
// $gte: accountsReceivableGte
|
|
244
|
+
// }
|
|
245
|
+
// });
|
|
246
|
+
// }
|
|
247
|
+
// const accountsReceivableLte = params.priceSpecification.accounting?.accountsReceivable?.$lte;
|
|
248
|
+
// if (typeof accountsReceivableLte === 'number') {
|
|
249
|
+
// andConditions.push({
|
|
250
|
+
// 'priceSpecification.accounting.accountsReceivable': {
|
|
251
|
+
// $exists: true,
|
|
252
|
+
// $lte: accountsReceivableLte
|
|
253
|
+
// }
|
|
254
|
+
// });
|
|
255
|
+
// }
|
|
256
|
+
// const accountingCodeValueEq = params.priceSpecification.accounting?.operatingRevenue?.codeValue?.$eq;
|
|
257
|
+
// if (typeof accountingCodeValueEq === 'string') {
|
|
258
|
+
// andConditions.push({
|
|
259
|
+
// 'priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
260
|
+
// $exists: true,
|
|
261
|
+
// $eq: accountingCodeValueEq
|
|
262
|
+
// }
|
|
263
|
+
// });
|
|
264
|
+
// }
|
|
265
|
+
// const accountingCodeValueIn = params.priceSpecification.accounting?.operatingRevenue?.codeValue?.$in;
|
|
266
|
+
// if (Array.isArray(accountingCodeValueIn)) {
|
|
267
|
+
// andConditions.push({
|
|
268
|
+
// 'priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
269
|
+
// $exists: true,
|
|
270
|
+
// $in: accountingCodeValueIn
|
|
271
|
+
// }
|
|
272
|
+
// });
|
|
273
|
+
// }
|
|
274
|
+
// const referenceQuantityValueEq = params.priceSpecification.referenceQuantity?.value?.$eq;
|
|
275
|
+
// if (typeof referenceQuantityValueEq === 'number') {
|
|
276
|
+
// andConditions.push({
|
|
277
|
+
// 'priceSpecification.referenceQuantity.value': {
|
|
278
|
+
// $exists: true,
|
|
279
|
+
// $eq: referenceQuantityValueEq
|
|
280
|
+
// }
|
|
281
|
+
// });
|
|
282
|
+
// }
|
|
283
|
+
// }
|
|
284
|
+
// const availabilityEq = params.availability?.$eq;
|
|
285
|
+
// if (typeof availabilityEq === 'string') {
|
|
286
|
+
// andConditions.push({ availability: { $eq: availabilityEq } });
|
|
287
|
+
// }
|
|
288
|
+
// const availableAtOrFromIdEq = params.availableAtOrFrom?.id?.$eq;
|
|
289
|
+
// if (typeof availableAtOrFromIdEq === 'string') {
|
|
290
|
+
// andConditions.push({
|
|
291
|
+
// 'availableAtOrFrom.id': {
|
|
292
|
+
// $exists: true,
|
|
293
|
+
// $eq: availableAtOrFromIdEq
|
|
294
|
+
// }
|
|
295
|
+
// });
|
|
296
|
+
// }
|
|
297
|
+
// const availableAtOrFromIdIn = params.availableAtOrFrom?.id?.$in;
|
|
298
|
+
// if (Array.isArray(availableAtOrFromIdIn)) {
|
|
299
|
+
// andConditions.push({
|
|
300
|
+
// 'availableAtOrFrom.id': {
|
|
301
|
+
// $exists: true,
|
|
302
|
+
// $in: availableAtOrFromIdIn
|
|
303
|
+
// }
|
|
304
|
+
// });
|
|
305
|
+
// }
|
|
306
|
+
// const addOnItemOfferedIdEq = params.addOn?.itemOffered?.id?.$eq;
|
|
307
|
+
// if (typeof addOnItemOfferedIdEq === 'string') {
|
|
308
|
+
// andConditions.push({
|
|
309
|
+
// 'addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
|
|
310
|
+
// });
|
|
311
|
+
// }
|
|
312
|
+
// const addOnItemOfferedIdIn = params.addOn?.itemOffered?.id?.$in;
|
|
313
|
+
// if (Array.isArray(addOnItemOfferedIdIn)) {
|
|
314
|
+
// andConditions.push({
|
|
315
|
+
// 'addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
|
|
316
|
+
// });
|
|
317
|
+
// }
|
|
318
|
+
// const hasMerchantReturnPolicyIdEq = params.hasMerchantReturnPolicy?.id?.$eq;
|
|
319
|
+
// if (typeof hasMerchantReturnPolicyIdEq === 'string') {
|
|
320
|
+
// andConditions.push({
|
|
321
|
+
// 'hasMerchantReturnPolicy.id': {
|
|
322
|
+
// $exists: true,
|
|
323
|
+
// $eq: hasMerchantReturnPolicyIdEq
|
|
324
|
+
// }
|
|
325
|
+
// });
|
|
326
|
+
// }
|
|
327
|
+
// const additionalPropertyAll = params.additionalProperty?.$all;
|
|
328
|
+
// if (Array.isArray(additionalPropertyAll)) {
|
|
329
|
+
// andConditions.push({
|
|
330
|
+
// additionalProperty: {
|
|
331
|
+
// $exists: true,
|
|
332
|
+
// $all: additionalPropertyAll
|
|
333
|
+
// }
|
|
334
|
+
// });
|
|
335
|
+
// }
|
|
336
|
+
// const additionalPropertyElemMatch = params.additionalProperty?.$elemMatch;
|
|
337
|
+
// if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
338
|
+
// andConditions.push({
|
|
339
|
+
// additionalProperty: {
|
|
340
|
+
// $exists: true,
|
|
341
|
+
// $elemMatch: additionalPropertyElemMatch
|
|
342
|
+
// }
|
|
343
|
+
// });
|
|
344
|
+
// }
|
|
345
|
+
// if (params.onlyValid === true) {
|
|
346
|
+
// const now = new Date();
|
|
347
|
+
// andConditions.push(
|
|
348
|
+
// {
|
|
349
|
+
// $or: [
|
|
350
|
+
// { validFrom: { $exists: false } },
|
|
351
|
+
// { validFrom: { $exists: true, $lte: now } }
|
|
352
|
+
// ]
|
|
353
|
+
// },
|
|
354
|
+
// {
|
|
355
|
+
// $or: [
|
|
356
|
+
// { validThrough: { $exists: false } },
|
|
357
|
+
// { validThrough: { $exists: true, $gte: now } }
|
|
358
|
+
// ]
|
|
359
|
+
// }
|
|
360
|
+
// );
|
|
361
|
+
// }
|
|
362
|
+
// return andConditions;
|
|
363
|
+
// }
|
|
364
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
365
|
+
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
|
|
366
|
+
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;
|
|
367
|
+
const matchStages = [];
|
|
42
368
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
43
369
|
if (typeof projectIdEq === 'string') {
|
|
44
|
-
|
|
45
|
-
'project.id': {
|
|
46
|
-
$eq: projectIdEq
|
|
47
|
-
}
|
|
370
|
+
matchStages.push({
|
|
371
|
+
$match: { 'project.id': { $eq: projectIdEq } }
|
|
48
372
|
});
|
|
49
373
|
}
|
|
50
|
-
const
|
|
374
|
+
const parentOfferIdIn = (_d = (_c = params.parentOffer) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$in;
|
|
375
|
+
if (Array.isArray(parentOfferIdIn)) {
|
|
376
|
+
matchStages.push({ $match: { _id: { $in: parentOfferIdIn } } });
|
|
377
|
+
}
|
|
378
|
+
const idEq = (_e = params.id) === null || _e === void 0 ? void 0 : _e.$eq;
|
|
51
379
|
if (typeof idEq === 'string') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
$eq: idEq
|
|
55
|
-
}
|
|
380
|
+
matchStages.push({
|
|
381
|
+
$match: { 'offers.id': { $eq: idEq } }
|
|
56
382
|
});
|
|
57
383
|
}
|
|
58
|
-
const idIn = (
|
|
384
|
+
const idIn = (_f = params.id) === null || _f === void 0 ? void 0 : _f.$in;
|
|
59
385
|
if (Array.isArray(idIn)) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$in: idIn
|
|
63
|
-
}
|
|
386
|
+
matchStages.push({
|
|
387
|
+
$match: { 'offers.id': { $in: idIn } }
|
|
64
388
|
});
|
|
65
389
|
}
|
|
66
|
-
const identifierEq = (
|
|
390
|
+
const identifierEq = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
67
391
|
if (typeof identifierEq === 'string') {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
$exists: true,
|
|
71
|
-
$eq: identifierEq
|
|
392
|
+
matchStages.push({
|
|
393
|
+
$match: {
|
|
394
|
+
'offers.identifier': { $exists: true, $eq: identifierEq }
|
|
72
395
|
}
|
|
73
396
|
});
|
|
74
397
|
}
|
|
75
|
-
const identifierIn = (
|
|
398
|
+
const identifierIn = (_h = params.identifier) === null || _h === void 0 ? void 0 : _h.$in;
|
|
76
399
|
if (Array.isArray(identifierIn)) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$exists: true,
|
|
80
|
-
$in: identifierIn
|
|
400
|
+
matchStages.push({
|
|
401
|
+
$match: {
|
|
402
|
+
'offers.identifier': { $exists: true, $in: identifierIn }
|
|
81
403
|
}
|
|
82
404
|
});
|
|
83
405
|
}
|
|
84
|
-
const identifierRegex = (
|
|
406
|
+
const identifierRegex = (_j = params.identifier) === null || _j === void 0 ? void 0 : _j.$regex;
|
|
85
407
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
$exists: true,
|
|
89
|
-
$regex: new RegExp(identifierRegex)
|
|
408
|
+
matchStages.push({
|
|
409
|
+
$match: {
|
|
410
|
+
'offers.identifier': { $exists: true, $regex: new RegExp(identifierRegex) }
|
|
90
411
|
}
|
|
91
412
|
});
|
|
92
413
|
}
|
|
93
|
-
const nameRegex = (
|
|
414
|
+
const nameRegex = (_k = params.name) === null || _k === void 0 ? void 0 : _k.$regex;
|
|
94
415
|
if (typeof nameRegex === 'string' && nameRegex.length > 0) {
|
|
95
416
|
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
|
-
]
|
|
417
|
+
matchStages.push({
|
|
418
|
+
$match: {
|
|
419
|
+
$or: [
|
|
420
|
+
{ 'offers.name.ja': { $exists: true, $regex: nameRegexExp } },
|
|
421
|
+
{ 'offers.name.en': { $exists: true, $regex: nameRegexExp } },
|
|
422
|
+
{ 'offers.alternateName.ja': { $exists: true, $regex: nameRegexExp } },
|
|
423
|
+
{ 'offers.alternateName.en': { $exists: true, $regex: nameRegexExp } }
|
|
424
|
+
]
|
|
425
|
+
}
|
|
123
426
|
});
|
|
124
427
|
}
|
|
125
|
-
const itemOfferedTypeOfEq = (
|
|
428
|
+
const itemOfferedTypeOfEq = (_m = (_l = params.itemOffered) === null || _l === void 0 ? void 0 : _l.typeOf) === null || _m === void 0 ? void 0 : _m.$eq;
|
|
126
429
|
if (typeof itemOfferedTypeOfEq === 'string') {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
$exists: true,
|
|
130
|
-
$eq: itemOfferedTypeOfEq
|
|
430
|
+
matchStages.push({
|
|
431
|
+
$match: {
|
|
432
|
+
'offers.itemOffered.typeOf': { $exists: true, $eq: itemOfferedTypeOfEq }
|
|
131
433
|
}
|
|
132
434
|
});
|
|
133
435
|
}
|
|
134
|
-
const categoryCodeValueIn = (
|
|
436
|
+
const categoryCodeValueIn = (_p = (_o = params.category) === null || _o === void 0 ? void 0 : _o.codeValue) === null || _p === void 0 ? void 0 : _p.$in;
|
|
135
437
|
if (Array.isArray(categoryCodeValueIn)) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
$exists: true,
|
|
139
|
-
$in: categoryCodeValueIn
|
|
438
|
+
matchStages.push({
|
|
439
|
+
$match: {
|
|
440
|
+
'offers.category.codeValue': { $exists: true, $in: categoryCodeValueIn }
|
|
140
441
|
}
|
|
141
442
|
});
|
|
142
443
|
}
|
|
143
|
-
const eligibleMembershipTypeCodeValueEq = (
|
|
444
|
+
const eligibleMembershipTypeCodeValueEq = (_r = (_q = params.eligibleMembershipType) === null || _q === void 0 ? void 0 : _q.codeValue) === null || _r === void 0 ? void 0 : _r.$eq;
|
|
144
445
|
if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
446
|
+
matchStages.push({
|
|
447
|
+
$match: {
|
|
448
|
+
'offers.eligibleMembershipType.codeValue': {
|
|
449
|
+
$exists: true,
|
|
450
|
+
$eq: eligibleMembershipTypeCodeValueEq
|
|
451
|
+
}
|
|
149
452
|
}
|
|
150
453
|
});
|
|
151
454
|
}
|
|
152
|
-
const eligibleMonetaryAmountCurrencyEq = (
|
|
455
|
+
const eligibleMonetaryAmountCurrencyEq = (_t = (_s = params.eligibleMonetaryAmount) === null || _s === void 0 ? void 0 : _s.currency) === null || _t === void 0 ? void 0 : _t.$eq;
|
|
153
456
|
if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
457
|
+
matchStages.push({
|
|
458
|
+
$match: {
|
|
459
|
+
'offers.eligibleMonetaryAmount.currency': {
|
|
460
|
+
$exists: true,
|
|
461
|
+
$eq: eligibleMonetaryAmountCurrencyEq
|
|
462
|
+
}
|
|
158
463
|
}
|
|
159
464
|
});
|
|
160
465
|
}
|
|
161
|
-
const eligibleSeatingTypeCodeValueEq = (
|
|
466
|
+
const eligibleSeatingTypeCodeValueEq = (_v = (_u = params.eligibleSeatingType) === null || _u === void 0 ? void 0 : _u.codeValue) === null || _v === void 0 ? void 0 : _v.$eq;
|
|
162
467
|
if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
468
|
+
matchStages.push({
|
|
469
|
+
$match: {
|
|
470
|
+
'offers.eligibleSeatingType.codeValue': {
|
|
471
|
+
$exists: true,
|
|
472
|
+
$eq: eligibleSeatingTypeCodeValueEq
|
|
473
|
+
}
|
|
167
474
|
}
|
|
168
475
|
});
|
|
169
476
|
}
|
|
170
|
-
const appliesToMovieTicketServiceTypeExist = (
|
|
477
|
+
const appliesToMovieTicketServiceTypeExist = (_y = (_x = (_w = params.priceSpecification) === null || _w === void 0 ? void 0 : _w.appliesToMovieTicket) === null || _x === void 0 ? void 0 : _x.serviceType) === null || _y === void 0 ? void 0 : _y.$exists;
|
|
171
478
|
if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
479
|
+
matchStages.push({
|
|
480
|
+
$match: {
|
|
481
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': {
|
|
482
|
+
$exists: appliesToMovieTicketServiceTypeExist
|
|
483
|
+
}
|
|
175
484
|
}
|
|
176
485
|
});
|
|
177
486
|
}
|
|
178
|
-
const appliesToMovieTicketServiceTypeEq = (
|
|
487
|
+
const appliesToMovieTicketServiceTypeEq = (_1 = (_0 = (_z = params.priceSpecification) === null || _z === void 0 ? void 0 : _z.appliesToMovieTicket) === null || _0 === void 0 ? void 0 : _0.serviceType) === null || _1 === void 0 ? void 0 : _1.$eq;
|
|
179
488
|
if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
489
|
+
matchStages.push({
|
|
490
|
+
$match: {
|
|
491
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceType': {
|
|
492
|
+
$exists: true,
|
|
493
|
+
$eq: appliesToMovieTicketServiceTypeEq
|
|
494
|
+
}
|
|
184
495
|
}
|
|
185
496
|
});
|
|
186
497
|
}
|
|
187
|
-
const appliesToMovieTicketServiceOutputTypeOfEq = (
|
|
498
|
+
const appliesToMovieTicketServiceOutputTypeOfEq = (_5 = (_4 = (_3 = (_2 = params.priceSpecification) === null || _2 === void 0 ? void 0 : _2.appliesToMovieTicket) === null || _3 === void 0 ? void 0 : _3.serviceOutput) === null || _4 === void 0 ? void 0 : _4.typeOf) === null || _5 === void 0 ? void 0 : _5.$eq;
|
|
188
499
|
if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
500
|
+
matchStages.push({
|
|
501
|
+
$match: {
|
|
502
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
503
|
+
$exists: true,
|
|
504
|
+
$eq: appliesToMovieTicketServiceOutputTypeOfEq
|
|
505
|
+
}
|
|
193
506
|
}
|
|
194
507
|
});
|
|
195
508
|
}
|
|
196
|
-
const appliesToMovieTicketServiceOutputTypeOfNin = (
|
|
509
|
+
const appliesToMovieTicketServiceOutputTypeOfNin = (_9 = (_8 = (_7 = (_6 = params.priceSpecification) === null || _6 === void 0 ? void 0 : _6.appliesToMovieTicket) === null || _7 === void 0 ? void 0 : _7.serviceOutput) === null || _8 === void 0 ? void 0 : _8.typeOf) === null || _9 === void 0 ? void 0 : _9.$nin;
|
|
197
510
|
if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
511
|
+
matchStages.push({
|
|
512
|
+
$match: {
|
|
513
|
+
'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
|
|
514
|
+
$nin: appliesToMovieTicketServiceOutputTypeOfNin
|
|
515
|
+
}
|
|
201
516
|
}
|
|
202
517
|
});
|
|
203
518
|
}
|
|
204
519
|
if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
|
|
205
|
-
const priceSpecificationPriceGte = (
|
|
520
|
+
const priceSpecificationPriceGte = (_10 = params.priceSpecification.price) === null || _10 === void 0 ? void 0 : _10.$gte;
|
|
206
521
|
if (typeof priceSpecificationPriceGte === 'number') {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
522
|
+
matchStages.push({
|
|
523
|
+
$match: {
|
|
524
|
+
'offers.priceSpecification.price': {
|
|
525
|
+
$exists: true,
|
|
526
|
+
$gte: priceSpecificationPriceGte
|
|
527
|
+
}
|
|
211
528
|
}
|
|
212
529
|
});
|
|
213
530
|
}
|
|
214
|
-
const priceSpecificationPriceLte = (
|
|
531
|
+
const priceSpecificationPriceLte = (_11 = params.priceSpecification.price) === null || _11 === void 0 ? void 0 : _11.$lte;
|
|
215
532
|
if (typeof priceSpecificationPriceLte === 'number') {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
533
|
+
matchStages.push({
|
|
534
|
+
$match: {
|
|
535
|
+
'offers.priceSpecification.price': {
|
|
536
|
+
$exists: true,
|
|
537
|
+
$lte: priceSpecificationPriceLte
|
|
538
|
+
}
|
|
220
539
|
}
|
|
221
540
|
});
|
|
222
541
|
}
|
|
223
|
-
const accountsReceivableGte = (
|
|
542
|
+
const accountsReceivableGte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$gte;
|
|
224
543
|
if (typeof accountsReceivableGte === 'number') {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
544
|
+
matchStages.push({
|
|
545
|
+
$match: {
|
|
546
|
+
'offers.priceSpecification.accounting.accountsReceivable': {
|
|
547
|
+
$exists: true,
|
|
548
|
+
$gte: accountsReceivableGte
|
|
549
|
+
}
|
|
229
550
|
}
|
|
230
551
|
});
|
|
231
552
|
}
|
|
232
|
-
const accountsReceivableLte = (
|
|
553
|
+
const accountsReceivableLte = (_15 = (_14 = params.priceSpecification.accounting) === null || _14 === void 0 ? void 0 : _14.accountsReceivable) === null || _15 === void 0 ? void 0 : _15.$lte;
|
|
233
554
|
if (typeof accountsReceivableLte === 'number') {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
555
|
+
matchStages.push({
|
|
556
|
+
$match: {
|
|
557
|
+
'offers.priceSpecification.accounting.accountsReceivable': {
|
|
558
|
+
$exists: true,
|
|
559
|
+
$lte: accountsReceivableLte
|
|
560
|
+
}
|
|
238
561
|
}
|
|
239
562
|
});
|
|
240
563
|
}
|
|
241
|
-
const accountingCodeValueEq = (
|
|
564
|
+
const accountingCodeValueEq = (_18 = (_17 = (_16 = params.priceSpecification.accounting) === null || _16 === void 0 ? void 0 : _16.operatingRevenue) === null || _17 === void 0 ? void 0 : _17.codeValue) === null || _18 === void 0 ? void 0 : _18.$eq;
|
|
242
565
|
if (typeof accountingCodeValueEq === 'string') {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
566
|
+
matchStages.push({
|
|
567
|
+
$match: {
|
|
568
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
569
|
+
$exists: true,
|
|
570
|
+
$eq: accountingCodeValueEq
|
|
571
|
+
}
|
|
247
572
|
}
|
|
248
573
|
});
|
|
249
574
|
}
|
|
250
|
-
const accountingCodeValueIn = (
|
|
575
|
+
const accountingCodeValueIn = (_21 = (_20 = (_19 = params.priceSpecification.accounting) === null || _19 === void 0 ? void 0 : _19.operatingRevenue) === null || _20 === void 0 ? void 0 : _20.codeValue) === null || _21 === void 0 ? void 0 : _21.$in;
|
|
251
576
|
if (Array.isArray(accountingCodeValueIn)) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
577
|
+
matchStages.push({
|
|
578
|
+
$match: {
|
|
579
|
+
'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
|
|
580
|
+
$exists: true,
|
|
581
|
+
$in: accountingCodeValueIn
|
|
582
|
+
}
|
|
256
583
|
}
|
|
257
584
|
});
|
|
258
585
|
}
|
|
259
|
-
const referenceQuantityValueEq = (
|
|
586
|
+
const referenceQuantityValueEq = (_23 = (_22 = params.priceSpecification.referenceQuantity) === null || _22 === void 0 ? void 0 : _22.value) === null || _23 === void 0 ? void 0 : _23.$eq;
|
|
260
587
|
if (typeof referenceQuantityValueEq === 'number') {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
588
|
+
matchStages.push({
|
|
589
|
+
$match: {
|
|
590
|
+
'offers.priceSpecification.referenceQuantity.value': {
|
|
591
|
+
$exists: true,
|
|
592
|
+
$eq: referenceQuantityValueEq
|
|
593
|
+
}
|
|
265
594
|
}
|
|
266
595
|
});
|
|
267
596
|
}
|
|
268
597
|
}
|
|
269
|
-
const availabilityEq = (
|
|
598
|
+
const availabilityEq = (_24 = params.availability) === null || _24 === void 0 ? void 0 : _24.$eq;
|
|
270
599
|
if (typeof availabilityEq === 'string') {
|
|
271
|
-
|
|
600
|
+
matchStages.push({
|
|
601
|
+
$match: {
|
|
602
|
+
'offers.availability': { $eq: availabilityEq }
|
|
603
|
+
}
|
|
604
|
+
});
|
|
272
605
|
}
|
|
273
|
-
const availableAtOrFromIdEq = (
|
|
606
|
+
const availableAtOrFromIdEq = (_26 = (_25 = params.availableAtOrFrom) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$eq;
|
|
274
607
|
if (typeof availableAtOrFromIdEq === 'string') {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
608
|
+
matchStages.push({
|
|
609
|
+
$match: {
|
|
610
|
+
'offers.availableAtOrFrom.id': {
|
|
611
|
+
$exists: true,
|
|
612
|
+
$eq: availableAtOrFromIdEq
|
|
613
|
+
}
|
|
279
614
|
}
|
|
280
615
|
});
|
|
281
616
|
}
|
|
282
|
-
const availableAtOrFromIdIn = (
|
|
617
|
+
const availableAtOrFromIdIn = (_28 = (_27 = params.availableAtOrFrom) === null || _27 === void 0 ? void 0 : _27.id) === null || _28 === void 0 ? void 0 : _28.$in;
|
|
283
618
|
if (Array.isArray(availableAtOrFromIdIn)) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
619
|
+
matchStages.push({
|
|
620
|
+
$match: {
|
|
621
|
+
'offers.availableAtOrFrom.id': {
|
|
622
|
+
$exists: true,
|
|
623
|
+
$in: availableAtOrFromIdIn
|
|
624
|
+
}
|
|
288
625
|
}
|
|
289
626
|
});
|
|
290
627
|
}
|
|
291
|
-
const addOnItemOfferedIdEq = (
|
|
628
|
+
const addOnItemOfferedIdEq = (_31 = (_30 = (_29 = params.addOn) === null || _29 === void 0 ? void 0 : _29.itemOffered) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
|
|
292
629
|
if (typeof addOnItemOfferedIdEq === 'string') {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
$exists: true,
|
|
296
|
-
|
|
630
|
+
matchStages.push({
|
|
631
|
+
$match: {
|
|
632
|
+
'offers.addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
const addOnItemOfferedIdIn = (_34 = (_33 = (_32 = params.addOn) === null || _32 === void 0 ? void 0 : _32.itemOffered) === null || _33 === void 0 ? void 0 : _33.id) === null || _34 === void 0 ? void 0 : _34.$in;
|
|
637
|
+
if (Array.isArray(addOnItemOfferedIdIn)) {
|
|
638
|
+
matchStages.push({
|
|
639
|
+
$match: {
|
|
640
|
+
'offers.addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
|
|
297
641
|
}
|
|
298
642
|
});
|
|
299
643
|
}
|
|
300
|
-
const hasMerchantReturnPolicyIdEq = (
|
|
644
|
+
const hasMerchantReturnPolicyIdEq = (_36 = (_35 = params.hasMerchantReturnPolicy) === null || _35 === void 0 ? void 0 : _35.id) === null || _36 === void 0 ? void 0 : _36.$eq;
|
|
301
645
|
if (typeof hasMerchantReturnPolicyIdEq === 'string') {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
646
|
+
matchStages.push({
|
|
647
|
+
$match: {
|
|
648
|
+
'offers.hasMerchantReturnPolicy.id': {
|
|
649
|
+
$exists: true,
|
|
650
|
+
$eq: hasMerchantReturnPolicyIdEq
|
|
651
|
+
}
|
|
306
652
|
}
|
|
307
653
|
});
|
|
308
654
|
}
|
|
309
|
-
const additionalPropertyAll = (
|
|
655
|
+
const additionalPropertyAll = (_37 = params.additionalProperty) === null || _37 === void 0 ? void 0 : _37.$all;
|
|
310
656
|
if (Array.isArray(additionalPropertyAll)) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
657
|
+
matchStages.push({
|
|
658
|
+
$match: {
|
|
659
|
+
'offers.additionalProperty': {
|
|
660
|
+
$exists: true,
|
|
661
|
+
$all: additionalPropertyAll
|
|
662
|
+
}
|
|
315
663
|
}
|
|
316
664
|
});
|
|
317
665
|
}
|
|
318
|
-
const additionalPropertyElemMatch = (
|
|
666
|
+
const additionalPropertyElemMatch = (_38 = params.additionalProperty) === null || _38 === void 0 ? void 0 : _38.$elemMatch;
|
|
319
667
|
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
668
|
+
matchStages.push({
|
|
669
|
+
$match: {
|
|
670
|
+
'offers.additionalProperty': {
|
|
671
|
+
$exists: true,
|
|
672
|
+
$elemMatch: additionalPropertyElemMatch
|
|
673
|
+
}
|
|
324
674
|
}
|
|
325
675
|
});
|
|
326
676
|
}
|
|
327
677
|
if (params.onlyValid === true) {
|
|
328
678
|
const now = new Date();
|
|
329
|
-
|
|
330
|
-
$
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
679
|
+
matchStages.push({
|
|
680
|
+
$match: {
|
|
681
|
+
$or: [
|
|
682
|
+
{ 'offers.validFrom': { $exists: false } },
|
|
683
|
+
{ 'offers.validFrom': { $exists: true, $lte: now } }
|
|
684
|
+
]
|
|
685
|
+
}
|
|
334
686
|
}, {
|
|
335
|
-
$
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
687
|
+
$match: {
|
|
688
|
+
$or: [
|
|
689
|
+
{ 'offers.validThrough': { $exists: false } },
|
|
690
|
+
{ 'offers.validThrough': { $exists: true, $gte: now } }
|
|
691
|
+
]
|
|
692
|
+
}
|
|
339
693
|
});
|
|
340
694
|
}
|
|
341
|
-
return
|
|
695
|
+
return matchStages;
|
|
696
|
+
}
|
|
697
|
+
static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
|
|
698
|
+
let projectStage = {
|
|
699
|
+
_id: 0,
|
|
700
|
+
offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
|
|
701
|
+
parentOffer: {
|
|
702
|
+
id: '$_id'
|
|
703
|
+
},
|
|
704
|
+
typeOf: '$offers.typeOf',
|
|
705
|
+
project: '$project',
|
|
706
|
+
id: '$offers.id',
|
|
707
|
+
identifier: '$offers.identifier',
|
|
708
|
+
name: '$offers.name',
|
|
709
|
+
description: '$offers.description',
|
|
710
|
+
category: '$offers.category',
|
|
711
|
+
color: '$offers.color',
|
|
712
|
+
additionalProperty: '$offers.additionalProperty',
|
|
713
|
+
advanceBookingRequirement: '$offers.advanceBookingRequirement',
|
|
714
|
+
alternateName: '$offers.alternateName',
|
|
715
|
+
addOn: '$offers.addOn',
|
|
716
|
+
availability: '$offers.availability',
|
|
717
|
+
availableAtOrFrom: '$offers.availableAtOrFrom',
|
|
718
|
+
hasMerchantReturnPolicy: '$offers.hasMerchantReturnPolicy',
|
|
719
|
+
itemOffered: '$offers.itemOffered',
|
|
720
|
+
priceCurrency: '$offers.priceCurrency',
|
|
721
|
+
priceSpecification: '$offers.priceSpecification',
|
|
722
|
+
eligibleCustomerType: '$offers.eligibleCustomerType',
|
|
723
|
+
eligibleDuration: '$offers.eligibleDuration',
|
|
724
|
+
eligibleMembershipType: '$offers.eligibleMembershipType',
|
|
725
|
+
eligibleMonetaryAmount: '$offers.eligibleMonetaryAmount',
|
|
726
|
+
eligibleQuantity: '$offers.eligibleQuantity',
|
|
727
|
+
eligibleRegion: '$offers.eligibleRegion',
|
|
728
|
+
eligibleSeatingType: '$offers.eligibleSeatingType',
|
|
729
|
+
eligibleSubReservation: '$offers.eligibleSubReservation',
|
|
730
|
+
settings: '$offers.settings',
|
|
731
|
+
validFrom: '$offers.validFrom',
|
|
732
|
+
validThrough: '$offers.validThrough',
|
|
733
|
+
validRateLimit: '$offers.validRateLimit'
|
|
734
|
+
};
|
|
735
|
+
const positiveProjectionFields = Object.keys(params)
|
|
736
|
+
.filter((key) => params[key] !== 0);
|
|
737
|
+
const negativeProjectionFields = Object.keys(params)
|
|
738
|
+
.filter((key) => params[key] === 0);
|
|
739
|
+
if (positiveProjectionFields.length > 0) {
|
|
740
|
+
projectStage = {
|
|
741
|
+
_id: 0,
|
|
742
|
+
offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
|
|
743
|
+
parentOffer: {
|
|
744
|
+
id: '$_id'
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
positiveProjectionFields.forEach((field) => {
|
|
748
|
+
projectStage[field] = `$offers.${field}`;
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
else if (negativeProjectionFields.length > 0) {
|
|
752
|
+
negativeProjectionFields.forEach((field) => {
|
|
753
|
+
if (typeof projectStage[field] === 'string') {
|
|
754
|
+
// tslint:disable-next-line:no-dynamic-delete
|
|
755
|
+
delete projectStage[field];
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
return projectStage;
|
|
342
760
|
}
|
|
343
761
|
/**
|
|
344
|
-
* カタログに含まれるオファーを検索する
|
|
345
|
-
*
|
|
762
|
+
* カタログに含まれるオファーを検索する(カタログ内ソートは保証しない)
|
|
763
|
+
* カタログ内ソートインデックスはsortedOfferIdsで判断する
|
|
346
764
|
*/
|
|
347
765
|
findOffersByOfferCatalogId(params) {
|
|
348
766
|
var _a;
|
|
349
767
|
return __awaiter(this, void 0, void 0, function* () {
|
|
768
|
+
const unitPriceOfferIds = params.ids;
|
|
769
|
+
let aggregateOfferIds = unitPriceOfferIds; // offersを使用していた段階では、集計オファーIDリストは単価オファーIDリストに等しい
|
|
770
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY && Array.isArray(unitPriceOfferIds)) {
|
|
771
|
+
// 解釈を集計オファーIDに変更する必要がある(2023-09-11~)
|
|
772
|
+
// 単価オファーIDリスト→集計オファーIDに変換→カタログ条件にセット
|
|
773
|
+
const searchDistinctAggregateOfferIdsResult = yield this.aggregateOfferModel.distinct('_id', { 'offers.id': { $in: unitPriceOfferIds } })
|
|
774
|
+
.exec();
|
|
775
|
+
aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
|
|
776
|
+
}
|
|
350
777
|
// aggregateで再実装(2023-01-26~)
|
|
351
778
|
const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
|
|
352
|
-
if (Array.isArray(
|
|
353
|
-
matchStages.push({
|
|
354
|
-
$match: { 'itemListElement.id': { $exists: true, $in: params.ids } }
|
|
355
|
-
});
|
|
779
|
+
if (Array.isArray(aggregateOfferIds)) {
|
|
780
|
+
matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: aggregateOfferIds } } });
|
|
356
781
|
}
|
|
357
|
-
const
|
|
782
|
+
const itemListElements = yield this.offerCatalogModel.aggregate([
|
|
358
783
|
{ $unwind: '$itemListElement' },
|
|
359
784
|
...matchStages,
|
|
360
785
|
{
|
|
@@ -363,14 +788,17 @@ class MongoRepository {
|
|
|
363
788
|
id: '$itemListElement.id'
|
|
364
789
|
}
|
|
365
790
|
}
|
|
366
|
-
])
|
|
367
|
-
|
|
791
|
+
])
|
|
792
|
+
.exec();
|
|
368
793
|
const sortedOfferIds = (Array.isArray(itemListElements))
|
|
369
794
|
? itemListElements.map((element) => element.id)
|
|
370
795
|
: [];
|
|
371
796
|
let offers = [];
|
|
372
797
|
if (sortedOfferIds.length > 0) {
|
|
373
|
-
const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
|
|
798
|
+
const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
|
|
799
|
+
// aggregateOffer.idで検索する(2023-09-09~)
|
|
800
|
+
// id: { $in: sortedOfferIds },
|
|
801
|
+
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
802
|
? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
|
|
375
803
|
: undefined), { priceSpecification: {
|
|
376
804
|
appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
|
|
@@ -385,116 +813,341 @@ class MongoRepository {
|
|
|
385
813
|
}
|
|
386
814
|
: undefined)
|
|
387
815
|
}, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
|
|
388
|
-
|
|
816
|
+
// 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
|
|
817
|
+
? { sort: { identifier: factory.sortType.Ascending } }
|
|
389
818
|
: undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
819
|
+
const useOffersAsPrimary = (params.useOffersAsPrimaryForcible === true);
|
|
820
|
+
offers = yield this.search(searchOffersConditions, params.projection, useOffersAsPrimary);
|
|
821
|
+
// 完全廃止(基本的にsortedOfferIdsと合わせて利用する想定)(2023-09-04~)
|
|
822
|
+
// if (params.sort) {
|
|
823
|
+
// // sorting
|
|
824
|
+
// offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
|
|
825
|
+
// }
|
|
395
826
|
}
|
|
396
827
|
return { offers, sortedOfferIds };
|
|
397
828
|
});
|
|
398
829
|
}
|
|
399
|
-
|
|
830
|
+
// 不要なので廃止(2023-09-11~)
|
|
831
|
+
// public async findById(params: {
|
|
832
|
+
// project: { id: string };
|
|
833
|
+
// id: string;
|
|
834
|
+
// }): Promise<factory.unitPriceOffer.IUnitPriceOffer> {
|
|
835
|
+
// const offers = await this.search({
|
|
836
|
+
// limit: 1,
|
|
837
|
+
// page: 1,
|
|
838
|
+
// project: { id: { $eq: params.project.id } },
|
|
839
|
+
// id: { $eq: params.id }
|
|
840
|
+
// });
|
|
841
|
+
// const unitPriceOffer = offers.shift();
|
|
842
|
+
// if (unitPriceOffer === undefined) {
|
|
843
|
+
// throw new factory.errors.NotFound(factory.offerType.Offer);
|
|
844
|
+
// }
|
|
845
|
+
// return unitPriceOffer;
|
|
846
|
+
// }
|
|
847
|
+
findAggregateOfferById(params) {
|
|
400
848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
-
const doc = yield this.
|
|
849
|
+
const doc = yield this.aggregateOfferModel.findOne({
|
|
850
|
+
_id: { $eq: params.id },
|
|
851
|
+
'project.id': { $eq: params.project.id }
|
|
852
|
+
}, {
|
|
402
853
|
__v: 0,
|
|
403
854
|
createdAt: 0,
|
|
404
855
|
updatedAt: 0
|
|
405
856
|
})
|
|
406
857
|
.exec();
|
|
407
858
|
if (doc === null) {
|
|
408
|
-
throw new factory.errors.NotFound(this.
|
|
859
|
+
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
409
860
|
}
|
|
410
861
|
return doc.toObject();
|
|
411
862
|
});
|
|
412
863
|
}
|
|
413
864
|
count(params) {
|
|
414
865
|
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
.
|
|
866
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
867
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
868
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
869
|
+
const [{ offerCount }] = yield this.aggregateOfferModel.aggregate([
|
|
870
|
+
{
|
|
871
|
+
$unwind: { path: '$offers' }
|
|
872
|
+
},
|
|
873
|
+
...matchStages,
|
|
874
|
+
{
|
|
875
|
+
$count: 'offerCount'
|
|
876
|
+
}
|
|
877
|
+
])
|
|
878
|
+
.exec();
|
|
879
|
+
return offerCount;
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
883
|
+
// const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
|
|
884
|
+
// return this.offerModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
885
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
886
|
+
// .exec();
|
|
887
|
+
}
|
|
419
888
|
});
|
|
420
889
|
}
|
|
421
|
-
search(params, projection
|
|
422
|
-
|
|
890
|
+
search(params, projection,
|
|
891
|
+
/**
|
|
892
|
+
* 強制的にoffersコレクションを使用する
|
|
893
|
+
*/
|
|
894
|
+
useOffersAsPrimary) {
|
|
423
895
|
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
-
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
: false;
|
|
429
|
-
const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, (positiveProjectionExists)
|
|
430
|
-
? projection
|
|
431
|
-
: Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
|
|
432
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
433
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
434
|
-
query.limit(params.limit)
|
|
435
|
-
.skip(params.limit * (page - 1));
|
|
896
|
+
// primaryコレクションをコントロール(2023-09-05~)
|
|
897
|
+
const useAggregateOfferAsPrimary = settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY && (useOffersAsPrimary !== true);
|
|
898
|
+
if (useAggregateOfferAsPrimary) {
|
|
899
|
+
return this.searchFromAggregateOffer(params, projection);
|
|
436
900
|
}
|
|
437
|
-
//
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
query.sort({ 'priceSpecification.price': params.sort['priceSpecification.price'] });
|
|
901
|
+
// useOffersAsPrimary禁止設定(2023-09-09~)
|
|
902
|
+
if (settings_1.USE_PROHIBIT_OFFERS_AS_PRIMARY) {
|
|
903
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
441
904
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
905
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
906
|
+
// const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
|
|
907
|
+
// const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
|
|
908
|
+
// ? Object.values(projection)
|
|
909
|
+
// .some((value) => value !== 0)
|
|
910
|
+
// : false;
|
|
911
|
+
// const query = this.offerModel.find<Document<string, factory.unitPriceOffer.IUnitPriceOffer>>(
|
|
912
|
+
// (conditions.length > 0) ? { $and: conditions } : {},
|
|
913
|
+
// (positiveProjectionExists)
|
|
914
|
+
// ? projection
|
|
915
|
+
// : {
|
|
916
|
+
// ...projection,
|
|
917
|
+
// __v: 0,
|
|
918
|
+
// createdAt: 0,
|
|
919
|
+
// updatedAt: 0,
|
|
920
|
+
// availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
|
|
921
|
+
// }
|
|
922
|
+
// );
|
|
923
|
+
// if (typeof params.limit === 'number' && params.limit > 0) {
|
|
924
|
+
// const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
925
|
+
// query.limit(params.limit)
|
|
926
|
+
// .skip(params.limit * (page - 1));
|
|
927
|
+
// }
|
|
928
|
+
// const sortByPrice = params.sort?.['priceSpecification.price'];
|
|
929
|
+
// const sortByIdentifier = params.sort?.identifier;
|
|
930
|
+
// if (typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number') {
|
|
931
|
+
// query.sort({
|
|
932
|
+
// ...(typeof sortByPrice === 'number')
|
|
933
|
+
// ? { 'priceSpecification.price': sortByPrice }
|
|
934
|
+
// : undefined,
|
|
935
|
+
// ...(typeof sortByIdentifier === 'number')
|
|
936
|
+
// ? { identifier: sortByIdentifier }
|
|
937
|
+
// : undefined
|
|
938
|
+
// });
|
|
939
|
+
// }
|
|
940
|
+
// return query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
941
|
+
// .exec()
|
|
942
|
+
// .then((docs) => docs.map((doc) => doc.toObject()));
|
|
445
943
|
});
|
|
446
944
|
}
|
|
945
|
+
// tslint:disable-next-line:max-func-body-length
|
|
447
946
|
save(params) {
|
|
448
947
|
return __awaiter(this, void 0, void 0, function* () {
|
|
449
948
|
let doc;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
949
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
950
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
951
|
+
const { $unset } = params, paramsWithoutUnset = __rest(params, ["$unset"]);
|
|
952
|
+
let savedUnitPriceOffer;
|
|
953
|
+
if (params.id === '') {
|
|
954
|
+
const id = uniqid();
|
|
955
|
+
savedUnitPriceOffer = Object.assign(Object.assign({}, paramsWithoutUnset), { id });
|
|
956
|
+
const aggregateOffer = {
|
|
957
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
958
|
+
project: params.project,
|
|
959
|
+
offers: [savedUnitPriceOffer]
|
|
960
|
+
};
|
|
961
|
+
doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id: id }));
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
const unitPriceOffers = yield this.searchFromAggregateOffer({
|
|
965
|
+
limit: 1,
|
|
966
|
+
page: 1,
|
|
967
|
+
project: { id: { $eq: params.project.id } },
|
|
968
|
+
id: { $eq: params.id }
|
|
969
|
+
}, { id: 1, identifier: 1, project: 1, typeOf: 1 });
|
|
970
|
+
const originalUnitPriceOffer = unitPriceOffers.shift();
|
|
971
|
+
if (originalUnitPriceOffer === undefined) {
|
|
972
|
+
throw new factory.errors.NotFound(factory.offerType.Offer);
|
|
973
|
+
}
|
|
974
|
+
// 上書き禁止属性を除外
|
|
975
|
+
const { id, identifier, project, typeOf } = paramsWithoutUnset, updateFields = __rest(paramsWithoutUnset, ["id", "identifier", "project", "typeOf"]);
|
|
976
|
+
savedUnitPriceOffer = Object.assign(Object.assign({}, updateFields), { id: originalUnitPriceOffer.id, identifier: originalUnitPriceOffer.identifier, project: originalUnitPriceOffer.project, typeOf: originalUnitPriceOffer.typeOf });
|
|
977
|
+
doc = yield this.aggregateOfferModel.findOneAndUpdate({ 'offers.id': params.id }, {
|
|
978
|
+
$set: {
|
|
979
|
+
'offers.$[offer]': savedUnitPriceOffer
|
|
980
|
+
}
|
|
981
|
+
}, {
|
|
982
|
+
upsert: false,
|
|
983
|
+
new: true,
|
|
984
|
+
arrayFilters: [
|
|
985
|
+
{ 'offer.id': { $eq: params.id } }
|
|
986
|
+
]
|
|
987
|
+
})
|
|
988
|
+
.exec();
|
|
989
|
+
}
|
|
990
|
+
if (doc === null) {
|
|
991
|
+
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
992
|
+
}
|
|
993
|
+
// 同期タスク作成(2023-09-05~)
|
|
994
|
+
if (typeof savedUnitPriceOffer.id === 'string') {
|
|
995
|
+
yield this.saveSyncTask({
|
|
996
|
+
project: { id: savedUnitPriceOffer.project.id },
|
|
997
|
+
id: { $in: [savedUnitPriceOffer.id] },
|
|
998
|
+
identifier: { $in: [] },
|
|
999
|
+
isDeleted: false,
|
|
1000
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
1001
|
+
options: { emitImmediately: true }
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
return savedUnitPriceOffer;
|
|
453
1005
|
}
|
|
454
1006
|
else {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
1007
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
1008
|
+
// if (params.id === '') {
|
|
1009
|
+
// const id = uniqid();
|
|
1010
|
+
// doc = await this.offerModel.create({
|
|
1011
|
+
// ...params,
|
|
1012
|
+
// _id: id
|
|
1013
|
+
// });
|
|
1014
|
+
// } else {
|
|
1015
|
+
// // 上書き禁止属性を除外(2022-08-24~)
|
|
1016
|
+
// const { id, identifier, project, typeOf, ...updateFields } = params;
|
|
1017
|
+
// doc = await this.offerModel.findOneAndUpdate(
|
|
1018
|
+
// { _id: params.id },
|
|
1019
|
+
// updateFields,
|
|
1020
|
+
// { upsert: false, new: true }
|
|
1021
|
+
// )
|
|
1022
|
+
// .exec();
|
|
1023
|
+
// }
|
|
1024
|
+
// if (doc === null) {
|
|
1025
|
+
// throw new factory.errors.NotFound(factory.offerType.Offer);
|
|
1026
|
+
// }
|
|
1027
|
+
// // 同期タスク作成(2023-09-03~)
|
|
1028
|
+
// if (typeof doc._id === 'string') {
|
|
1029
|
+
// await this.saveSyncTask({
|
|
1030
|
+
// project: { id: params.project.id },
|
|
1031
|
+
// id: { $in: [doc._id] },
|
|
1032
|
+
// identifier: { $in: [] },
|
|
1033
|
+
// isDeleted: false,
|
|
1034
|
+
// typeOf: factory.offerType.Offer,
|
|
1035
|
+
// options: { emitImmediately: true }
|
|
1036
|
+
// });
|
|
1037
|
+
// }
|
|
1038
|
+
// return doc.toObject();
|
|
459
1039
|
}
|
|
460
|
-
if (doc === null) {
|
|
461
|
-
throw new factory.errors.NotFound(this.offerModel.modelName);
|
|
462
|
-
}
|
|
463
|
-
return doc.toObject();
|
|
464
1040
|
});
|
|
465
1041
|
}
|
|
1042
|
+
/**
|
|
1043
|
+
* sskts専用オファー保管
|
|
1044
|
+
*/
|
|
1045
|
+
// tslint:disable-next-line:max-func-body-length
|
|
466
1046
|
saveManyByIdentifier(params) {
|
|
467
1047
|
return __awaiter(this, void 0, void 0, function* () {
|
|
468
|
-
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
1048
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-06~)
|
|
1049
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
1050
|
+
const insertBulkWriteOps = [];
|
|
1051
|
+
const updateBulkWriteOps = [];
|
|
1052
|
+
if (Array.isArray(params)) {
|
|
1053
|
+
params.forEach((p) => {
|
|
1054
|
+
const newOfferId = uniqid();
|
|
1055
|
+
const unitPriceOffer = Object.assign(Object.assign({}, p.attributes), { id: newOfferId });
|
|
1056
|
+
const aggregateOffer = {
|
|
1057
|
+
project: p.attributes.project,
|
|
1058
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
1059
|
+
offers: [unitPriceOffer]
|
|
1060
|
+
};
|
|
1061
|
+
insertBulkWriteOps.push({
|
|
1062
|
+
updateOne: {
|
|
1063
|
+
filter: {
|
|
1064
|
+
'project.id': { $eq: p.attributes.project.id },
|
|
1065
|
+
'offers.identifier': { $exists: true, $eq: p.attributes.identifier }
|
|
481
1066
|
},
|
|
482
|
-
|
|
483
|
-
$
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
1067
|
+
update: {
|
|
1068
|
+
$setOnInsert: Object.assign(Object.assign({}, aggregateOffer), { _id: newOfferId })
|
|
1069
|
+
},
|
|
1070
|
+
upsert: true
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
const { id } = unitPriceOffer, $set = __rest(unitPriceOffer, ["id"]);
|
|
1074
|
+
updateBulkWriteOps.push({
|
|
1075
|
+
updateOne: {
|
|
1076
|
+
filter: {
|
|
1077
|
+
'project.id': { $eq: unitPriceOffer.project.id },
|
|
1078
|
+
'offers.identifier': { $exists: true, $eq: unitPriceOffer.identifier }
|
|
1079
|
+
},
|
|
1080
|
+
update: {
|
|
1081
|
+
// 特定の属性のみ更新する(IDを上書きできないので)
|
|
1082
|
+
$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))
|
|
1083
|
+
? { 'offers.0.eligibleMembershipType': $set.eligibleMembershipType }
|
|
1084
|
+
: undefined), (Array.isArray($set.eligibleMonetaryAmount))
|
|
1085
|
+
? { 'offers.0.eligibleMonetaryAmount': $set.eligibleMonetaryAmount }
|
|
1086
|
+
: undefined)
|
|
1087
|
+
},
|
|
1088
|
+
upsert: false
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
493
1091
|
});
|
|
494
|
-
}
|
|
1092
|
+
}
|
|
1093
|
+
if (insertBulkWriteOps.length > 0) {
|
|
1094
|
+
yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
|
|
1095
|
+
yield this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
|
|
1096
|
+
// 同期タスク作成(2023-09-03~)
|
|
1097
|
+
yield this.saveSyncTask({
|
|
1098
|
+
project: { id: params[0].attributes.project.id },
|
|
1099
|
+
id: { $in: [] },
|
|
1100
|
+
identifier: { $in: params.map((savingOffer) => savingOffer.attributes.identifier) },
|
|
1101
|
+
isDeleted: false,
|
|
1102
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
1103
|
+
options: { emitImmediately: true }
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
495
1106
|
}
|
|
496
|
-
|
|
497
|
-
|
|
1107
|
+
else {
|
|
1108
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
1109
|
+
// const bulkWriteOps: AnyBulkWriteOperation[] = [];
|
|
1110
|
+
// if (Array.isArray(params)) {
|
|
1111
|
+
// params.forEach((p) => {
|
|
1112
|
+
// const id = uniqid();
|
|
1113
|
+
// const $set = { ...p.attributes };
|
|
1114
|
+
// if (typeof $set.id === 'string') {
|
|
1115
|
+
// delete $set.id;
|
|
1116
|
+
// }
|
|
1117
|
+
// bulkWriteOps.push({
|
|
1118
|
+
// updateOne: {
|
|
1119
|
+
// filter: {
|
|
1120
|
+
// 'project.id': {
|
|
1121
|
+
// $eq: p.attributes.project.id
|
|
1122
|
+
// },
|
|
1123
|
+
// identifier: {
|
|
1124
|
+
// $exists: true,
|
|
1125
|
+
// $eq: p.attributes.identifier
|
|
1126
|
+
// }
|
|
1127
|
+
// },
|
|
1128
|
+
// update: {
|
|
1129
|
+
// $set: $set,
|
|
1130
|
+
// $setOnInsert: {
|
|
1131
|
+
// _id: id
|
|
1132
|
+
// }
|
|
1133
|
+
// },
|
|
1134
|
+
// upsert: (p.upsert !== undefined) ? p.upsert : false
|
|
1135
|
+
// }
|
|
1136
|
+
// });
|
|
1137
|
+
// });
|
|
1138
|
+
// }
|
|
1139
|
+
// if (bulkWriteOps.length > 0) {
|
|
1140
|
+
// await this.offerModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
1141
|
+
// // 同期タスク作成(2023-09-03~)
|
|
1142
|
+
// await this.saveSyncTask({
|
|
1143
|
+
// project: { id: params[0].attributes.project.id },
|
|
1144
|
+
// id: { $in: [] },
|
|
1145
|
+
// identifier: { $in: params.map((savingOffer) => savingOffer.attributes.identifier) },
|
|
1146
|
+
// isDeleted: false,
|
|
1147
|
+
// typeOf: factory.offerType.Offer,
|
|
1148
|
+
// options: { emitImmediately: true }
|
|
1149
|
+
// });
|
|
1150
|
+
// }
|
|
498
1151
|
}
|
|
499
1152
|
});
|
|
500
1153
|
}
|
|
@@ -506,42 +1159,379 @@ class MongoRepository {
|
|
|
506
1159
|
if (params.addOn.itemOffered.id.$in.length === 0) {
|
|
507
1160
|
return;
|
|
508
1161
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
1162
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1163
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
1164
|
+
const conditions = {
|
|
1165
|
+
'project.id': { $eq: params.project.id },
|
|
1166
|
+
'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
|
|
1167
|
+
};
|
|
1168
|
+
const updatingOffers = yield this.searchFromAggregateOffer({
|
|
1169
|
+
project: { id: { $eq: params.project.id } },
|
|
1170
|
+
addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
|
|
1171
|
+
}, { id: 1 });
|
|
1172
|
+
const result = yield this.aggregateOfferModel.updateMany(conditions, {
|
|
1173
|
+
$pull: {
|
|
1174
|
+
'offers.$[offer].addOn': {
|
|
1175
|
+
'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
|
|
1176
|
+
}
|
|
516
1177
|
}
|
|
1178
|
+
}, {
|
|
1179
|
+
arrayFilters: [
|
|
1180
|
+
{ 'offer.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in } }
|
|
1181
|
+
]
|
|
1182
|
+
})
|
|
1183
|
+
.exec();
|
|
1184
|
+
// 同期タスク作成(2023-09-05~)
|
|
1185
|
+
if (updatingOffers.length > 0) {
|
|
1186
|
+
yield this.saveSyncTask({
|
|
1187
|
+
project: { id: params.project.id },
|
|
1188
|
+
id: { $in: updatingOffers.map((offer) => String(offer.id)) },
|
|
1189
|
+
identifier: { $in: [] },
|
|
1190
|
+
isDeleted: false,
|
|
1191
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
1192
|
+
options: { emitImmediately: true }
|
|
1193
|
+
});
|
|
517
1194
|
}
|
|
518
|
-
|
|
519
|
-
|
|
1195
|
+
return result;
|
|
1196
|
+
}
|
|
1197
|
+
else {
|
|
1198
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
1199
|
+
// const conditions: any = {
|
|
1200
|
+
// 'project.id': { $eq: params.project.id },
|
|
1201
|
+
// 'addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
|
|
1202
|
+
// };
|
|
1203
|
+
// const updatingOffers = await this.offerModel.find<Document<string>>(conditions, { _id: 1 })
|
|
1204
|
+
// .exec()
|
|
1205
|
+
// .then((docs) => docs.map((doc) => doc.toObject<{ id: string }>()));
|
|
1206
|
+
// const result = await this.offerModel.updateMany(
|
|
1207
|
+
// conditions,
|
|
1208
|
+
// {
|
|
1209
|
+
// $pull: {
|
|
1210
|
+
// addOn: {
|
|
1211
|
+
// 'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
|
|
1212
|
+
// }
|
|
1213
|
+
// }
|
|
1214
|
+
// }
|
|
1215
|
+
// )
|
|
1216
|
+
// .exec();
|
|
1217
|
+
// // 同期タスク作成(2023-09-03~)
|
|
1218
|
+
// if (updatingOffers.length > 0) {
|
|
1219
|
+
// await this.saveSyncTask({
|
|
1220
|
+
// project: { id: params.project.id },
|
|
1221
|
+
// id: { $in: updatingOffers.map((offer) => offer.id) },
|
|
1222
|
+
// identifier: { $in: [] },
|
|
1223
|
+
// isDeleted: false,
|
|
1224
|
+
// typeOf: factory.offerType.Offer,
|
|
1225
|
+
// options: { emitImmediately: true }
|
|
1226
|
+
// });
|
|
1227
|
+
// }
|
|
1228
|
+
// return result;
|
|
1229
|
+
}
|
|
520
1230
|
});
|
|
521
1231
|
}
|
|
522
1232
|
deleteById(params) {
|
|
523
1233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
-
|
|
525
|
-
|
|
1234
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1235
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
1236
|
+
yield this.aggregateOfferModel.findOneAndRemove({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
|
|
1237
|
+
.exec();
|
|
1238
|
+
// 同期タスク作成(2023-09-03~)
|
|
1239
|
+
yield this.saveSyncTask({
|
|
1240
|
+
project: { id: params.project.id },
|
|
1241
|
+
id: { $in: [params.id] },
|
|
1242
|
+
identifier: { $in: [] },
|
|
1243
|
+
isDeleted: true,
|
|
1244
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
1245
|
+
options: { emitImmediately: true }
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
else {
|
|
1249
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
1250
|
+
// await this.offerModel.findOneAndRemove(
|
|
1251
|
+
// { _id: { $eq: params.id } },
|
|
1252
|
+
// { projection: { _id: 1 } }
|
|
1253
|
+
// )
|
|
1254
|
+
// .exec();
|
|
1255
|
+
// // 同期タスク作成(2023-09-03~)
|
|
1256
|
+
// await this.saveSyncTask({
|
|
1257
|
+
// project: { id: params.project.id },
|
|
1258
|
+
// id: { $in: [params.id] },
|
|
1259
|
+
// identifier: { $in: [] },
|
|
1260
|
+
// isDeleted: true,
|
|
1261
|
+
// typeOf: factory.offerType.Offer,
|
|
1262
|
+
// options: { emitImmediately: true }
|
|
1263
|
+
// });
|
|
1264
|
+
}
|
|
526
1265
|
});
|
|
527
1266
|
}
|
|
528
|
-
deleteByProject(params
|
|
1267
|
+
// public async deleteByProject(params: {
|
|
1268
|
+
// project: { id: string };
|
|
1269
|
+
// }): Promise<void> {
|
|
1270
|
+
// await this.offerModel.deleteMany({
|
|
1271
|
+
// 'project.id': { $eq: params.project.id }
|
|
1272
|
+
// })
|
|
1273
|
+
// .exec();
|
|
1274
|
+
// }
|
|
1275
|
+
// public getCursor(conditions: any, projection: any) {
|
|
1276
|
+
// return this.offerModel.find(conditions, projection)
|
|
1277
|
+
// .sort({ 'priceSpecification.price': factory.sortType.Descending })
|
|
1278
|
+
// .cursor();
|
|
1279
|
+
// }
|
|
1280
|
+
// public async unsetUnnecessaryFields(params: {
|
|
1281
|
+
// filter: any;
|
|
1282
|
+
// $unset: any;
|
|
1283
|
+
// }) {
|
|
1284
|
+
// return this.offerModel.updateMany(
|
|
1285
|
+
// params.filter,
|
|
1286
|
+
// { $unset: params.$unset }
|
|
1287
|
+
// )
|
|
1288
|
+
// .exec();
|
|
1289
|
+
// }
|
|
1290
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length prefer-function-over-method
|
|
1291
|
+
sync2aggregateOffer(params) {
|
|
529
1292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
.
|
|
1293
|
+
if (params.typeOf === factory.offerType.Offer) {
|
|
1294
|
+
throw new factory.errors.NotImplemented('useOffersAsPrimary prohibited');
|
|
1295
|
+
// const idIn = params.id?.$in;
|
|
1296
|
+
// const identifierIn = params.identifier?.$in;
|
|
1297
|
+
// if (params.isDeleted === true) {
|
|
1298
|
+
// if (Array.isArray(idIn) && idIn.length > 0) {
|
|
1299
|
+
// await this.aggregateOfferModel.deleteMany({
|
|
1300
|
+
// 'project.id': { $eq: params.project.id },
|
|
1301
|
+
// _id: { $in: idIn }
|
|
1302
|
+
// })
|
|
1303
|
+
// .exec();
|
|
1304
|
+
// }
|
|
1305
|
+
// // コードで削除することは現状ない
|
|
1306
|
+
// } else {
|
|
1307
|
+
// let unitPriceOffers: (factory.unitPriceOffer.IUnitPriceOffer & { _id: string })[] = [];
|
|
1308
|
+
// if (Array.isArray(idIn) && idIn.length > 0) {
|
|
1309
|
+
// unitPriceOffers = await this.offerModel.find<Document<string, factory.unitPriceOffer.IUnitPriceOffer>>(
|
|
1310
|
+
// {
|
|
1311
|
+
// 'project.id': { $eq: params.project.id },
|
|
1312
|
+
// _id: { $in: idIn }
|
|
1313
|
+
// },
|
|
1314
|
+
// {
|
|
1315
|
+
// __v: 0,
|
|
1316
|
+
// createdAt: 0,
|
|
1317
|
+
// updatedAt: 0,
|
|
1318
|
+
// offers: 0,
|
|
1319
|
+
// availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
|
|
1320
|
+
// }
|
|
1321
|
+
// )
|
|
1322
|
+
// .exec()
|
|
1323
|
+
// .then((docs) => docs.map((doc) => doc.toObject()));
|
|
1324
|
+
// }
|
|
1325
|
+
// if (Array.isArray(identifierIn) && identifierIn.length > 0) {
|
|
1326
|
+
// unitPriceOffers = await this.offerModel.find<Document<string, factory.unitPriceOffer.IUnitPriceOffer>>(
|
|
1327
|
+
// {
|
|
1328
|
+
// 'project.id': { $eq: params.project.id },
|
|
1329
|
+
// identifier: { $exists: true, $in: identifierIn }
|
|
1330
|
+
// },
|
|
1331
|
+
// {
|
|
1332
|
+
// __v: 0,
|
|
1333
|
+
// createdAt: 0,
|
|
1334
|
+
// updatedAt: 0,
|
|
1335
|
+
// offers: 0,
|
|
1336
|
+
// availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
|
|
1337
|
+
// }
|
|
1338
|
+
// )
|
|
1339
|
+
// .exec()
|
|
1340
|
+
// .then((docs) => docs.map((doc) => doc.toObject()));
|
|
1341
|
+
// }
|
|
1342
|
+
// const bulkWriteOps: AnyBulkWriteOperation<factory.aggregateOffer.IAggregateOffer & { _id: string }>[] = [];
|
|
1343
|
+
// if (unitPriceOffers.length > 0) {
|
|
1344
|
+
// unitPriceOffers.forEach((unitPriceOffer) => {
|
|
1345
|
+
// const { _id, ...settingUnitPriceOffer } = unitPriceOffer;
|
|
1346
|
+
// const $set: factory.aggregateOffer.IAggregateOffer = {
|
|
1347
|
+
// project: unitPriceOffer.project,
|
|
1348
|
+
// typeOf: factory.offerType.AggregateOffer,
|
|
1349
|
+
// offers: [settingUnitPriceOffer]
|
|
1350
|
+
// };
|
|
1351
|
+
// bulkWriteOps.push({
|
|
1352
|
+
// updateOne: {
|
|
1353
|
+
// filter: {
|
|
1354
|
+
// 'project.id': { $eq: unitPriceOffer.project.id },
|
|
1355
|
+
// _id: { $eq: unitPriceOffer.id }
|
|
1356
|
+
// },
|
|
1357
|
+
// update: {
|
|
1358
|
+
// $set,
|
|
1359
|
+
// $setOnInsert: { _id: unitPriceOffer.id }
|
|
1360
|
+
// },
|
|
1361
|
+
// upsert: true
|
|
1362
|
+
// }
|
|
1363
|
+
// });
|
|
1364
|
+
// });
|
|
1365
|
+
// }
|
|
1366
|
+
// if (bulkWriteOps.length > 0) {
|
|
1367
|
+
// return this.aggregateOfferModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
1368
|
+
// }
|
|
1369
|
+
// }
|
|
1370
|
+
}
|
|
1371
|
+
else if (params.typeOf === factory.offerType.AggregateOffer) {
|
|
1372
|
+
// no op
|
|
1373
|
+
return;
|
|
1374
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1375
|
+
// const idIn = params.id?.$in;
|
|
1376
|
+
// const identifierIn = params.identifier?.$in;
|
|
1377
|
+
// if (params.isDeleted === true) {
|
|
1378
|
+
// if (Array.isArray(idIn) && idIn.length > 0) {
|
|
1379
|
+
// await this.offerModel.deleteMany({
|
|
1380
|
+
// 'project.id': { $eq: params.project.id },
|
|
1381
|
+
// _id: { $in: idIn }
|
|
1382
|
+
// })
|
|
1383
|
+
// .exec();
|
|
1384
|
+
// }
|
|
1385
|
+
// } else {
|
|
1386
|
+
// let aggregateOffers: { offer: factory.unitPriceOffer.IUnitPriceOffer }[] = [];
|
|
1387
|
+
// if (Array.isArray(idIn) && idIn.length > 0) {
|
|
1388
|
+
// aggregateOffers = await this.aggregateOfferModel.aggregate<{ offer: factory.unitPriceOffer.IUnitPriceOffer }>([
|
|
1389
|
+
// {
|
|
1390
|
+
// $unwind: {
|
|
1391
|
+
// path: '$offers'
|
|
1392
|
+
// }
|
|
1393
|
+
// },
|
|
1394
|
+
// {
|
|
1395
|
+
// $match: {
|
|
1396
|
+
// 'project.id': { $eq: params.project.id },
|
|
1397
|
+
// 'offers.id': { $in: idIn }
|
|
1398
|
+
// }
|
|
1399
|
+
// },
|
|
1400
|
+
// {
|
|
1401
|
+
// $project: {
|
|
1402
|
+
// _id: 0,
|
|
1403
|
+
// offer: '$offers'
|
|
1404
|
+
// }
|
|
1405
|
+
// }
|
|
1406
|
+
// ])
|
|
1407
|
+
// .exec();
|
|
1408
|
+
// }
|
|
1409
|
+
// if (Array.isArray(identifierIn) && identifierIn.length > 0) {
|
|
1410
|
+
// aggregateOffers = await this.aggregateOfferModel.aggregate<{ offer: factory.unitPriceOffer.IUnitPriceOffer }>([
|
|
1411
|
+
// {
|
|
1412
|
+
// $unwind: {
|
|
1413
|
+
// path: '$offers'
|
|
1414
|
+
// }
|
|
1415
|
+
// },
|
|
1416
|
+
// {
|
|
1417
|
+
// $match: {
|
|
1418
|
+
// 'project.id': { $eq: params.project.id },
|
|
1419
|
+
// 'offers.identifier': { $exists: true, $in: identifierIn }
|
|
1420
|
+
// }
|
|
1421
|
+
// },
|
|
1422
|
+
// {
|
|
1423
|
+
// $project: {
|
|
1424
|
+
// _id: 0,
|
|
1425
|
+
// offer: '$offers'
|
|
1426
|
+
// }
|
|
1427
|
+
// }
|
|
1428
|
+
// ])
|
|
1429
|
+
// .exec();
|
|
1430
|
+
// }
|
|
1431
|
+
// const bulkWriteOps: AnyBulkWriteOperation<factory.unitPriceOffer.IUnitPriceOffer & { _id: string }>[] = [];
|
|
1432
|
+
// if (aggregateOffers.length > 0) {
|
|
1433
|
+
// aggregateOffers.forEach((aggregateOffer) => {
|
|
1434
|
+
// const savingUnitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer & { _id: string } = {
|
|
1435
|
+
// ...aggregateOffer.offer,
|
|
1436
|
+
// _id: String(aggregateOffer.offer.id)
|
|
1437
|
+
// };
|
|
1438
|
+
// const { id, ...replacement } = savingUnitPriceOffer;
|
|
1439
|
+
// bulkWriteOps.push({
|
|
1440
|
+
// replaceOne: {
|
|
1441
|
+
// filter: {
|
|
1442
|
+
// 'project.id': { $eq: savingUnitPriceOffer.project.id },
|
|
1443
|
+
// _id: { $eq: savingUnitPriceOffer.id }
|
|
1444
|
+
// },
|
|
1445
|
+
// replacement,
|
|
1446
|
+
// upsert: true
|
|
1447
|
+
// }
|
|
1448
|
+
// });
|
|
1449
|
+
// });
|
|
1450
|
+
// }
|
|
1451
|
+
// if (bulkWriteOps.length > 0) {
|
|
1452
|
+
// return this.offerModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
1453
|
+
// }
|
|
1454
|
+
// }
|
|
1455
|
+
}
|
|
534
1456
|
});
|
|
535
1457
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
1458
|
+
/**
|
|
1459
|
+
* オファー同期専用のタスク保管
|
|
1460
|
+
*/
|
|
1461
|
+
saveSyncTask(params) {
|
|
1462
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1463
|
+
const syncAggregateOfferTask = {
|
|
1464
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
1465
|
+
name: factory.taskName.SyncAggregateOffer,
|
|
1466
|
+
status: factory.taskStatus.Ready,
|
|
1467
|
+
runsAt: new Date(),
|
|
1468
|
+
remainingNumberOfTries: 3,
|
|
1469
|
+
numberOfTried: 0,
|
|
1470
|
+
executionResults: [],
|
|
1471
|
+
data: {
|
|
1472
|
+
project: { id: params.project.id },
|
|
1473
|
+
id: params.id,
|
|
1474
|
+
identifier: params.identifier,
|
|
1475
|
+
isDeleted: params.isDeleted,
|
|
1476
|
+
typeOf: params.typeOf
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
const taskAttributes = [syncAggregateOfferTask];
|
|
1480
|
+
const result = yield this.taskModel.insertMany(taskAttributes, { ordered: false, rawResult: true });
|
|
1481
|
+
if (result.insertedCount !== taskAttributes.length) {
|
|
1482
|
+
throw new factory.errors.ServiceUnavailable('all tasks not saved');
|
|
1483
|
+
}
|
|
1484
|
+
const savedTasks = Object.values(result.insertedIds)
|
|
1485
|
+
.map((objectId) => {
|
|
1486
|
+
return { id: objectId.toHexString() };
|
|
1487
|
+
});
|
|
1488
|
+
if (params.options.emitImmediately === true) {
|
|
1489
|
+
savedTasks.forEach((savedTask) => {
|
|
1490
|
+
task_2.taskEventEmitter.emitTaskStatusChanged({
|
|
1491
|
+
id: savedTask.id,
|
|
1492
|
+
status: factory.taskStatus.Ready
|
|
1493
|
+
});
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
return savedTasks;
|
|
1497
|
+
});
|
|
540
1498
|
}
|
|
541
|
-
|
|
1499
|
+
searchFromAggregateOffer(params, projection) {
|
|
1500
|
+
var _a, _b;
|
|
542
1501
|
return __awaiter(this, void 0, void 0, function* () {
|
|
543
|
-
|
|
544
|
-
|
|
1502
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
1503
|
+
const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
|
|
1504
|
+
const sortByPrice = (_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price'];
|
|
1505
|
+
const sortByIdentifier = (_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier;
|
|
1506
|
+
const aggregate = this.aggregateOfferModel.aggregate([
|
|
1507
|
+
{
|
|
1508
|
+
$unwind: {
|
|
1509
|
+
path: '$offers',
|
|
1510
|
+
includeArrayIndex: OFFERS_ARRAY_INDEX_NAME
|
|
1511
|
+
}
|
|
1512
|
+
},
|
|
1513
|
+
...matchStages,
|
|
1514
|
+
...(typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number')
|
|
1515
|
+
? [
|
|
1516
|
+
{
|
|
1517
|
+
$sort: Object.assign(Object.assign({}, (typeof sortByPrice === 'number')
|
|
1518
|
+
? { 'offers.priceSpecification.price': sortByPrice }
|
|
1519
|
+
: undefined), (typeof sortByIdentifier === 'number')
|
|
1520
|
+
? { 'offers.identifier': sortByIdentifier }
|
|
1521
|
+
: undefined)
|
|
1522
|
+
}
|
|
1523
|
+
]
|
|
1524
|
+
: [],
|
|
1525
|
+
{ $project: projectStage }
|
|
1526
|
+
]);
|
|
1527
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
1528
|
+
/* istanbul ignore else */
|
|
1529
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
1530
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
1531
|
+
aggregate.limit(params.limit * page)
|
|
1532
|
+
.skip(params.limit * (page - 1));
|
|
1533
|
+
}
|
|
1534
|
+
return aggregate.exec();
|
|
545
1535
|
});
|
|
546
1536
|
}
|
|
547
1537
|
}
|