@chevre/domain 21.8.0-alpha.4 → 21.8.0-alpha.41

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 (87) hide show
  1. package/example/src/chevre/countOffers.ts +32 -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/pullAddOnsFromOffer.ts +26 -0
  10. package/example/src/chevre/searchOffersByCatalog.ts +9 -4
  11. package/example/src/chevre/searchOffersFromAggregateOffer.ts +167 -0
  12. package/example/src/chevre/sync2aggregateOffer.ts +27 -0
  13. package/example/src/chevre/syncAggregateOffer.ts +25 -0
  14. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  15. package/lib/chevre/repo/assetTransaction.js +54 -2
  16. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +71 -0
  17. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +176 -0
  18. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  19. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  20. package/lib/chevre/repo/mongoose/schemas/order.js +1 -0
  21. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  22. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  23. package/lib/chevre/repo/offer.d.ts +71 -14
  24. package/lib/chevre/repo/offer.js +1061 -87
  25. package/lib/chevre/repo/order.d.ts +15 -0
  26. package/lib/chevre/repo/order.js +34 -1
  27. package/lib/chevre/repo/task.d.ts +7 -1
  28. package/lib/chevre/repo/task.js +100 -0
  29. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -2
  30. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -2
  31. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  32. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  33. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  34. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  35. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  36. package/lib/chevre/service/assetTransaction/reserve.js +105 -31
  37. package/lib/chevre/service/delivery.js +17 -0
  38. package/lib/chevre/service/offer/event/authorize.js +18 -19
  39. package/lib/chevre/service/offer/event/factory.js +8 -8
  40. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  41. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +2 -2
  42. package/lib/chevre/service/offer/event/voidTransaction.js +7 -2
  43. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
  44. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  45. package/lib/chevre/service/order/confirmPayTransaction.js +29 -40
  46. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  47. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  48. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  49. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  50. package/lib/chevre/service/order/onOrderStatusChanged.js +104 -81
  51. package/lib/chevre/service/order/payOrder.d.ts +2 -10
  52. package/lib/chevre/service/order/payOrder.js +4 -45
  53. package/lib/chevre/service/order/placeOrder.js +11 -13
  54. package/lib/chevre/service/order.d.ts +3 -1
  55. package/lib/chevre/service/order.js +6 -2
  56. package/lib/chevre/service/payment/any/factory.js +33 -8
  57. package/lib/chevre/service/payment/any.js +30 -21
  58. package/lib/chevre/service/payment/creditCard.js +12 -12
  59. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  60. package/lib/chevre/service/payment/movieTicket.js +10 -11
  61. package/lib/chevre/service/payment/paymentCard.js +9 -12
  62. package/lib/chevre/service/project.js +1 -1
  63. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  64. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +1 -4
  65. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +1 -5
  66. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  67. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +1 -4
  68. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  69. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  70. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  71. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  72. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +6 -0
  73. package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
  74. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  75. package/lib/chevre/service/task/syncAggregateOffer.d.ts +7 -0
  76. package/lib/chevre/service/task/syncAggregateOffer.js +23 -0
  77. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
  78. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
  79. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
  80. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  81. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  82. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  83. package/lib/chevre/settings.d.ts +4 -2
  84. package/lib/chevre/settings.js +5 -5
  85. package/package.json +3 -3
  86. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  87. 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);
@@ -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,75 @@
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
+ try {
38
+ const aggregateOffer = await offerRepo.findAggregateOfferById({
39
+ project: { id: unitPriceOffer.project.id },
40
+ id: String(unitPriceOffer.id)
41
+ });
42
+ const offerByAggregateOffer = aggregateOffer.offers.shift();
43
+ // alreadyMigrated = true;
44
+ console.log(unitPriceOffer, offerByAggregateOffer);
45
+ if (util.isDeepStrictEqual(unitPriceOffer, offerByAggregateOffer)) {
46
+ alreadyMigrated = true;
47
+ }
48
+ } catch (error) {
49
+ // no op
50
+ }
51
+
52
+ if (alreadyMigrated) {
53
+ console.log('already exist.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
54
+ } else {
55
+ console.log('updating...', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
56
+ await offerRepo.saveSyncTask({
57
+ project: { id: unitPriceOffer.project.id },
58
+ id: { $in: [String(unitPriceOffer.id)] },
59
+ identifier: { $in: [] },
60
+ isDeleted: false,
61
+ typeOf: chevre.factory.offerType.Offer,
62
+ options: { emitImmediately: false }
63
+ });
64
+ updateCount += 1;
65
+ console.log('updated.', unitPriceOffer.project.id, unitPriceOffer.id, unitPriceOffer.identifier, i);
66
+ }
67
+ });
68
+
69
+ console.log(i, 'offers checked');
70
+ console.log(updateCount, 'offers updated');
71
+ }
72
+
73
+ main()
74
+ .then()
75
+ .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);
@@ -10,17 +10,22 @@ 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'],
13
+ limit: 100,
14
+ page: 1,
15
+ // ids: ['al96nqj7z', 'xxx', '1001'],
14
16
  // ids: ['xx', 'xxx'],
15
17
  offerCatalog: {
16
18
  id: '0001'
17
19
  // id: 'xxx'
18
20
  },
19
- excludeAppliesToMovieTicket: false,
20
- sort: true
21
+ excludeAppliesToMovieTicket: false
22
+ // useOffersAsPrimary: true
21
23
  });
22
- console.log(offers.map((o) => o.id));
24
+ console.log(offers.map((offer) => {
25
+ return `${offer.project?.id} ${offer.identifier} ${offer.priceSpecification?.price} ${offer.name?.ja} ${offer.id} ${(<any>offer).offerIndex}`;
26
+ }));
23
27
  console.log(offers.length);
28
+ console.log('USE_AGGREGATE_OFFERS_AS_PRIMARY:', process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY);
24
29
  }
25
30
 
26
31
  main()
@@ -0,0 +1,167 @@
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: true });
9
+
10
+ const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
+
12
+ const offers = await offerRepo.search(
13
+ {
14
+ limit: 10,
15
+ page: 1,
16
+ sort: {
17
+ 'priceSpecification.price': 1,
18
+ identifier: 1
19
+ },
20
+ project: { id: { $eq: String(process.env.PROJECT_ID) } },
21
+ availability: { $eq: chevre.factory.itemAvailability.InStock },
22
+ itemOffered: {
23
+ typeOf: {
24
+ // $eq: chevre.factory.product.ProductType.EventService
25
+ }
26
+ },
27
+ addOn: {
28
+ itemOffered: {
29
+ /**
30
+ * アドオンプロダクトID
31
+ */
32
+ id: {
33
+ // $eq: ''
34
+ }
35
+ }
36
+ },
37
+ availableAtOrFrom: {
38
+ id: {
39
+ // $eq: ''
40
+ // $in: string[]
41
+ }
42
+ },
43
+ eligibleMembershipType: {
44
+ /**
45
+ * 適用メンバーシップ区分
46
+ */
47
+ codeValue: {
48
+ // $eq: 'Permit'
49
+ }
50
+ },
51
+ eligibleMonetaryAmount: {
52
+ /**
53
+ * 適用通貨区分
54
+ */
55
+ currency: {
56
+ // $eq: 'Point'
57
+ }
58
+ },
59
+ eligibleSeatingType: {
60
+ /**
61
+ * 適用座席区分
62
+ */
63
+ codeValue: {
64
+ // $eq: ''
65
+ }
66
+ },
67
+ hasMerchantReturnPolicy: {
68
+ id: {
69
+ // $eq: ''
70
+ }
71
+ },
72
+ id: {
73
+ // $eq: '1001'
74
+ // $in: string[];
75
+ },
76
+ identifier: {
77
+ // $eq: '1001'
78
+ // $in: string[];
79
+ // $regex: '003'
80
+ },
81
+ name: {
82
+ // $regex: ''
83
+ },
84
+ priceSpecification: {
85
+ appliesToMovieTicket: {
86
+ /**
87
+ * 適用決済カード区分
88
+ */
89
+ serviceType: {
90
+ /**
91
+ * 適用決済カード区分が存在するかどうか
92
+ */
93
+ // $exists: boolean;
94
+ // $eq: '01'
95
+ },
96
+ serviceOutput: {
97
+ /**
98
+ * 適用決済方法タイプ
99
+ */
100
+ typeOf: {
101
+ // $eq: ''
102
+ // $nin: string[];
103
+ }
104
+ }
105
+ },
106
+ price: {
107
+ // $gte: 2000,
108
+ // $lte: 2000
109
+ },
110
+ referenceQuantity: {
111
+ value: {
112
+ // $eq: 2
113
+ }
114
+ },
115
+ accounting: {
116
+ accountsReceivable: {
117
+ // $gte: 1800,
118
+ // $lte: 100
119
+ },
120
+ operatingRevenue: {
121
+ codeValue: {
122
+ // $eq: ''
123
+ // $in: string[];
124
+ }
125
+ }
126
+ }
127
+ },
128
+ category: {
129
+ codeValue: {
130
+ // $in: ['1']
131
+ }
132
+ }
133
+ /**
134
+ * 有効期間設定がない、あるいは、有効期間内
135
+ */
136
+ // onlyValid: true
137
+ // additionalProperty: {
138
+ // $all: [
139
+ // {
140
+ // $elemMatch: {
141
+ // name: { $eq: 'nameForPrinting' },
142
+ // value: { $in: ['General'] }
143
+ // }
144
+ // }
145
+ // ]
146
+ // }
147
+ },
148
+ {
149
+ id: 1,
150
+ identifier: 1,
151
+ name: 1,
152
+ alternateName: 1,
153
+ priceSpecification: 1,
154
+ project: 1
155
+ }
156
+ );
157
+ console.log(offers);
158
+ console.log(offers.map((offer) => {
159
+ return `${offer.project?.id} ${offer.identifier} ${offer.priceSpecification?.price} ${offer.name?.ja} ${offer.id}`;
160
+ }));
161
+ console.log(offers.length);
162
+ console.log('USE_AGGREGATE_OFFERS_AS_PRIMARY:', process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY);
163
+ }
164
+
165
+ main()
166
+ .then(console.log)
167
+ .catch(console.error);
@@ -0,0 +1,27 @@
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.sync2aggregateOffer({
13
+ id: {
14
+ $in: ['1001']
15
+ },
16
+ project: {
17
+ id: String(process.env.PROJECT_ID)
18
+ },
19
+ isDeleted: false,
20
+ typeOf: chevre.factory.offerType.AggregateOffer
21
+ });
22
+ console.log(result);
23
+ }
24
+
25
+ main()
26
+ .then(console.log)
27
+ .catch(console.error);