@chevre/domain 21.8.0-alpha.3 → 21.8.0-alpha.31

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.
Files changed (86) hide show
  1. package/example/src/chevre/db/stats.ts +22 -0
  2. package/example/src/chevre/importOffersFromCOA.ts +7 -1
  3. package/example/src/chevre/migrateAggregateOffers.ts +75 -0
  4. package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
  5. package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
  6. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -0
  7. package/example/src/chevre/processPay.ts +3 -4
  8. package/example/src/chevre/publishPermitOwnershipInfoToken.ts +56 -0
  9. package/example/src/chevre/searchOffersByCatalog.ts +1 -2
  10. package/example/src/chevre/searchOffersFromAggregateOffer.ts +152 -0
  11. package/example/src/chevre/searchTasks.ts +9 -9
  12. package/example/src/chevre/syncAggregateOffer.ts +25 -0
  13. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  14. package/lib/chevre/repo/assetTransaction.js +54 -2
  15. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +71 -0
  16. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +54 -0
  17. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  18. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  19. package/lib/chevre/repo/mongoose/schemas/order.js +1 -0
  20. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  21. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  22. package/lib/chevre/repo/offer.d.ts +50 -9
  23. package/lib/chevre/repo/offer.js +669 -21
  24. package/lib/chevre/repo/order.d.ts +15 -0
  25. package/lib/chevre/repo/order.js +34 -1
  26. package/lib/chevre/repo/task.d.ts +7 -1
  27. package/lib/chevre/repo/task.js +111 -22
  28. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -2
  29. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -2
  30. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  31. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  32. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  33. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  34. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  35. package/lib/chevre/service/assetTransaction/reserve.js +105 -31
  36. package/lib/chevre/service/delivery.js +17 -0
  37. package/lib/chevre/service/offer/event/authorize.js +3 -0
  38. package/lib/chevre/service/offer/event/factory.js +8 -8
  39. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  40. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +2 -2
  41. package/lib/chevre/service/offer/event/voidTransaction.js +7 -2
  42. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
  43. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  44. package/lib/chevre/service/order/confirmPayTransaction.js +29 -40
  45. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  46. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  47. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  48. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  49. package/lib/chevre/service/order/onOrderStatusChanged.js +104 -81
  50. package/lib/chevre/service/order/payOrder.d.ts +2 -10
  51. package/lib/chevre/service/order/payOrder.js +4 -45
  52. package/lib/chevre/service/order/placeOrder.js +11 -13
  53. package/lib/chevre/service/order.d.ts +3 -1
  54. package/lib/chevre/service/order.js +6 -2
  55. package/lib/chevre/service/payment/any/factory.js +33 -8
  56. package/lib/chevre/service/payment/any.js +30 -21
  57. package/lib/chevre/service/payment/creditCard.js +12 -12
  58. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  59. package/lib/chevre/service/payment/movieTicket.js +10 -11
  60. package/lib/chevre/service/payment/paymentCard.js +9 -12
  61. package/lib/chevre/service/project.js +1 -1
  62. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  63. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +1 -4
  64. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +1 -5
  65. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  66. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +1 -4
  67. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  68. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  69. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  70. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  71. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +6 -0
  72. package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
  73. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  74. package/lib/chevre/service/task/syncAggregateOffer.d.ts +7 -0
  75. package/lib/chevre/service/task/syncAggregateOffer.js +23 -0
  76. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
  77. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
  78. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
  79. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  80. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  81. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  82. package/lib/chevre/settings.d.ts +2 -2
  83. package/lib/chevre/settings.js +3 -5
  84. package/package.json +3 -3
  85. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  86. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
@@ -23,16 +23,21 @@ 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");
29
32
  /**
30
33
  * オファーリポジトリ
31
34
  */
32
35
  class MongoRepository {
33
36
  constructor(connection) {
37
+ this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
34
38
  this.offerModel = connection.model(offer_1.modelName, offer_1.schema);
35
39
  this.offerCatalogModel = connection.model(offerCatalog_1.modelName, offerCatalog_1.schema);
40
+ this.taskModel = connection.model(task_1.modelName, task_1.schema);
36
41
  }
37
42
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
38
43
  static CREATE_OFFER_MONGO_CONDITIONS(params) {
@@ -340,6 +345,373 @@ class MongoRepository {
340
345
  }
341
346
  return andConditions;
342
347
  }
348
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
349
+ static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
350
+ 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;
351
+ const matchStages = [];
352
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
353
+ if (typeof projectIdEq === 'string') {
354
+ matchStages.push({
355
+ $match: {
356
+ 'project.id': { $eq: projectIdEq }
357
+ }
358
+ });
359
+ }
360
+ const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
361
+ if (typeof idEq === 'string') {
362
+ matchStages.push({
363
+ $match: {
364
+ 'offers.id': { $eq: idEq }
365
+ }
366
+ });
367
+ }
368
+ const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
369
+ if (Array.isArray(idIn)) {
370
+ matchStages.push({
371
+ $match: {
372
+ 'offers.id': {
373
+ $in: idIn
374
+ }
375
+ }
376
+ });
377
+ }
378
+ const identifierEq = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
379
+ if (typeof identifierEq === 'string') {
380
+ matchStages.push({
381
+ $match: {
382
+ 'offers.identifier': {
383
+ $exists: true,
384
+ $eq: identifierEq
385
+ }
386
+ }
387
+ });
388
+ }
389
+ const identifierIn = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$in;
390
+ if (Array.isArray(identifierIn)) {
391
+ matchStages.push({
392
+ $match: {
393
+ 'offers.identifier': {
394
+ $exists: true,
395
+ $in: identifierIn
396
+ }
397
+ }
398
+ });
399
+ }
400
+ const identifierRegex = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$regex;
401
+ if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
402
+ matchStages.push({
403
+ $match: {
404
+ 'offers.identifier': {
405
+ $exists: true,
406
+ $regex: new RegExp(identifierRegex)
407
+ }
408
+ }
409
+ });
410
+ }
411
+ const nameRegex = (_h = params.name) === null || _h === void 0 ? void 0 : _h.$regex;
412
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
413
+ const nameRegexExp = new RegExp(nameRegex);
414
+ matchStages.push({
415
+ $match: {
416
+ $or: [
417
+ {
418
+ 'offers.name.ja': {
419
+ $exists: true,
420
+ $regex: nameRegexExp
421
+ }
422
+ },
423
+ {
424
+ 'offers.name.en': {
425
+ $exists: true,
426
+ $regex: nameRegexExp
427
+ }
428
+ },
429
+ {
430
+ 'offers.alternateName.ja': {
431
+ $exists: true,
432
+ $regex: nameRegexExp
433
+ }
434
+ },
435
+ {
436
+ 'offers.alternateName.en': {
437
+ $exists: true,
438
+ $regex: nameRegexExp
439
+ }
440
+ }
441
+ ]
442
+ }
443
+ });
444
+ }
445
+ const itemOfferedTypeOfEq = (_k = (_j = params.itemOffered) === null || _j === void 0 ? void 0 : _j.typeOf) === null || _k === void 0 ? void 0 : _k.$eq;
446
+ if (typeof itemOfferedTypeOfEq === 'string') {
447
+ matchStages.push({
448
+ $match: {
449
+ 'offers.itemOffered.typeOf': {
450
+ $exists: true,
451
+ $eq: itemOfferedTypeOfEq
452
+ }
453
+ }
454
+ });
455
+ }
456
+ const categoryCodeValueIn = (_m = (_l = params.category) === null || _l === void 0 ? void 0 : _l.codeValue) === null || _m === void 0 ? void 0 : _m.$in;
457
+ if (Array.isArray(categoryCodeValueIn)) {
458
+ matchStages.push({
459
+ $match: {
460
+ 'offers.category.codeValue': {
461
+ $exists: true,
462
+ $in: categoryCodeValueIn
463
+ }
464
+ }
465
+ });
466
+ }
467
+ const eligibleMembershipTypeCodeValueEq = (_p = (_o = params.eligibleMembershipType) === null || _o === void 0 ? void 0 : _o.codeValue) === null || _p === void 0 ? void 0 : _p.$eq;
468
+ if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
469
+ matchStages.push({
470
+ $match: {
471
+ 'offers.eligibleMembershipType.codeValue': {
472
+ $exists: true,
473
+ $eq: eligibleMembershipTypeCodeValueEq
474
+ }
475
+ }
476
+ });
477
+ }
478
+ const eligibleMonetaryAmountCurrencyEq = (_r = (_q = params.eligibleMonetaryAmount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
479
+ if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
480
+ matchStages.push({
481
+ $match: {
482
+ 'offers.eligibleMonetaryAmount.currency': {
483
+ $exists: true,
484
+ $eq: eligibleMonetaryAmountCurrencyEq
485
+ }
486
+ }
487
+ });
488
+ }
489
+ const eligibleSeatingTypeCodeValueEq = (_t = (_s = params.eligibleSeatingType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
490
+ if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
491
+ matchStages.push({
492
+ $match: {
493
+ 'offers.eligibleSeatingType.codeValue': {
494
+ $exists: true,
495
+ $eq: eligibleSeatingTypeCodeValueEq
496
+ }
497
+ }
498
+ });
499
+ }
500
+ 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;
501
+ if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
502
+ matchStages.push({
503
+ $match: {
504
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
505
+ $exists: appliesToMovieTicketServiceTypeExist
506
+ }
507
+ }
508
+ });
509
+ }
510
+ 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;
511
+ if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
512
+ matchStages.push({
513
+ $match: {
514
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
515
+ $exists: true,
516
+ $eq: appliesToMovieTicketServiceTypeEq
517
+ }
518
+ }
519
+ });
520
+ }
521
+ 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;
522
+ if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
523
+ matchStages.push({
524
+ $match: {
525
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
526
+ $exists: true,
527
+ $eq: appliesToMovieTicketServiceOutputTypeOfEq
528
+ }
529
+ }
530
+ });
531
+ }
532
+ 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;
533
+ if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
534
+ matchStages.push({
535
+ $match: {
536
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
537
+ $nin: appliesToMovieTicketServiceOutputTypeOfNin
538
+ }
539
+ }
540
+ });
541
+ }
542
+ if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
543
+ const priceSpecificationPriceGte = (_8 = params.priceSpecification.price) === null || _8 === void 0 ? void 0 : _8.$gte;
544
+ if (typeof priceSpecificationPriceGte === 'number') {
545
+ matchStages.push({
546
+ $match: {
547
+ 'offers.priceSpecification.price': {
548
+ $exists: true,
549
+ $gte: priceSpecificationPriceGte
550
+ }
551
+ }
552
+ });
553
+ }
554
+ const priceSpecificationPriceLte = (_9 = params.priceSpecification.price) === null || _9 === void 0 ? void 0 : _9.$lte;
555
+ if (typeof priceSpecificationPriceLte === 'number') {
556
+ matchStages.push({
557
+ $match: {
558
+ 'offers.priceSpecification.price': {
559
+ $exists: true,
560
+ $lte: priceSpecificationPriceLte
561
+ }
562
+ }
563
+ });
564
+ }
565
+ const accountsReceivableGte = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.accountsReceivable) === null || _11 === void 0 ? void 0 : _11.$gte;
566
+ if (typeof accountsReceivableGte === 'number') {
567
+ matchStages.push({
568
+ $match: {
569
+ 'offers.priceSpecification.accounting.accountsReceivable': {
570
+ $exists: true,
571
+ $gte: accountsReceivableGte
572
+ }
573
+ }
574
+ });
575
+ }
576
+ const accountsReceivableLte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$lte;
577
+ if (typeof accountsReceivableLte === 'number') {
578
+ matchStages.push({
579
+ $match: {
580
+ 'offers.priceSpecification.accounting.accountsReceivable': {
581
+ $exists: true,
582
+ $lte: accountsReceivableLte
583
+ }
584
+ }
585
+ });
586
+ }
587
+ 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;
588
+ if (typeof accountingCodeValueEq === 'string') {
589
+ matchStages.push({
590
+ $match: {
591
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
592
+ $exists: true,
593
+ $eq: accountingCodeValueEq
594
+ }
595
+ }
596
+ });
597
+ }
598
+ 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;
599
+ if (Array.isArray(accountingCodeValueIn)) {
600
+ matchStages.push({
601
+ $match: {
602
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
603
+ $exists: true,
604
+ $in: accountingCodeValueIn
605
+ }
606
+ }
607
+ });
608
+ }
609
+ const referenceQuantityValueEq = (_21 = (_20 = params.priceSpecification.referenceQuantity) === null || _20 === void 0 ? void 0 : _20.value) === null || _21 === void 0 ? void 0 : _21.$eq;
610
+ if (typeof referenceQuantityValueEq === 'number') {
611
+ matchStages.push({
612
+ $match: {
613
+ 'offers.priceSpecification.referenceQuantity.value': {
614
+ $exists: true,
615
+ $eq: referenceQuantityValueEq
616
+ }
617
+ }
618
+ });
619
+ }
620
+ }
621
+ const availabilityEq = (_22 = params.availability) === null || _22 === void 0 ? void 0 : _22.$eq;
622
+ if (typeof availabilityEq === 'string') {
623
+ matchStages.push({
624
+ $match: {
625
+ 'offers.availability': { $eq: availabilityEq }
626
+ }
627
+ });
628
+ }
629
+ const availableAtOrFromIdEq = (_24 = (_23 = params.availableAtOrFrom) === null || _23 === void 0 ? void 0 : _23.id) === null || _24 === void 0 ? void 0 : _24.$eq;
630
+ if (typeof availableAtOrFromIdEq === 'string') {
631
+ matchStages.push({
632
+ $match: {
633
+ 'offers.availableAtOrFrom.id': {
634
+ $exists: true,
635
+ $eq: availableAtOrFromIdEq
636
+ }
637
+ }
638
+ });
639
+ }
640
+ const availableAtOrFromIdIn = (_26 = (_25 = params.availableAtOrFrom) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$in;
641
+ if (Array.isArray(availableAtOrFromIdIn)) {
642
+ matchStages.push({
643
+ $match: {
644
+ 'offers.availableAtOrFrom.id': {
645
+ $exists: true,
646
+ $in: availableAtOrFromIdIn
647
+ }
648
+ }
649
+ });
650
+ }
651
+ 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;
652
+ if (typeof addOnItemOfferedIdEq === 'string') {
653
+ matchStages.push({
654
+ $match: {
655
+ 'offers.addOn.itemOffered.id': {
656
+ $exists: true,
657
+ $eq: addOnItemOfferedIdEq
658
+ }
659
+ }
660
+ });
661
+ }
662
+ const hasMerchantReturnPolicyIdEq = (_31 = (_30 = params.hasMerchantReturnPolicy) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
663
+ if (typeof hasMerchantReturnPolicyIdEq === 'string') {
664
+ matchStages.push({
665
+ $match: {
666
+ 'offers.hasMerchantReturnPolicy.id': {
667
+ $exists: true,
668
+ $eq: hasMerchantReturnPolicyIdEq
669
+ }
670
+ }
671
+ });
672
+ }
673
+ const additionalPropertyAll = (_32 = params.additionalProperty) === null || _32 === void 0 ? void 0 : _32.$all;
674
+ if (Array.isArray(additionalPropertyAll)) {
675
+ matchStages.push({
676
+ $match: {
677
+ 'offers.additionalProperty': {
678
+ $exists: true,
679
+ $all: additionalPropertyAll
680
+ }
681
+ }
682
+ });
683
+ }
684
+ const additionalPropertyElemMatch = (_33 = params.additionalProperty) === null || _33 === void 0 ? void 0 : _33.$elemMatch;
685
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
686
+ matchStages.push({
687
+ $match: {
688
+ 'offers.additionalProperty': {
689
+ $exists: true,
690
+ $elemMatch: additionalPropertyElemMatch
691
+ }
692
+ }
693
+ });
694
+ }
695
+ if (params.onlyValid === true) {
696
+ const now = new Date();
697
+ matchStages.push({
698
+ $match: {
699
+ $or: [
700
+ { 'offers.validFrom': { $exists: false } },
701
+ { 'offers.validFrom': { $exists: true, $lte: now } }
702
+ ]
703
+ }
704
+ }, {
705
+ $match: {
706
+ $or: [
707
+ { 'offers.validThrough': { $exists: false } },
708
+ { 'offers.validThrough': { $exists: true, $gte: now } }
709
+ ]
710
+ }
711
+ });
712
+ }
713
+ return matchStages;
714
+ }
343
715
  /**
344
716
  * カタログに含まれるオファーを検索する
345
717
  * カタログに登録されたオファーの順序は保証される
@@ -388,10 +760,11 @@ class MongoRepository {
388
760
  ? { sort: { _id: factory.sortType.Ascending } }
389
761
  : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
390
762
  offers = yield this.search(searchOffersConditions, params.projection);
391
- if (params.sort) {
392
- // sorting
393
- offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
394
- }
763
+ // 完全廃止(基本的にsortedOfferIdsと合わせて利用する想定)(2023-09-04~)
764
+ // if (params.sort) {
765
+ // // sorting
766
+ // offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
767
+ // }
395
768
  }
396
769
  return { offers, sortedOfferIds };
397
770
  });
@@ -401,7 +774,8 @@ class MongoRepository {
401
774
  const doc = yield this.offerModel.findOne({ _id: params.id }, {
402
775
  __v: 0,
403
776
  createdAt: 0,
404
- updatedAt: 0
777
+ updatedAt: 0,
778
+ availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
405
779
  })
406
780
  .exec();
407
781
  if (doc === null) {
@@ -410,6 +784,23 @@ class MongoRepository {
410
784
  return doc.toObject();
411
785
  });
412
786
  }
787
+ findAggregateOfferById(params) {
788
+ return __awaiter(this, void 0, void 0, function* () {
789
+ const doc = yield this.aggregateOfferModel.findOne({
790
+ _id: { $eq: params.id },
791
+ 'project.id': { $eq: params.project.id }
792
+ }, {
793
+ __v: 0,
794
+ createdAt: 0,
795
+ updatedAt: 0
796
+ })
797
+ .exec();
798
+ if (doc === null) {
799
+ throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
800
+ }
801
+ return doc.toObject();
802
+ });
803
+ }
413
804
  count(params) {
414
805
  return __awaiter(this, void 0, void 0, function* () {
415
806
  const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
@@ -428,7 +819,8 @@ class MongoRepository {
428
819
  : false;
429
820
  const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, (positiveProjectionExists)
430
821
  ? projection
431
- : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
822
+ : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0, availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
823
+ }));
432
824
  if (typeof params.limit === 'number' && params.limit > 0) {
433
825
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
434
826
  query.limit(params.limit)
@@ -444,6 +836,80 @@ class MongoRepository {
444
836
  .then((docs) => docs.map((doc) => doc.toObject()));
445
837
  });
446
838
  }
839
+ // tslint:disable-next-line:max-func-body-length
840
+ searchFromAggregateOffer(params, __) {
841
+ var _a;
842
+ return __awaiter(this, void 0, void 0, function* () {
843
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
844
+ // tslint:disable-next-line:no-suspicious-comment
845
+ // TODO implement projection
846
+ // const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
847
+ // ? Object.values(projection)
848
+ // .some((value) => value !== 0)
849
+ // : false;
850
+ const aggregate = this.aggregateOfferModel.aggregate([
851
+ { $unwind: '$offers' },
852
+ ...matchStages,
853
+ ...(((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) !== undefined)
854
+ ? [{ $sort: { 'offers.priceSpecification.price': params.sort['priceSpecification.price'] } }]
855
+ : [],
856
+ {
857
+ $project: {
858
+ _id: 0,
859
+ typeOf: '$offers.typeOf',
860
+ project: '$project',
861
+ id: '$offers.id',
862
+ identifier: '$offers.identifier',
863
+ name: '$offers.name',
864
+ description: '$offers.description',
865
+ category: '$offers.category',
866
+ color: '$offers.color',
867
+ additionalProperty: '$offers.additionalProperty',
868
+ advanceBookingRequirement: '$offers.advanceBookingRequirement',
869
+ alternateName: '$offers.alternateName',
870
+ addOn: '$offers.addOn',
871
+ availability: '$offers.availability',
872
+ availableAtOrFrom: '$offers.availableAtOrFrom',
873
+ hasMerchantReturnPolicy: '$offers.hasMerchantReturnPolicy',
874
+ itemOffered: '$offers.itemOffered',
875
+ priceCurrency: '$offers.priceCurrency',
876
+ priceSpecification: '$offers.priceSpecification',
877
+ eligibleCustomerType: '$offers.eligibleCustomerType',
878
+ eligibleDuration: '$offers.eligibleDuration',
879
+ eligibleMembershipType: '$offers.eligibleMembershipType',
880
+ eligibleMonetaryAmount: '$offers.eligibleMonetaryAmount',
881
+ eligibleQuantity: '$offers.eligibleQuantity',
882
+ eligibleRegion: '$offers.eligibleRegion',
883
+ eligibleSeatingType: '$offers.eligibleSeatingType',
884
+ eligibleSubReservation: '$offers.eligibleSubReservation',
885
+ settings: '$offers.settings',
886
+ validFrom: '$offers.validFrom',
887
+ validThrough: '$offers.validThrough',
888
+ validRateLimit: '$offers.validRateLimit'
889
+ // ...(searchConditions.$projection?.seatCount === 1)
890
+ // ? {
891
+ // seatCount: {
892
+ // $cond: {
893
+ // if: { $isArray: '$containsPlace.containsPlace' },
894
+ // then: { $size: '$containsPlace.containsPlace' },
895
+ // else: 0
896
+ // }
897
+ // }
898
+ // }
899
+ // : undefined
900
+ }
901
+ }
902
+ ]);
903
+ // tslint:disable-next-line:no-single-line-block-comment
904
+ /* istanbul ignore else */
905
+ if (typeof params.limit === 'number' && params.limit > 0) {
906
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
907
+ aggregate.limit(params.limit * page)
908
+ .skip(params.limit * (page - 1));
909
+ }
910
+ return aggregate.exec();
911
+ });
912
+ }
447
913
  save(params) {
448
914
  return __awaiter(this, void 0, void 0, function* () {
449
915
  let doc;
@@ -460,9 +926,23 @@ class MongoRepository {
460
926
  if (doc === null) {
461
927
  throw new factory.errors.NotFound(this.offerModel.modelName);
462
928
  }
929
+ // 同期タスク作成(2023-09-03~)
930
+ if (typeof doc._id === 'string') {
931
+ yield this.saveSyncTask({
932
+ project: { id: params.project.id },
933
+ id: { $in: [doc._id] },
934
+ identifier: { $in: [] },
935
+ isDeleted: false,
936
+ typeOf: factory.offerType.Offer,
937
+ options: { emitImmediately: true }
938
+ });
939
+ }
463
940
  return doc.toObject();
464
941
  });
465
942
  }
943
+ /**
944
+ * sskts専用オファー保管
945
+ */
466
946
  saveManyByIdentifier(params) {
467
947
  return __awaiter(this, void 0, void 0, function* () {
468
948
  const bulkWriteOps = [];
@@ -486,7 +966,9 @@ class MongoRepository {
486
966
  },
487
967
  update: {
488
968
  $set: $set,
489
- $setOnInsert: { _id: id }
969
+ $setOnInsert: {
970
+ _id: id
971
+ }
490
972
  },
491
973
  upsert: (p.upsert !== undefined) ? p.upsert : false
492
974
  }
@@ -495,6 +977,15 @@ class MongoRepository {
495
977
  }
496
978
  if (bulkWriteOps.length > 0) {
497
979
  yield this.offerModel.bulkWrite(bulkWriteOps, { ordered: false });
980
+ // 同期タスク作成(2023-09-03~)
981
+ yield this.saveSyncTask({
982
+ project: { id: params[0].attributes.project.id },
983
+ id: { $in: [] },
984
+ identifier: { $in: params.map((savingOffer) => savingOffer.attributes.identifier) },
985
+ isDeleted: false,
986
+ typeOf: factory.offerType.Offer,
987
+ options: { emitImmediately: true }
988
+ });
498
989
  }
499
990
  });
500
991
  }
@@ -506,10 +997,14 @@ class MongoRepository {
506
997
  if (params.addOn.itemOffered.id.$in.length === 0) {
507
998
  return;
508
999
  }
509
- return this.offerModel.updateMany({
1000
+ const conditions = {
510
1001
  'project.id': { $eq: params.project.id },
511
1002
  'addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
512
- }, {
1003
+ };
1004
+ const updatingOffers = yield this.offerModel.find(conditions, { _id: 1 })
1005
+ .exec()
1006
+ .then((docs) => docs.map((doc) => doc.toObject()));
1007
+ const result = yield this.offerModel.updateMany(conditions, {
513
1008
  $pull: {
514
1009
  addOn: {
515
1010
  'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
@@ -517,31 +1012,184 @@ class MongoRepository {
517
1012
  }
518
1013
  })
519
1014
  .exec();
1015
+ // 同期タスク作成(2023-09-03~)
1016
+ if (updatingOffers.length > 0) {
1017
+ yield this.saveSyncTask({
1018
+ project: { id: params.project.id },
1019
+ id: { $in: updatingOffers.map((offer) => offer.id) },
1020
+ identifier: { $in: [] },
1021
+ isDeleted: false,
1022
+ typeOf: factory.offerType.Offer,
1023
+ options: { emitImmediately: true }
1024
+ });
1025
+ }
1026
+ return result;
520
1027
  });
521
1028
  }
522
1029
  deleteById(params) {
523
1030
  return __awaiter(this, void 0, void 0, function* () {
524
- yield this.offerModel.findOneAndRemove({ _id: params.id })
525
- .exec();
526
- });
527
- }
528
- deleteByProject(params) {
529
- return __awaiter(this, void 0, void 0, function* () {
530
- yield this.offerModel.deleteMany({
531
- 'project.id': { $eq: params.project.id }
532
- })
1031
+ yield this.offerModel.findOneAndRemove({ _id: params.id }, { projection: { _id: 1 } })
533
1032
  .exec();
1033
+ // 同期タスク作成(2023-09-03~)
1034
+ yield this.saveSyncTask({
1035
+ project: { id: params.project.id },
1036
+ id: { $in: [params.id] },
1037
+ identifier: { $in: [] },
1038
+ isDeleted: true,
1039
+ typeOf: factory.offerType.Offer,
1040
+ options: { emitImmediately: true }
1041
+ });
534
1042
  });
535
1043
  }
1044
+ // public async deleteByProject(params: {
1045
+ // project: { id: string };
1046
+ // }): Promise<void> {
1047
+ // await this.offerModel.deleteMany({
1048
+ // 'project.id': { $eq: params.project.id }
1049
+ // })
1050
+ // .exec();
1051
+ // }
536
1052
  getCursor(conditions, projection) {
537
1053
  return this.offerModel.find(conditions, projection)
538
1054
  .sort({ 'priceSpecification.price': factory.sortType.Descending })
539
1055
  .cursor();
540
1056
  }
541
- unsetUnnecessaryFields(params) {
1057
+ // public async unsetUnnecessaryFields(params: {
1058
+ // filter: any;
1059
+ // $unset: any;
1060
+ // }) {
1061
+ // return this.offerModel.updateMany(
1062
+ // params.filter,
1063
+ // { $unset: params.$unset }
1064
+ // )
1065
+ // .exec();
1066
+ // }
1067
+ sync2aggregateOffer(params) {
1068
+ var _a, _b;
542
1069
  return __awaiter(this, void 0, void 0, function* () {
543
- return this.offerModel.updateMany(params.filter, { $unset: params.$unset })
544
- .exec();
1070
+ if (params.typeOf === factory.offerType.Offer) {
1071
+ const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;
1072
+ const identifierIn = (_b = params.identifier) === null || _b === void 0 ? void 0 : _b.$in;
1073
+ if (params.isDeleted === true) {
1074
+ if (Array.isArray(idIn) && idIn.length > 0) {
1075
+ yield this.aggregateOfferModel.deleteMany({
1076
+ 'project.id': { $eq: params.project.id },
1077
+ _id: { $in: idIn }
1078
+ })
1079
+ .exec();
1080
+ }
1081
+ // コードで削除することは現状ない
1082
+ // if (Array.isArray(identifierIn) && identifierIn.length > 0) {
1083
+ // await this.aggregateOfferModel.deleteMany({
1084
+ // 'project.id': { $eq: params.project.id },
1085
+ // 'offers.identifier': { $exists: true, $in: identifierIn }
1086
+ // })
1087
+ // .exec();
1088
+ // }
1089
+ }
1090
+ else {
1091
+ let unitPriceOffers = [];
1092
+ if (Array.isArray(idIn) && idIn.length > 0) {
1093
+ unitPriceOffers = yield this.offerModel.find({
1094
+ 'project.id': { $eq: params.project.id },
1095
+ _id: { $in: idIn }
1096
+ }, {
1097
+ __v: 0,
1098
+ createdAt: 0,
1099
+ updatedAt: 0,
1100
+ offers: 0,
1101
+ availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
1102
+ })
1103
+ .exec()
1104
+ .then((docs) => docs.map((doc) => doc.toObject()));
1105
+ }
1106
+ if (Array.isArray(identifierIn) && identifierIn.length > 0) {
1107
+ unitPriceOffers = yield this.offerModel.find({
1108
+ 'project.id': { $eq: params.project.id },
1109
+ identifier: { $exists: true, $in: identifierIn }
1110
+ }, {
1111
+ __v: 0,
1112
+ createdAt: 0,
1113
+ updatedAt: 0,
1114
+ offers: 0,
1115
+ availableAddOn: 0 // 廃止属性の残存が確認されたので(2023-09-04~)
1116
+ })
1117
+ .exec()
1118
+ .then((docs) => docs.map((doc) => doc.toObject()));
1119
+ }
1120
+ const bulkWriteOps = [];
1121
+ if (unitPriceOffers.length > 0) {
1122
+ unitPriceOffers.forEach((unitPriceOffer) => {
1123
+ delete unitPriceOffer._id;
1124
+ const $set = {
1125
+ project: unitPriceOffer.project,
1126
+ typeOf: factory.offerType.AggregateOffer,
1127
+ offers: [unitPriceOffer]
1128
+ };
1129
+ bulkWriteOps.push({
1130
+ updateOne: {
1131
+ filter: {
1132
+ 'project.id': { $eq: unitPriceOffer.project.id },
1133
+ _id: { $eq: unitPriceOffer.id }
1134
+ },
1135
+ update: {
1136
+ $set,
1137
+ $setOnInsert: { _id: unitPriceOffer.id }
1138
+ },
1139
+ upsert: true
1140
+ }
1141
+ });
1142
+ });
1143
+ }
1144
+ if (bulkWriteOps.length > 0) {
1145
+ return this.aggregateOfferModel.bulkWrite(bulkWriteOps, { ordered: false });
1146
+ }
1147
+ }
1148
+ }
1149
+ else if (params.typeOf === factory.offerType.AggregateOffer) {
1150
+ // no op
1151
+ }
1152
+ });
1153
+ }
1154
+ /**
1155
+ * オファー同期専用のタスク保管
1156
+ */
1157
+ saveSyncTask(params) {
1158
+ return __awaiter(this, void 0, void 0, function* () {
1159
+ const syncAggregateOfferTask = {
1160
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
1161
+ name: factory.taskName.SyncAggregateOffer,
1162
+ status: factory.taskStatus.Ready,
1163
+ runsAt: new Date(),
1164
+ remainingNumberOfTries: 3,
1165
+ numberOfTried: 0,
1166
+ executionResults: [],
1167
+ data: {
1168
+ project: { id: params.project.id },
1169
+ id: params.id,
1170
+ identifier: params.identifier,
1171
+ isDeleted: params.isDeleted,
1172
+ typeOf: params.typeOf
1173
+ }
1174
+ };
1175
+ const taskAttributes = [syncAggregateOfferTask];
1176
+ const result = yield this.taskModel.insertMany(taskAttributes, { ordered: false, rawResult: true });
1177
+ if (result.insertedCount !== taskAttributes.length) {
1178
+ throw new factory.errors.ServiceUnavailable('all tasks not saved');
1179
+ }
1180
+ const savedTasks = Object.values(result.insertedIds)
1181
+ .map((objectId) => {
1182
+ return { id: objectId.toHexString() };
1183
+ });
1184
+ if (params.options.emitImmediately === true) {
1185
+ savedTasks.forEach((savedTask) => {
1186
+ task_2.taskEventEmitter.emitTaskStatusChanged({
1187
+ id: savedTask.id,
1188
+ status: factory.taskStatus.Ready
1189
+ });
1190
+ });
1191
+ }
1192
+ return savedTasks;
545
1193
  });
546
1194
  }
547
1195
  }