@chevre/domain 21.8.0-alpha.6 → 21.8.0-alpha.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/example/src/chevre/countOffers.ts +32 -0
  2. package/example/src/chevre/findItemListElementByCatalogId.ts +23 -0
  3. package/example/src/chevre/importOffersFromCOA.ts +7 -1
  4. package/example/src/chevre/migrateAggregateOffers.ts +89 -0
  5. package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
  6. package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
  7. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -0
  8. package/example/src/chevre/processPay.ts +3 -4
  9. package/example/src/chevre/publishPermitOwnershipInfoToken.ts +56 -0
  10. package/example/src/chevre/pullAddOnsFromOffer.ts +26 -0
  11. package/example/src/chevre/searchAggregateOffers.ts +48 -0
  12. package/example/src/chevre/searchEventTicketOffers.ts +3 -1
  13. package/example/src/chevre/searchEvents.ts +9 -7
  14. package/example/src/chevre/searchOffersByCatalog.ts +9 -5
  15. package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
  16. package/example/src/chevre/searchOrders.ts +9 -7
  17. package/example/src/chevre/sync2aggregateOffer.ts +27 -0
  18. package/example/src/chevre/syncAggregateOffer.ts +25 -0
  19. package/lib/chevre/emailMessageBuilder.js +6 -5
  20. package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
  21. package/lib/chevre/repo/aggregateOffer.js +534 -0
  22. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  23. package/lib/chevre/repo/assetTransaction.js +54 -2
  24. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +74 -0
  25. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +177 -0
  26. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +3 -3
  27. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +3 -3
  28. package/lib/chevre/repo/mongoose/schemas/event.d.ts +3 -3
  29. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +24 -33
  30. package/lib/chevre/repo/mongoose/schemas/offer.js +4 -3
  31. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  32. package/lib/chevre/repo/mongoose/schemas/order.js +7 -0
  33. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +9 -9
  34. package/lib/chevre/repo/mongoose/schemas/product.d.ts +3 -3
  35. package/lib/chevre/repo/mongoose/schemas/project.d.ts +3 -3
  36. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  37. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  38. package/lib/chevre/repo/offer.d.ts +82 -47
  39. package/lib/chevre/repo/offer.js +1279 -289
  40. package/lib/chevre/repo/offerCatalog.d.ts +6 -0
  41. package/lib/chevre/repo/offerCatalog.js +13 -0
  42. package/lib/chevre/repo/order.d.ts +15 -0
  43. package/lib/chevre/repo/order.js +58 -26
  44. package/lib/chevre/repo/task.d.ts +7 -1
  45. package/lib/chevre/repo/task.js +100 -0
  46. package/lib/chevre/repository.d.ts +3 -0
  47. package/lib/chevre/repository.js +5 -1
  48. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -1
  49. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -1
  50. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  51. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  52. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  53. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  54. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  55. package/lib/chevre/service/assetTransaction/registerService.js +2 -1
  56. package/lib/chevre/service/assetTransaction/reserve.js +111 -35
  57. package/lib/chevre/service/delivery.js +17 -0
  58. package/lib/chevre/service/offer/event/authorize.js +39 -35
  59. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  60. package/lib/chevre/service/offer/event/factory.js +8 -8
  61. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  62. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +1 -0
  63. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +6 -3
  64. package/lib/chevre/service/offer/event/voidTransaction.js +57 -36
  65. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  66. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +7 -11
  67. package/lib/chevre/service/offer/eventServiceByCOA.js +55 -27
  68. package/lib/chevre/service/offer/factory.d.ts +12 -4
  69. package/lib/chevre/service/offer/factory.js +9 -11
  70. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +8 -1
  71. package/lib/chevre/service/offer/product/searchProductOffers.js +10 -3
  72. package/lib/chevre/service/offer/product.d.ts +1 -0
  73. package/lib/chevre/service/offer/product.js +3 -2
  74. package/lib/chevre/service/offer.d.ts +1 -0
  75. package/lib/chevre/service/offer.js +7 -1
  76. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  77. package/lib/chevre/service/order/confirmPayTransaction.js +29 -40
  78. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  79. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  80. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  81. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  82. package/lib/chevre/service/order/onOrderStatusChanged.js +81 -54
  83. package/lib/chevre/service/order/payOrder.d.ts +2 -10
  84. package/lib/chevre/service/order/payOrder.js +4 -45
  85. package/lib/chevre/service/order/placeOrder.js +11 -13
  86. package/lib/chevre/service/order.d.ts +3 -1
  87. package/lib/chevre/service/order.js +6 -2
  88. package/lib/chevre/service/payment/any/factory.js +33 -8
  89. package/lib/chevre/service/payment/any.js +30 -21
  90. package/lib/chevre/service/payment/creditCard.js +12 -12
  91. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  92. package/lib/chevre/service/payment/movieTicket.js +10 -11
  93. package/lib/chevre/service/payment/paymentCard.js +9 -12
  94. package/lib/chevre/service/project.js +1 -1
  95. package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
  96. package/lib/chevre/service/reserve/checkInReservation.js +3 -2
  97. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  98. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +4 -5
  99. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +8 -0
  100. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +16 -11
  101. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  102. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  103. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +3 -5
  104. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  105. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  106. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  107. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  108. package/lib/chevre/service/task/onAuthorizationCreated.js +5 -1
  109. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +6 -0
  110. package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
  111. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
  112. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -0
  113. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +17 -0
  114. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +60 -0
  115. package/lib/chevre/service/task/onResourceUpdated.js +12 -0
  116. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  117. package/lib/chevre/service/task/syncAggregateOffer.d.ts +7 -0
  118. package/lib/chevre/service/task/syncAggregateOffer.js +23 -0
  119. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
  120. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
  121. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
  122. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  123. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  124. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  125. package/lib/chevre/settings.d.ts +5 -3
  126. package/lib/chevre/settings.js +6 -6
  127. package/package.json +3 -3
  128. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  129. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
@@ -0,0 +1,32 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // tslint:disable-next-line:max-func-body-length
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
+
12
+ const result = await offerRepo.count(
13
+ {
14
+ project: { id: { $eq: String(process.env.PROJECT_ID) } },
15
+ availability: { $eq: chevre.factory.itemAvailability.InStock },
16
+ id: {
17
+ // $eq: '1001'
18
+ // $in: string[];
19
+ },
20
+ identifier: {
21
+ // $eq: '1001'
22
+ // $in: string[];
23
+ // $regex: '003'
24
+ }
25
+ }
26
+ );
27
+ console.log(result);
28
+ }
29
+
30
+ main()
31
+ .then(console.log)
32
+ .catch(console.error);
@@ -0,0 +1,23 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
10
+
11
+ const catalog = await offerCatalogRepo.findItemListElementById(
12
+ {
13
+ id: '0001',
14
+ project: { id: String(process.env.PROJECT_ID) }
15
+ }
16
+ );
17
+ console.log(catalog);
18
+ console.log(catalog.itemListElement.length);
19
+ }
20
+
21
+ main()
22
+ .then(console.log)
23
+ .catch(console.error);
@@ -16,6 +16,7 @@ async function main() {
16
16
 
17
17
  const categoryCodeRepo = new chevre.repository.CategoryCode(mongoose.connection);
18
18
  const offerRepo = new chevre.repository.Offer(mongoose.connection);
19
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
19
20
  const masterService = new chevre.COA.service.Master(
20
21
  {
21
22
  endpoint: chevre.credentials.coa.endpoint,
@@ -27,7 +28,12 @@ async function main() {
27
28
  await chevre.service.offer.event.importFromCOA({
28
29
  project,
29
30
  theaterCode: '120'
30
- })({ categoryCode: categoryCodeRepo, offer: offerRepo, masterService });
31
+ })({
32
+ categoryCode: categoryCodeRepo,
33
+ offer: offerRepo,
34
+ task: taskRepo,
35
+ masterService
36
+ });
31
37
  console.log('imported');
32
38
  }
33
39
 
@@ -0,0 +1,89 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+ import * as util from 'util';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const offerRepo = new chevre.repository.Offer(mongoose.connection);
14
+
15
+ const cursor = offerRepo.getCursor(
16
+ {
17
+ // 'project.id': { $eq: project.id }
18
+ },
19
+ {
20
+ __v: 0,
21
+ createdAt: 0,
22
+ updatedAt: 0,
23
+ offers: 0,
24
+ availableAddOn: 0
25
+ }
26
+ );
27
+ console.log('offers found');
28
+
29
+ let i = 0;
30
+ let updateCount = 0;
31
+ await cursor.eachAsync(async (doc) => {
32
+ i += 1;
33
+ const { _id, ...unitPriceOffer } =
34
+ <chevre.factory.unitPriceOffer.IUnitPriceOffer & { _id: string }>doc.toObject();
35
+
36
+ let alreadyMigrated = false;
37
+ const aggregateOffer = await offerRepo.findAggregateOfferById({
38
+ project: { id: unitPriceOffer.project.id },
39
+ id: String(unitPriceOffer.id)
40
+ });
41
+ let offerByAggregateOffer = aggregateOffer.offers.shift();
42
+ // alreadyMigrated = true;
43
+ console.log(unitPriceOffer, offerByAggregateOffer);
44
+
45
+ // 比較のために補完
46
+ if (offerByAggregateOffer !== undefined) {
47
+ offerByAggregateOffer = {
48
+ ...offerByAggregateOffer,
49
+ additionalProperty: (Array.isArray(offerByAggregateOffer.additionalProperty))
50
+ ? offerByAggregateOffer.additionalProperty : [],
51
+ addOn: (Array.isArray(offerByAggregateOffer.addOn))
52
+ ? offerByAggregateOffer.addOn : [],
53
+ availableAtOrFrom: (Array.isArray(offerByAggregateOffer.availableAtOrFrom))
54
+ ? offerByAggregateOffer.availableAtOrFrom : []
55
+ };
56
+ // delete (<any>offerByAggregateOffer).$unset;
57
+ }
58
+
59
+ if (util.isDeepStrictEqual(unitPriceOffer, offerByAggregateOffer)) {
60
+ alreadyMigrated = true;
61
+ } else {
62
+ console.error(unitPriceOffer, offerByAggregateOffer);
63
+ throw new Error('not matched');
64
+ }
65
+
66
+ if (alreadyMigrated) {
67
+ console.log('already exist.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
68
+ } else {
69
+ console.log('updating...', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
70
+ // await offerRepo.saveSyncTask({
71
+ // project: { id: unitPriceOffer.project.id },
72
+ // id: { $in: [String(unitPriceOffer.id)] },
73
+ // identifier: { $in: [] },
74
+ // isDeleted: false,
75
+ // typeOf: chevre.factory.offerType.Offer,
76
+ // options: { emitImmediately: false }
77
+ // });
78
+ updateCount += 1;
79
+ console.log('updated.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
80
+ }
81
+ });
82
+
83
+ console.log(i, 'offers checked');
84
+ console.log(updateCount, 'offers updated');
85
+ }
86
+
87
+ main()
88
+ .then()
89
+ .catch(console.error);
@@ -0,0 +1,81 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const orderRepo = new chevre.repository.Order(mongoose.connection);
14
+
15
+ const cursor = orderRepo.getCursor(
16
+ {
17
+ // 'project.id': { $eq: project.id },
18
+ // orderNumber: { $eq: 'KNR1-3961294-9087043' },
19
+ orderDate: {
20
+ $gte: moment()
21
+ // tslint:disable-next-line:no-magic-numbers
22
+ .add(-12, 'months')
23
+ .toDate()
24
+ // $lte: moment()
25
+ // // tslint:disable-next-line:no-magic-numbers
26
+ // .add(-6, 'months')
27
+ // .toDate()
28
+ }
29
+ },
30
+ {
31
+ orderDate: 1,
32
+ orderNumber: 1,
33
+ project: 1,
34
+ paymentMethods: 1
35
+ }
36
+ );
37
+ console.log('orders found');
38
+
39
+ let i = 0;
40
+ let updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ i += 1;
43
+ const order: Pick<
44
+ chevre.factory.order.IOrder,
45
+ 'orderDate' | 'orderNumber' | 'project' | 'paymentMethods'
46
+ > = doc.toObject();
47
+
48
+ const noPayment = order.paymentMethods.length === 0;
49
+ const alreadyMigrated = order.paymentMethods.every((invoice) => {
50
+ return typeof invoice.paymentMethod?.identifier === 'string'
51
+ && invoice.paymentMethod.identifier === invoice.typeOf;
52
+ });
53
+
54
+ if (noPayment) {
55
+ console.log('noPayment.', order.project.id, order.orderNumber, order.orderDate, i);
56
+ } else if (alreadyMigrated) {
57
+ console.log('already exist.', order.project.id, order.orderNumber, order.orderDate, i);
58
+ } else {
59
+ console.log('updating...', order.project.id, order.orderNumber, order.orderDate, i);
60
+ for (const invoice of order.paymentMethods) {
61
+ await orderRepo.fixPaymentMethodIdentifier({
62
+ project: { id: order.project.id },
63
+ orderNumber: order.orderNumber,
64
+ invoice: {
65
+ paymentMethodId: invoice.paymentMethodId,
66
+ paymentMethod: { identifier: invoice.typeOf }
67
+ }
68
+ });
69
+ }
70
+ updateCount += 1;
71
+ console.log('updated.', order.project.id, order.orderNumber, order.orderDate, i);
72
+ }
73
+ });
74
+
75
+ console.log(i, 'orders checked');
76
+ console.log(updateCount, 'orders updated');
77
+ }
78
+
79
+ main()
80
+ .then()
81
+ .catch(console.error);
@@ -0,0 +1,72 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
14
+
15
+ const cursor = assetTransactionRepo.getCursor(
16
+ {
17
+ typeOf: { $eq: chevre.factory.assetTransactionType.Pay },
18
+ // 'object.paymentMethodId': { $exists: false },
19
+ // 'project.id': { $eq: project.id },
20
+ startDate: {
21
+ $gte: moment()
22
+ // tslint:disable-next-line:no-magic-numbers
23
+ .add(-12, 'months')
24
+ .toDate()
25
+ }
26
+ },
27
+ {
28
+ typeOf: 1,
29
+ project: 1,
30
+ object: 1,
31
+ transactionNumber: 1,
32
+ startDate: 1
33
+ }
34
+ );
35
+ console.log('transactions found');
36
+
37
+ let i = 0;
38
+ let updateCount = 0;
39
+ await cursor.eachAsync(async (doc) => {
40
+ i += 1;
41
+ const payTransaction: Pick<
42
+ chevre.factory.assetTransaction.pay.ITransaction,
43
+ 'project' | 'object' | 'transactionNumber' | 'startDate' | 'typeOf'
44
+ > = doc.toObject();
45
+
46
+ const alreadyMigrated = typeof payTransaction.object.paymentMethodId === 'string'
47
+ && payTransaction.object.paymentMethodId === (<any>payTransaction.object.paymentMethod).paymentMethodId;
48
+
49
+ if (alreadyMigrated) {
50
+ console.log(
51
+ 'already exist.',
52
+ payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i);
53
+ } else {
54
+ const paymentMethodIdentifier = (<any>payTransaction.object.paymentMethod).typeOf;
55
+ console.log(
56
+ 'updating...',
57
+ payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i,
58
+ paymentMethodIdentifier);
59
+ updateCount += 1;
60
+ console.log(
61
+ 'updated.',
62
+ payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i);
63
+ }
64
+ });
65
+
66
+ console.log(i, 'transactions checked');
67
+ console.log(updateCount, 'transactions updated');
68
+ }
69
+
70
+ main()
71
+ .then()
72
+ .catch(console.error);
@@ -0,0 +1,78 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
14
+
15
+ const cursor = assetTransactionRepo.getCursor(
16
+ {
17
+ typeOf: { $eq: chevre.factory.assetTransactionType.Pay },
18
+ // 'project.id': { $eq: project.id },
19
+ startDate: {
20
+ $gte: moment('2023-05-08T00:00:00Z')
21
+ // tslint:disable-next-line:no-magic-numbers
22
+ // .add(-12, 'months')
23
+ .toDate(),
24
+ $lte: moment('2023-08-30T21:00:00Z')
25
+ .toDate()
26
+ }
27
+ },
28
+ {
29
+ typeOf: 1,
30
+ project: 1,
31
+ object: 1,
32
+ transactionNumber: 1,
33
+ startDate: 1
34
+ }
35
+ );
36
+ console.log('transactions found');
37
+
38
+ let i = 0;
39
+ let updateCount = 0;
40
+ await cursor.eachAsync(async (doc) => {
41
+ i += 1;
42
+ const payTransaction: Pick<
43
+ chevre.factory.assetTransaction.pay.ITransaction,
44
+ 'project' | 'object' | 'transactionNumber' | 'startDate' | 'typeOf'
45
+ > = doc.toObject();
46
+
47
+ const alreadyMigrated = payTransaction.object.paymentMethod.identifier
48
+ === (<any>payTransaction.object.paymentMethod).typeOf;
49
+
50
+ if (alreadyMigrated) {
51
+ console.log(
52
+ 'already exist.',
53
+ payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate,
54
+ i, updateCount);
55
+ } else {
56
+ const paymentMethodIdentifier = (<any>payTransaction.object.paymentMethod).typeOf;
57
+ console.log(
58
+ 'updating...',
59
+ payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i,
60
+ paymentMethodIdentifier);
61
+ await assetTransactionRepo.migratePaymentMethodIdentifier({
62
+ transactionNumber: payTransaction.transactionNumber,
63
+ object: { paymentMethod: { identifier: paymentMethodIdentifier } }
64
+ });
65
+ updateCount += 1;
66
+ console.log(
67
+ 'updated.',
68
+ payTransaction.project.id, payTransaction.typeOf, payTransaction.transactionNumber, payTransaction.startDate, i);
69
+ }
70
+ });
71
+
72
+ console.log(i, 'transactions checked');
73
+ console.log(updateCount, 'transactions updated');
74
+ }
75
+
76
+ main()
77
+ .then()
78
+ .catch(console.error);
@@ -43,14 +43,13 @@ async function main() {
43
43
  .toDate(),
44
44
  object: {
45
45
  typeOf: chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
46
- id: '5f9a6986cc98a1eb13a90285',
46
+ id: 'xxx',
47
47
  paymentMethod: {
48
48
  amount: 1,
49
- // paymentMethodId?: string;
50
- typeOf: 'CreditCard',
49
+ identifier: 'CreditCard',
51
50
  method: '1',
52
51
  creditCard: {
53
- memberId: 'a7909268-a584-425e-8212-d7d10f344093',
52
+ memberId: 'xxx',
54
53
  cardSeq: 91
55
54
  // cardPass?: string;
56
55
  }
@@ -0,0 +1,56 @@
1
+ // tslint:disable:no-console
2
+ import * as jwt from 'jsonwebtoken';
3
+ import { chevre } from '../../../lib/index';
4
+
5
+ function getToken(params: {
6
+ expiresIn: number;
7
+ payload: chevre.factory.authorization.IOwnershipInfoAsObject;
8
+ }) {
9
+ return async (__: {}) => {
10
+ // const now = new Date();
11
+
12
+ // const data = authorization.object;
13
+
14
+ return new Promise<string>((resolve, reject) => {
15
+ // 所有権を暗号化する
16
+ jwt.sign(
17
+ params.payload,
18
+ chevre.credentials.jwt.secret,
19
+ // params.secret,
20
+ {
21
+ issuer: chevre.credentials.jwt.issuer,
22
+ // issuer: params.issuer,
23
+ expiresIn: params.expiresIn
24
+ },
25
+ (err, encoded) => {
26
+ if (err instanceof Error) {
27
+ reject(err);
28
+ } else {
29
+ if (typeof encoded !== 'string') {
30
+ reject(new chevre.factory.errors.ServiceUnavailable('authorization.object cannot be signed unexpectedly'));
31
+ } else {
32
+ resolve(encoded);
33
+ }
34
+ }
35
+ }
36
+ );
37
+ });
38
+ };
39
+ }
40
+
41
+ getToken({
42
+ expiresIn: 2678400,
43
+ payload: {
44
+ typeOf: 'OwnershipInfo',
45
+ id: '',
46
+ typeOfGood: {
47
+ typeOf: chevre.factory.permit.PermitType.Permit,
48
+ identifier: 'xxxxxxxxxxxx',
49
+ issuedThrough: { id: '64f193ad5e79fe8a06ca3156', typeOf: chevre.factory.service.paymentService.PaymentServiceType.CreditCard }
50
+ }
51
+ }
52
+ })({})
53
+ .then((token) => {
54
+ console.log('token:', token);
55
+ })
56
+ .catch(console.error);
@@ -0,0 +1,26 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const offerRepo = new chevre.repository.Offer(mongoose.connection);
10
+
11
+ const result = await offerRepo.pullAddOns({
12
+ project: { id: String(process.env.PROJECT_ID) },
13
+ addOn: {
14
+ itemOffered: {
15
+ id: {
16
+ $in: ['xxx']
17
+ }
18
+ }
19
+ }
20
+ });
21
+ console.log(result);
22
+ }
23
+
24
+ main()
25
+ .then(console.log)
26
+ .catch(console.error);
@@ -0,0 +1,48 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const aggregateOfferRepo = new chevre.repository.AggregateOffer(mongoose.connection);
10
+
11
+ const offers = await aggregateOfferRepo.search(
12
+ {
13
+ limit: 10,
14
+ // page: 1,
15
+ project: { id: { $eq: String(process.env.PROJECT_ID) } },
16
+ availability: { $eq: chevre.factory.itemAvailability.InStock },
17
+ itemOffered: { typeOf: { $eq: chevre.factory.product.ProductType.EventService } },
18
+ // identifier: { $eq: '901' },
19
+ sort: {
20
+ 'priceSpecification.price': 1,
21
+ identifier: 1
22
+ }
23
+ },
24
+ {
25
+ id: 1,
26
+ identifier: 1,
27
+ name: 1,
28
+ priceSpecification: 1
29
+ }
30
+ );
31
+ console.log(offers);
32
+ console.log(offers[0]?.offers);
33
+ console.log(offers.map((offer) => {
34
+ return `${offer.project.id} ${(<any>offer).offerCount} ${offer.offers[0].identifier} ${offer.offers[0].name.ja} ${offer.offers[0].priceSpecification.price}`;
35
+ }));
36
+ console.log(offers.length);
37
+
38
+ const aggregateOfferCount = await aggregateOfferRepo.count({
39
+ project: { id: { $eq: String(process.env.PROJECT_ID) } },
40
+ availability: { $eq: chevre.factory.itemAvailability.InStock },
41
+ itemOffered: { typeOf: { $eq: chevre.factory.product.ProductType.EventService } }
42
+ });
43
+ console.log('aggregateOfferCount:', aggregateOfferCount);
44
+ }
45
+
46
+ main()
47
+ .then(console.log)
48
+ .catch(console.error);
@@ -30,7 +30,8 @@ async function main() {
30
30
  validateOfferRateLimit: true,
31
31
  addSortIndex: true,
32
32
  limit: 100,
33
- page: 1
33
+ page: 1,
34
+ useOffersAsPrimaryForcible: false
34
35
  // ...(typeof availableAtId === 'string') ? { store: { id: availableAtId } } : undefined
35
36
  })({
36
37
  event: eventRepo,
@@ -39,6 +40,7 @@ async function main() {
39
40
  priceSpecification: priceSpecificationRepo,
40
41
  product: productRepo
41
42
  });
43
+ console.log(ticketOffers);
42
44
  console.log(ticketOffers.map((o) => o.sortIndex));
43
45
  console.log(ticketOffers.length);
44
46
  }
@@ -12,15 +12,17 @@ async function main() {
12
12
 
13
13
  const events = await eventRepo.search(
14
14
  {
15
- limit: 100,
16
- page: 1,
17
- sort: { startDate: 1 },
18
- typeOf: chevre.factory.eventType.ScreeningEvent,
19
- project: { id: { $eq: PROJECT_ID } },
20
- id: { $eq: 'al6aff83y' }
15
+ // limit: 100,
16
+ // page: 1,
17
+ // sort: { startDate: 1 },
18
+ // typeOf: chevre.factory.eventType.ScreeningEvent,
19
+ // project: { id: { $eq: PROJECT_ID } },
20
+ id: { $eq: 'al6aff83y' },
21
+ typeOfIn: [chevre.factory.eventType.Event, chevre.factory.eventType.ScreeningEvent]
21
22
  },
22
23
  {
23
- name: 1
24
+ _id: 1
25
+ // name: 1
24
26
  }
25
27
  );
26
28
  console.log(events);
@@ -10,17 +10,21 @@ async function main() {
10
10
  const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
11
 
12
12
  const { offers } = await offerRepo.findOffersByOfferCatalogId({
13
- ids: ['al96nqj7z', 'xxx', '1001'],
14
- // ids: ['xx', 'xxx'],
13
+ limit: 100,
14
+ page: 1,
15
+ // ids: ['xx', 'xxx', '1001', '901'],
15
16
  offerCatalog: {
16
17
  id: '0001'
17
- // id: 'xxx'
18
18
  },
19
19
  excludeAppliesToMovieTicket: false,
20
- sort: true
20
+ useOffersAsPrimaryForcible: false
21
21
  });
22
- console.log(offers.map((o) => o.id));
22
+ // console.log(offers);
23
+ console.log(offers.map((offer) => {
24
+ return `${offer.project?.id} ${offer.identifier} ${offer.priceSpecification?.price} ${offer.name?.ja} ${offer.id} ${offer.offerIndex}`;
25
+ }));
23
26
  console.log(offers.length);
27
+ console.log('USE_AGGREGATE_OFFERS_AS_PRIMARY:', process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY);
24
28
  }
25
29
 
26
30
  main()