@chevre/domain 23.0.0-alpha.9 → 23.1.0-alpha.0

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 (68) hide show
  1. package/example/src/chevre/assetTransaction/processReserve.ts +102 -40
  2. package/example/src/chevre/categoryCode/checkUniqueness.ts +69 -0
  3. package/example/src/chevre/event/checkEventAdditionalPropertyUniqueness.ts +108 -0
  4. package/example/src/chevre/event/migrateEventAdditionalProperty2identifier.ts +121 -0
  5. package/example/src/chevre/event/updateSellerMakesOffersByIdentifier.ts +106 -0
  6. package/example/src/chevre/offerCatalog/updateManyOfferCatalogsByIds.ts +49 -0
  7. package/example/src/chevre/paymentServices/findPaymentServices.ts +37 -0
  8. package/example/src/chevre/product/findHasOfferCatalog.ts +14 -10
  9. package/example/src/chevre/reIndex.ts +2 -3
  10. package/example/src/chevre/roles/{addAdminProductReadPermissionIfNotExists.ts → addAdminPaymentServiceReadPermissionIfNotExists.ts} +1 -1
  11. package/example/src/chevre/roles/addAdminProductHasOfferCatalogReadPermissionIfNotExists.ts +33 -0
  12. package/example/src/chevre/roles/addAdminSellerEventIfNotExists.ts +48 -0
  13. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +1 -1
  14. package/example/src/chevre/roles/removePermissionIfExists.ts +1 -6
  15. package/example/src/objectId.ts +12 -0
  16. package/example/src/signPayload.ts +12 -7
  17. package/lib/chevre/errorHandler.d.ts +6 -2
  18. package/lib/chevre/errorHandler.js +18 -2
  19. package/lib/chevre/repo/categoryCode.d.ts +26 -14
  20. package/lib/chevre/repo/categoryCode.js +53 -42
  21. package/lib/chevre/repo/event.d.ts +25 -11
  22. package/lib/chevre/repo/event.js +60 -35
  23. package/lib/chevre/repo/eventSellerMakesOffer.d.ts +24 -39
  24. package/lib/chevre/repo/eventSellerMakesOffer.js +88 -43
  25. package/lib/chevre/repo/issuer.js +9 -5
  26. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +48 -42
  27. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.d.ts +10 -0
  28. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +107 -0
  29. package/lib/chevre/repo/mongoose/schemas/product.d.ts +4 -4
  30. package/lib/chevre/repo/mongoose/schemas/product.js +2 -2
  31. package/lib/chevre/repo/movieTicketType.d.ts +57 -0
  32. package/lib/chevre/repo/movieTicketType.js +253 -0
  33. package/lib/chevre/repo/offerCatalog.d.ts +17 -2
  34. package/lib/chevre/repo/offerCatalog.js +5 -2
  35. package/lib/chevre/repo/productHasOfferCatalog.d.ts +1 -0
  36. package/lib/chevre/repo/productHasOfferCatalog.js +5 -1
  37. package/lib/chevre/repository.d.ts +5 -0
  38. package/lib/chevre/repository.js +15 -2
  39. package/lib/chevre/service/assetTransaction/reserve/start.js +2 -2
  40. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +15 -0
  41. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +159 -0
  42. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +16 -0
  43. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +184 -0
  44. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +4 -1
  45. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +25 -139
  46. package/lib/chevre/service/event.js +1 -1
  47. package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
  48. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -3
  49. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +3 -3
  50. package/lib/chevre/service/offer/onEventChanged.js +26 -30
  51. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +39 -0
  52. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +86 -0
  53. package/lib/chevre/service/payment/any/{handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts → authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts} +4 -4
  54. package/lib/chevre/service/payment/any/{handlePrePublishedPaymentMethodIdOnAuthorizing.js → authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js} +1 -1
  55. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +25 -0
  56. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +51 -0
  57. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.d.ts +2 -2
  58. package/lib/chevre/service/payment/any.js +91 -70
  59. package/lib/chevre/service/project.d.ts +3 -0
  60. package/lib/chevre/service/project.js +2 -1
  61. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +1 -1
  62. package/lib/chevre/service/task/onResourceUpdated.js +1 -1
  63. package/package.json +4 -4
  64. package/example/src/chevre/aggregateEventSellerMakesOffer.ts +0 -32
  65. package/example/src/chevre/event/migrateEventIdentifier4ttts.ts +0 -96
  66. package/example/src/chevre/searchCategoryCodesByAggregate.ts +0 -31
  67. package/example/src/chevre/searchOfferCatalogItems.ts +0 -59
  68. package/example/src/chevre/searchPaymentServices.ts +0 -32
@@ -6,8 +6,16 @@ import * as redis from 'redis';
6
6
  import { chevre } from '../../../../lib/index';
7
7
 
8
8
  const project = { id: String(process.env.PROJECT_ID) };
9
+ const { EVENT_ID, OFFER_ID, APPLICATION_ID, OFFER_TOKEN } = process.env;
9
10
 
11
+ // tslint:disable-next-line:max-func-body-length
10
12
  async function main() {
13
+ if (typeof EVENT_ID !== 'string'
14
+ || typeof OFFER_ID !== 'string'
15
+ || typeof APPLICATION_ID !== 'string') {
16
+ throw new Error('environment variables required');
17
+ }
18
+
11
19
  const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
12
20
  socket: {
13
21
  port: Number(<string>process.env.REDIS_PORT),
@@ -21,59 +29,113 @@ async function main() {
21
29
  const transactionNumberRepo = await chevre.repository.TransactionNumber.createInstance({
22
30
  connection: mongoose.connection
23
31
  });
24
- const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
25
-
26
32
  const { transactionNumber } = await transactionNumberRepo.publishByTimestamp({ startDate: new Date() });
27
33
  const provider: chevre.factory.reservation.IProvider = {
28
34
  id: '59d20831e53ebc2b4e774466',
29
35
  typeOf: chevre.factory.organizationType.Corporation
30
36
  };
31
- const reserveTransaction = await assetTransactionRepo.start<chevre.factory.assetTransactionType.Reserve>({
32
- project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
33
- typeOf: chevre.factory.assetTransactionType.Reserve,
34
- transactionNumber,
35
- agent: { ...provider, name: 'sample agent name' },
36
- object: {
37
- provider,
38
- reservationNumber: transactionNumber,
39
- reservationStatus: chevre.factory.reservationStatusType.ReservationPending,
40
- disablePendingReservations: true,
41
- useHoldStockByTransactionNumber: true,
42
- typeOf: chevre.factory.reservationType.ReservationPackage
43
- },
44
- expires: moment()
45
- .add(1, 'minute')
46
- .toDate()
47
- });
48
- let cancelResult = await assetTransactionRepo.cancel<chevre.factory.assetTransactionType.Reserve>({
49
- typeOf: reserveTransaction.typeOf,
50
- id: reserveTransaction.id
51
- });
52
- console.log('cancelResult:', cancelResult);
53
- cancelResult = await assetTransactionRepo.cancel<chevre.factory.assetTransactionType.Reserve>({
54
- typeOf: reserveTransaction.typeOf,
55
- id: reserveTransaction.id
56
- });
57
- console.log('cancelResult:', cancelResult);
58
37
 
59
- let transaction = await assetTransactionRepo.findById<chevre.factory.assetTransactionType.Reserve>(
38
+ const { transaction } = await (await chevre.service.assetTransaction.createService()).reserve.start(
60
39
  {
40
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
61
41
  typeOf: chevre.factory.assetTransactionType.Reserve,
62
- id: reserveTransaction.id
42
+ transactionNumber,
43
+ agent: { ...provider, name: 'sample agent name' },
44
+ object: {
45
+ acceptedOffer: [{
46
+ /**
47
+ * オファーID
48
+ */
49
+ id: OFFER_ID,
50
+ /**
51
+ * アイテム情報
52
+ * 予約の詳細指定など
53
+ */
54
+ itemOffered: {
55
+ serviceOutput: {
56
+ typeOf: chevre.factory.reservationType.EventReservation,
57
+ reservedTicket: {
58
+ /**
59
+ * チケット識別子
60
+ * 指定された場合、決済カードの対象チケット識別子と関連付けされます
61
+ * /^[0-9a-zA-Z]{8,16}$/
62
+ */
63
+ // identifier?: string;
64
+ // issuedBy?: ReservationFactory.IUnderName;
65
+ typeOf: 'Ticket',
66
+ ticketedSeat: {
67
+ typeOf: chevre.factory.placeType.Seat,
68
+ seatNumber: 'A-01',
69
+ seatRow: '',
70
+ seatSection: 'Default'
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }],
76
+ reservationFor: {
77
+ id: EVENT_ID,
78
+ offers: {
79
+ token: OFFER_TOKEN,
80
+ identifier: 'LegacyReservation'
81
+ }
82
+ }
83
+ },
84
+ expires: moment()
85
+ // tslint:disable-next-line:no-magic-numbers
86
+ .add(5, 'seconds')
87
+ .toDate(),
88
+ validateEvent: false,
89
+ validateEventOfferPeriod: true,
90
+ validateAppliesToMovieTicket: true,
91
+ instrument: [],
92
+ availableAtOrFrom: { id: APPLICATION_ID }
93
+ // stockHoldUntilDaysAfterEventEnd: STOCK_HOLD_UNTIL_DAYS_AFTER_EVENT_END
63
94
  },
64
- ['status', 'transactionNumber', 'project', 'typeOf']
65
- );
66
- console.log('transaction:', transaction);
67
-
68
- transaction = await assetTransactionRepo.findByTransactionNumber<chevre.factory.assetTransactionType.Reserve>(
95
+ { maxReservationGracePeriodInDays: 93 }
96
+ )(
69
97
  {
70
- typeOf: chevre.factory.assetTransactionType.Reserve,
71
- transactionNumber
98
+ advanceBookingRequirement: await chevre.repository.AdvanceBookingRequirement.createInstance(mongoose.connection),
99
+ project: await chevre.repository.Project.createInstance(mongoose.connection),
100
+ stockHolder: await chevre.repository.StockHolder.createInstance({ connection: mongoose.connection }),
101
+ event: await chevre.repository.Event.createInstance(mongoose.connection),
102
+ eventSeries: await chevre.repository.EventSeries.createInstance(mongoose.connection),
103
+ issuer: await chevre.repository.Issuer.createInstance(mongoose.connection),
104
+ memberProgram: await chevre.repository.MemberProgram.createInstance(mongoose.connection),
105
+ offer: await chevre.repository.Offer.createInstance(mongoose.connection),
106
+ offerCatalog: await chevre.repository.OfferCatalog.createInstance(mongoose.connection),
107
+ offerCatalogItem: await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection),
108
+ offerRateLimit: await chevre.repository.rateLimit.Offer.createInstance(redisClient),
109
+ paymentService: await chevre.repository.PaymentService.createInstance(mongoose.connection),
110
+ priceSpecification: await chevre.repository.PriceSpecification.createInstance(mongoose.connection),
111
+ product: await chevre.repository.Product.createInstance(mongoose.connection),
112
+ productOffer: await chevre.repository.ProductOffer.createInstance(mongoose.connection),
113
+ seat: await chevre.repository.place.Seat.createInstance(mongoose.connection),
114
+ setting: await chevre.repository.Setting.createInstance(mongoose.connection),
115
+ task: await chevre.repository.Task.createInstance(mongoose.connection),
116
+ assetTransaction: await chevre.repository.AssetTransaction.createInstance(mongoose.connection)
72
117
  },
73
- ['status']
118
+ new chevre.settings.Settings({
119
+ abortedTasksWithoutReport: [],
120
+ numTryConfirmReserveTransaction: 10,
121
+ deliverOrderLimit: 1,
122
+ coa: { timeout: 20000 },
123
+ gmo: {
124
+ timeout: 5000,
125
+ timeoutBackground: 5000,
126
+ useFetch: true
127
+ },
128
+ movieticketReserve: {
129
+ timeout: 5000,
130
+ timeoutCheck: 5000,
131
+ minIntervalBetweenPayAndRefund: 1,
132
+ credentialsExpireInSeconds: 300
133
+ },
134
+ // useAssetTransactionSyncProcessing: process.env.USE_ASSET_TRANSACTION_SYNC_PROCESSING === '1',
135
+ useExperimentalFeature: false
136
+ })
74
137
  );
75
138
  console.log('transaction:', transaction);
76
-
77
139
  }
78
140
 
79
141
  main()
@@ -0,0 +1,69 @@
1
+ // tslint:disable:no-console no-magic-numbers
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 categoryCodeRepo = await chevre.repository.CategoryCode.createInstance(mongoose.connection);
11
+
12
+ const cursor = categoryCodeRepo.getCursor(
13
+ {
14
+ // _id: { $eq: '68f5d32176b5f6b689ff24a6' },
15
+ // 'project.id': { $eq: project.id },
16
+ // 'additionalProperty.name': { $exists: true, $eq: PROPERTY_NAME }
17
+ 'inCodeSet.identifier': { $ne: chevre.factory.movieTicketType.CategorySetIdentifier.MovieTicketType }
18
+ },
19
+ {
20
+ _id: 1,
21
+ codeValue: 1,
22
+ project: 1,
23
+ inCodeSet: 1,
24
+ name: 1,
25
+ typeOf: 1
26
+ }
27
+ );
28
+ console.log('docs found');
29
+
30
+ let i = 0;
31
+ let notUniqueCount = 0;
32
+ await cursor.eachAsync(async (doc) => {
33
+ i += 1;
34
+ const categoryCode: Pick<
35
+ chevre.factory.categoryCode.ICategoryCode,
36
+ 'codeValue' | 'id' | 'inCodeSet' | 'name' | 'project' | 'typeOf'
37
+ > = doc.toObject();
38
+
39
+ // console.log('unique?', categoryCode.project.id, categoryCode.id, categoryCode.codeValue, i);
40
+
41
+ const sameCodeValues = (await categoryCodeRepo.projectCategoryCodeFields(
42
+ {
43
+ project: { id: { $eq: categoryCode.project.id } },
44
+ codeValue: { $eq: categoryCode.codeValue }
45
+ // inCodeSet:{identifier:{$}}
46
+ },
47
+ ['codeValue', 'inCodeSet']
48
+ )).filter(
49
+ ({ inCodeSet }) => <unknown>inCodeSet.identifier !== chevre.factory.movieTicketType.CategorySetIdentifier.MovieTicketType
50
+ );
51
+ // console.log(sameCodeValues, 'sameCodeValues found', categoryCode.project.id, categoryCode.id, categoryCode.codeValue, i);
52
+
53
+ const isUnique = sameCodeValues.length === 1;
54
+ if (isUnique) {
55
+ // console.log(
56
+ // 'unique.', categoryCode.project.id, categoryCode.id, categoryCode.codeValue, i);
57
+ } else {
58
+ notUniqueCount += 1;
59
+ console.log('not unique.', categoryCode.project.id, categoryCode.id, categoryCode.codeValue, i);
60
+ }
61
+ });
62
+
63
+ console.log(i, 'docs checked');
64
+ console.log(notUniqueCount, 'docs not unique');
65
+ }
66
+
67
+ main()
68
+ .then()
69
+ .catch(console.error);
@@ -0,0 +1,108 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import { webcrypto } from 'crypto';
3
+ import * as moment from 'moment';
4
+ import * as mongoose from 'mongoose';
5
+
6
+ import { chevre } from '../../../../lib/index';
7
+
8
+ // const project = { id: String(process.env.PROJECT_ID) };
9
+ const PROPERTY_NAME = 'createId';
10
+
11
+ async function additionalProperty2identifier(raw: string) {
12
+ const data = new TextEncoder().encode(raw);
13
+ const hashBuffer = await webcrypto.subtle.digest('SHA-256', data);
14
+ const bytes = Array.from(new Uint8Array(hashBuffer));
15
+
16
+ // 0-9 + a-z の36文字セット
17
+ const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
18
+ // tslint:disable-next-line:no-magic-numbers
19
+ const id = bytes.map((b) => chars[b % 36])
20
+ .join('');
21
+
22
+ // tslint:disable-next-line:no-magic-numbers
23
+ return id.slice(0, 16);
24
+ }
25
+
26
+ const identifierMustMatch = /^[0-9a-zA-Z]+$/;
27
+ function validateIdentifier(identifier: string) {
28
+ if (!identifierMustMatch.test(identifier)) {
29
+ throw new Error(`not matched ${identifier}`);
30
+ }
31
+
32
+ if (identifier.length < 8 || identifier.length > 32) {
33
+ throw new Error(`invalid length ${identifier}`);
34
+ }
35
+ }
36
+
37
+ // tslint:disable-next-line:max-func-body-length
38
+ async function main() {
39
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
40
+
41
+ const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
42
+
43
+ const cursor = eventRepo.getCursor(
44
+ {
45
+ // _id: { $eq: '68f5d32176b5f6b689ff24a6' },
46
+ // 'project.id': { $eq: project.id },
47
+ 'additionalProperty.name': { $exists: true, $eq: PROPERTY_NAME },
48
+ startDate: {
49
+ $gte: moment()
50
+ .add(-1, 'days')
51
+ .toDate()
52
+ }
53
+ },
54
+ {
55
+ _id: 1,
56
+ startDate: 1,
57
+ project: 1,
58
+ identifier: 1,
59
+ additionalProperty: 1,
60
+ typeOf: 1
61
+ }
62
+ );
63
+ console.log('events found');
64
+
65
+ let i = 0;
66
+ await cursor.eachAsync(async (doc) => {
67
+ i += 1;
68
+ const event: Pick<
69
+ chevre.factory.event.screeningEvent.IEvent,
70
+ 'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
71
+ > = doc.toObject();
72
+
73
+ console.log(
74
+ 'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
75
+ const eventIdentifier = event.identifier;
76
+ const additionalPropertyValue = event.additionalProperty?.find(({ name }) => name === PROPERTY_NAME)?.value;
77
+ if (typeof additionalPropertyValue !== 'string') {
78
+ throw new Error('additionalPropertyValue not found');
79
+ }
80
+ const identifierMustBe = await additionalProperty2identifier(additionalPropertyValue);
81
+ validateIdentifier(identifierMustBe);
82
+
83
+ // const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier.length > 0;
84
+ // const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === identifierMustBe;
85
+
86
+ console.log(
87
+ 'checking...',
88
+ identifierMustBe, event.project.id, eventIdentifier, additionalPropertyValue, event.id, event.startDate, i);
89
+ const existingEvents = await eventRepo.findByAdditionalProperty(
90
+ {
91
+ // limit: 2,
92
+ // page: 1,
93
+ project: { id: event.project.id },
94
+ additionalProperty: { name: PROPERTY_NAME, value: additionalPropertyValue }
95
+ }
96
+ );
97
+ console.log('existingEvents found.', existingEvents.length, existingEvents);
98
+ if (existingEvents.length !== 1 || existingEvents[0]._id !== event.id) {
99
+ throw new Error(`not unique! ${event.id} ${additionalPropertyValue}`);
100
+ }
101
+ });
102
+
103
+ console.log(i, 'events checked');
104
+ }
105
+
106
+ main()
107
+ .then()
108
+ .catch(console.error);
@@ -0,0 +1,121 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import { webcrypto } from 'crypto';
3
+ // import * as moment from 'moment';
4
+ import * as mongoose from 'mongoose';
5
+
6
+ import { chevre } from '../../../../lib/index';
7
+
8
+ // const project = { id: String(process.env.PROJECT_ID) };
9
+ const PROPERTY_NAME = 'createId';
10
+
11
+ async function additionalProperty2identifier(raw: string) {
12
+ const data = new TextEncoder().encode(raw);
13
+ const hashBuffer = await webcrypto.subtle.digest('SHA-256', data);
14
+ const bytes = Array.from(new Uint8Array(hashBuffer));
15
+
16
+ // 0-9 + a-z の36文字セット
17
+ const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
18
+ // tslint:disable-next-line:no-magic-numbers
19
+ const id = bytes.map((b) => chars[b % 36])
20
+ .join('');
21
+
22
+ // tslint:disable-next-line:no-magic-numbers
23
+ return id.slice(0, 16);
24
+ }
25
+
26
+ const identifierMustMatch = /^[0-9a-zA-Z]+$/;
27
+ function validateIdentifier(identifier: string) {
28
+ if (!identifierMustMatch.test(identifier)) {
29
+ throw new Error(`not matched ${identifier}`);
30
+ }
31
+
32
+ if (identifier.length < 8 || identifier.length > 32) {
33
+ throw new Error(`invalid length ${identifier}`);
34
+ }
35
+ }
36
+
37
+ // tslint:disable-next-line:max-func-body-length
38
+ async function main() {
39
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
40
+
41
+ const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
42
+
43
+ const cursor = eventRepo.getCursor(
44
+ {
45
+ // _id: { $eq: '68f5d32176b5f6b689ff24a6' },
46
+ // 'project.id': { $eq: project.id },
47
+ // startDate: {
48
+ // $lte: moment('2025-05-01T10:00:00Z')
49
+ // .toDate()
50
+ // },
51
+ 'additionalProperty.name': { $exists: true, $eq: PROPERTY_NAME }
52
+ },
53
+ {
54
+ _id: 1,
55
+ startDate: 1,
56
+ project: 1,
57
+ identifier: 1,
58
+ additionalProperty: 1,
59
+ typeOf: 1
60
+ }
61
+ );
62
+ console.log('events found');
63
+
64
+ let i = 0;
65
+ let updateCount = 0;
66
+ await cursor.eachAsync(async (doc) => {
67
+ i += 1;
68
+ const event: Pick<
69
+ chevre.factory.event.screeningEvent.IEvent,
70
+ 'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
71
+ > = doc.toObject();
72
+
73
+ console.log(
74
+ 'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
75
+ const eventIdentifier = event.identifier;
76
+ const additionalPropertyValue = event.additionalProperty?.find(({ name }) => name === PROPERTY_NAME)?.value;
77
+ if (typeof additionalPropertyValue !== 'string') {
78
+ throw new Error('additionalPropertyValue not found');
79
+ }
80
+ const identifierMustBe = await additionalProperty2identifier(additionalPropertyValue);
81
+ validateIdentifier(identifierMustBe);
82
+
83
+ const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier.length > 0;
84
+ // const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === identifierMustBe;
85
+
86
+ if (alreadyMigrated) {
87
+ validateIdentifier(eventIdentifier);
88
+ // 追加特性から生成された識別子に一致するはず
89
+ if (identifierMustBe !== eventIdentifier) {
90
+ throw new Error(`${identifierMustBe} !== ${eventIdentifier} ${event.id}, ${i}`);
91
+ }
92
+ console.log(
93
+ 'already migrated.', event.project.id, eventIdentifier, additionalPropertyValue, event.id, event.startDate, i);
94
+ } else {
95
+ console.log(
96
+ 'updating...',
97
+ identifierMustBe, event.project.id, eventIdentifier, additionalPropertyValue, event.id, event.startDate, i);
98
+ await eventRepo.updatePartiallyById({
99
+ project: { id: event.project.id },
100
+ id: event.id,
101
+ attributes: {
102
+ typeOf: event.typeOf,
103
+ ...{
104
+ identifier: identifierMustBe
105
+ }
106
+ }
107
+ });
108
+ updateCount += 1;
109
+ console.log(
110
+ 'updated.',
111
+ event.project.id, eventIdentifier, event.id, event.startDate, i);
112
+ }
113
+ });
114
+
115
+ console.log(i, 'events checked');
116
+ console.log(updateCount, 'events updated');
117
+ }
118
+
119
+ main()
120
+ .then()
121
+ .catch(console.error);
@@ -0,0 +1,106 @@
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
+ const { EVENT_IDENTTIFIER } = process.env;
9
+
10
+ async function main() {
11
+ if (typeof EVENT_IDENTTIFIER !== 'string') {
12
+ throw new Error('environment variables required');
13
+ }
14
+
15
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
16
+
17
+ const eventSellerMakesOfferRepo = await chevre.repository.EventSellerMakesOffer.createInstance(mongoose.connection);
18
+ const availabilityEnds = moment('2025-10-26T05:20:00.000Z')
19
+ .toDate();
20
+ const availabilityStarts = moment('2025-10-23T15:00:00.000Z')
21
+ .toDate();
22
+ const validFrom = moment('2025-10-12T15:00:00.000Z')
23
+ .toDate();
24
+ const validThrough = moment('2025-10-26T05:20:00.000Z')
25
+ .toDate();
26
+ const result = await eventSellerMakesOfferRepo.updateSellerMakesOffersByEventIdentifier([
27
+ {
28
+ $set: {
29
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
30
+ identifier: EVENT_IDENTTIFIER,
31
+ offers: {
32
+ seller: {
33
+ makesOffer: [
34
+ {
35
+ typeOf: chevre.factory.offerType.Offer,
36
+ availableAtOrFrom: {
37
+ id: '3eo6okferrsdpfd9j2ce1iv9k7'
38
+ },
39
+ availabilityEnds,
40
+ availabilityStarts,
41
+ validFrom,
42
+ validThrough
43
+ },
44
+ {
45
+ typeOf: chevre.factory.offerType.Offer,
46
+ availableAtOrFrom: {
47
+ id: '51qbjcfr72h62m06vtv5kkhgje'
48
+ },
49
+ availabilityEnds,
50
+ availabilityStarts,
51
+ validFrom,
52
+ validThrough
53
+ },
54
+ {
55
+ typeOf: chevre.factory.offerType.Offer,
56
+ availableAtOrFrom: {
57
+ id: '5h3gs22mu9j3ok7o63uog9o9i3'
58
+ },
59
+ availabilityEnds,
60
+ availabilityStarts,
61
+ validFrom,
62
+ validThrough
63
+ },
64
+ {
65
+ typeOf: chevre.factory.offerType.Offer,
66
+ availableAtOrFrom: {
67
+ id: '66e7p2g713675v96nrhdm975kg'
68
+ },
69
+ availabilityEnds,
70
+ availabilityStarts,
71
+ validFrom,
72
+ validThrough
73
+ },
74
+ {
75
+ typeOf: chevre.factory.offerType.Offer,
76
+ availableAtOrFrom: {
77
+ id: '7divuoimobsfgq95tp1csorjqq'
78
+ },
79
+ availabilityEnds,
80
+ availabilityStarts,
81
+ validFrom,
82
+ validThrough
83
+ },
84
+ {
85
+ typeOf: chevre.factory.offerType.Offer,
86
+ availableAtOrFrom: {
87
+ id: 'ckevmf3fueqcunnideu6artt'
88
+ },
89
+ availabilityEnds,
90
+ availabilityStarts,
91
+ validFrom,
92
+ validThrough
93
+ }
94
+ ]
95
+ }
96
+ }
97
+ }
98
+ }
99
+ ]);
100
+ // tslint:disable-next-line:no-null-keyword
101
+ console.dir(result, { depth: null });
102
+ }
103
+
104
+ main()
105
+ .then(console.log)
106
+ .catch(console.error);
@@ -0,0 +1,49 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ // const PROJECT_ID = process.env.PROJECT_ID;
7
+ mongoose.Model.on('index', (...args) => {
8
+ console.error('******** index event emitted. ********\n', args);
9
+ });
10
+
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
15
+
16
+ try {
17
+ await offerCatalogRepo.updateManyOfferCatalogsByIds({
18
+ id: {
19
+ $in: ['xxx']
20
+ },
21
+ itemOffered: {
22
+ typeOf: {
23
+ $eq: chevre.factory.product.ProductType.EventService
24
+ }
25
+ },
26
+ $push: {
27
+ itemListElement: {
28
+ $each: [{ id: 'xxx', typeOf: chevre.factory.offerType.Offer }],
29
+ $slice: 300
30
+ }
31
+ },
32
+ $pull: {
33
+ itemListElement: {
34
+ $elemMatch: {
35
+ id: {
36
+ $in: ['xxx']
37
+ }
38
+ }
39
+ }
40
+ }
41
+ });
42
+ } catch (error) {
43
+ throw await chevre.errorHandler.handleMongoError(error);
44
+ }
45
+ }
46
+
47
+ main()
48
+ .then(console.log)
49
+ .catch(console.error);
@@ -0,0 +1,37 @@
1
+ // tslint:disable:no-implicit-dependencies no-console
2
+ import * as mongoose from 'mongoose';
3
+ import { chevre } from '../../../../lib/index';
4
+
5
+ const project = { id: String(process.env.PROJECT_ID) };
6
+
7
+ async function main() {
8
+ try {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
12
+
13
+ const limit = 10;
14
+ const page = 1;
15
+ const docs = await paymentServiceRepo.projectFields(
16
+ {
17
+ limit,
18
+ page,
19
+ project: { id: { $eq: project.id } },
20
+ availableChannel: { id: { $eq: 'xxx' } },
21
+ id: { $eq: 'xxx' }
22
+ },
23
+ ['availableChannel', 'productID']
24
+ );
25
+ // tslint:disable-next-line:no-null-keyword
26
+ console.dir(docs, { depth: null });
27
+ console.log(docs.length, 'docs found');
28
+ } catch (error) {
29
+ throw await chevre.errorHandler.handleMongoError(error);
30
+ }
31
+ }
32
+
33
+ main()
34
+ .then(() => {
35
+ console.log('success!');
36
+ })
37
+ .catch(console.error);