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