@chevre/domain 20.1.0-alpha.3 → 20.1.0-alpha.30

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 (97) hide show
  1. package/example/src/chevre/deleteEvents.ts +9 -1
  2. package/example/src/chevre/migrateAccountTitleAdditionalProperties.ts +157 -0
  3. package/example/src/chevre/migrateCreativeWorkAdditionalProperties.ts +116 -0
  4. package/example/src/chevre/migrateEventOffersSellerMakesOffer.ts +139 -0
  5. package/example/src/chevre/migrateEventSeriesAdditionalProperties.ts +96 -0
  6. package/example/src/chevre/migratePlaceAdditionalProperties.ts +162 -0
  7. package/example/src/chevre/migrateSSKTEventCOAEndpoint.ts +64 -0
  8. package/example/src/chevre/searchEvents.ts +36 -16
  9. package/lib/chevre/repo/accountAction.d.ts +0 -18
  10. package/lib/chevre/repo/accountAction.js +402 -355
  11. package/lib/chevre/repo/accountTitle.d.ts +1 -0
  12. package/lib/chevre/repo/accountTitle.js +6 -1
  13. package/lib/chevre/repo/additionalProperty.d.ts +35 -0
  14. package/lib/chevre/repo/additionalProperty.js +205 -0
  15. package/lib/chevre/repo/categoryCode.d.ts +1 -0
  16. package/lib/chevre/repo/categoryCode.js +15 -1
  17. package/lib/chevre/repo/creativeWork.js +10 -1
  18. package/lib/chevre/repo/customer.d.ts +1 -0
  19. package/lib/chevre/repo/customer.js +5 -0
  20. package/lib/chevre/repo/event.d.ts +9 -4
  21. package/lib/chevre/repo/event.js +69 -48
  22. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -0
  23. package/lib/chevre/repo/merchantReturnPolicy.js +5 -0
  24. package/lib/chevre/repo/mongoose/model/additionalProperty.d.ts +7 -0
  25. package/lib/chevre/repo/mongoose/model/additionalProperty.js +81 -0
  26. package/lib/chevre/repo/mongoose/model/categoryCode.js +18 -2
  27. package/lib/chevre/repo/mongoose/model/creativeWork.js +6 -0
  28. package/lib/chevre/repo/mongoose/model/event.js +53 -0
  29. package/lib/chevre/repo/mongoose/model/offer.js +7 -1
  30. package/lib/chevre/repo/mongoose/model/offerCatalog.js +21 -2
  31. package/lib/chevre/repo/mongoose/model/ownershipInfo.js +3 -15
  32. package/lib/chevre/repo/mongoose/model/place.js +42 -0
  33. package/lib/chevre/repo/offer.js +10 -1
  34. package/lib/chevre/repo/offerCatalog.js +10 -10
  35. package/lib/chevre/repo/place.d.ts +1 -0
  36. package/lib/chevre/repo/place.js +54 -7
  37. package/lib/chevre/repo/transaction.js +20 -5
  38. package/lib/chevre/repository.d.ts +6 -3
  39. package/lib/chevre/repository.js +10 -5
  40. package/lib/chevre/service/account.d.ts +0 -4
  41. package/lib/chevre/service/account.js +24 -22
  42. package/lib/chevre/service/accountTransaction/deposit.d.ts +0 -2
  43. package/lib/chevre/service/accountTransaction/deposit.js +3 -3
  44. package/lib/chevre/service/accountTransaction/transfer.d.ts +0 -2
  45. package/lib/chevre/service/accountTransaction/transfer.js +3 -3
  46. package/lib/chevre/service/accountTransaction/withdraw.d.ts +0 -2
  47. package/lib/chevre/service/accountTransaction/withdraw.js +3 -3
  48. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +11 -20
  49. package/lib/chevre/service/delivery/factory.js +2 -1
  50. package/lib/chevre/service/event.js +12 -2
  51. package/lib/chevre/service/offer/event/authorize.d.ts +4 -0
  52. package/lib/chevre/service/offer/event/authorize.js +46 -10
  53. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +0 -1
  54. package/lib/chevre/service/offer/factory.js +7 -20
  55. package/lib/chevre/service/offer.js +6 -6
  56. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +5 -3
  57. package/lib/chevre/service/order/onOrderStatusChanged.js +5 -4
  58. package/lib/chevre/service/order/placeOrder.js +17 -7
  59. package/lib/chevre/service/order/returnOrder.js +2 -1
  60. package/lib/chevre/service/order/sendOrder.js +4 -2
  61. package/lib/chevre/service/transaction/orderProgramMembership.js +6 -8
  62. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +6 -3
  63. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +9 -4
  64. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/givePointAward.js +2 -1
  65. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +2 -1
  66. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +2 -1
  67. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.js +4 -3
  68. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +4 -2
  69. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +2 -4
  70. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.d.ts +3 -1
  71. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.js +3 -2
  72. package/lib/chevre/service/transaction/placeOrderInProgress.js +16 -2
  73. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +4 -5
  74. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +6 -3
  75. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +4 -6
  76. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +2 -1
  77. package/lib/chevre/service/transaction/returnOrder.js +10 -1
  78. package/lib/chevre/service/transaction.js +1 -14
  79. package/package.json +4 -4
  80. package/example/src/chevre/accountBlanceTest.ts +0 -24
  81. package/example/src/chevre/checkOffersAppliesToMovieTicket.ts +0 -56
  82. package/example/src/chevre/createSeats.ts +0 -59
  83. package/example/src/chevre/manageOwnedByOfOwnershipInfo.ts +0 -35
  84. package/example/src/chevre/migrateEventOffersItemOfferedName.ts +0 -82
  85. package/example/src/chevre/migrateMovieTicketChargePriceSpecs.ts +0 -92
  86. package/example/src/chevre/migrateSellerMakesOffers.ts +0 -84
  87. package/example/src/chevre/migrateTTTSOldEventId.ts +0 -68
  88. package/example/src/chevre/publishConfirmationNumber.ts +0 -30
  89. package/example/src/chevre/publishServiceOutputIdentifier.ts +0 -28
  90. package/example/src/chevre/publishTransactionNumber.ts +0 -28
  91. package/example/src/chevre/renameTransaction.ts +0 -22
  92. package/lib/chevre/service/task/accountMoneyTransfer.d.ts +0 -3
  93. package/lib/chevre/service/task/accountMoneyTransfer.js +0 -31
  94. package/lib/chevre/service/task/cancelAccountMoneyTransfer.d.ts +0 -3
  95. package/lib/chevre/service/task/cancelAccountMoneyTransfer.js +0 -33
  96. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmReservation.d.ts +0 -11
  97. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmReservation.js +0 -187
@@ -1,4 +1,5 @@
1
1
  // tslint:disable:no-console
2
+ import * as moment from 'moment';
2
3
  import * as mongoose from 'mongoose';
3
4
 
4
5
  import { chevre } from '../../../lib/index';
@@ -13,7 +14,14 @@ async function main() {
13
14
  const cursor = eventRepo.getCursor(
14
15
  {
15
16
  'project.id': { $eq: project.id },
16
- typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
17
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
18
+ // 'superEvent.location.branchCode': { $eq: '118', $exists: true },
19
+ endDate: {
20
+ $exists: true,
21
+ $lt: moment()
22
+ .add(-1, 'month')
23
+ .toDate()
24
+ }
17
25
  },
18
26
  {
19
27
  // _id: 1,
@@ -0,0 +1,157 @@
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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const accountTitleRepo = new chevre.repository.AccountTitle(mongoose.connection);
15
+
16
+ const cursor = accountTitleRepo.getCursor(
17
+ {
18
+ // 'project.id': { $eq: project.id },
19
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID }
20
+ // typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
21
+ // starDate: { $gte: new Date() }
22
+ // _id: { $eq: 'al6aff83w' }
23
+ },
24
+ {
25
+ // _id: 1,
26
+ }
27
+ );
28
+ console.log('accountTitles found');
29
+
30
+ const additionalPropertyNamesOnCategories: string[] = [];
31
+ const additionalPropertyNames: string[] = [];
32
+ const additionalPropertyNamesOnTitles: string[] = [];
33
+ const projectIdsOnCategories: string[] = [];
34
+ const projectIds: string[] = [];
35
+ const projectIdsOnTitles: string[] = [];
36
+ const unexpextedprojectIdsOnCategories: string[] = [];
37
+ const unexpextedprojectIds: string[] = [];
38
+ const unexpextedprojectIdsOnTitles: string[] = [];
39
+
40
+ let i = 0;
41
+ let updateCount = 0;
42
+ // tslint:disable-next-line:max-func-body-length
43
+ await cursor.eachAsync(async (doc) => {
44
+ i += 1;
45
+ const accountTitleCategory: chevre.factory.accountTitle.IAccountTitle = doc.toObject();
46
+
47
+ const additionalPropertyNamesOnCategory = accountTitleCategory.additionalProperty?.map((p) => p.name);
48
+ console.log(
49
+ (Array.isArray(additionalPropertyNamesOnCategory)) ? additionalPropertyNamesOnCategory.length : 0,
50
+ 'additionalPropertyNamesOnCategory found',
51
+ accountTitleCategory.project.id,
52
+ accountTitleCategory.codeValue
53
+ );
54
+ if (Array.isArray(additionalPropertyNamesOnCategory) && additionalPropertyNamesOnCategory.length > 0) {
55
+ console.log(
56
+ additionalPropertyNamesOnCategory.length,
57
+ 'additionalPropertyNamesOnResource found',
58
+ accountTitleCategory.project.id,
59
+ accountTitleCategory.codeValue
60
+ );
61
+ additionalPropertyNamesOnCategories.push(...additionalPropertyNamesOnCategory);
62
+ projectIdsOnCategories.push(accountTitleCategory.project.id);
63
+ additionalPropertyNamesOnCategory.forEach((name) => {
64
+ if (!name.match(/^[a-zA-Z]*$/)) {
65
+ // throw new Error(`not matched ${creativeWork.project.id} ${creativeWork.id}`);
66
+ unexpextedprojectIdsOnCategories.push(accountTitleCategory.project.id);
67
+ }
68
+ // tslint:disable-next-line:no-magic-numbers
69
+ if (name.length < 5) {
70
+ // throw new Error(`length matched ${creativeWork.project.id} ${creativeWork.id} ${name}`);
71
+ unexpextedprojectIdsOnCategories.push(accountTitleCategory.project.id);
72
+ }
73
+ });
74
+ }
75
+
76
+ if (Array.isArray(accountTitleCategory.hasCategoryCode)) {
77
+ accountTitleCategory.hasCategoryCode.forEach((accountTitleSet) => {
78
+ const additionalPropertyNamesOnResource = accountTitleSet.additionalProperty?.map((p) => p.name);
79
+ console.log(
80
+ (Array.isArray(additionalPropertyNamesOnResource)) ? additionalPropertyNamesOnResource.length : 0,
81
+ 'additionalPropertyNamesOnResource found',
82
+ accountTitleCategory.project.id,
83
+ accountTitleCategory.codeValue
84
+ );
85
+ if (Array.isArray(additionalPropertyNamesOnResource) && additionalPropertyNamesOnResource.length > 0) {
86
+ console.log(
87
+ additionalPropertyNamesOnResource.length,
88
+ 'additionalPropertyNamesOnResource found',
89
+ accountTitleCategory.project.id,
90
+ accountTitleCategory.codeValue
91
+ );
92
+ additionalPropertyNames.push(...additionalPropertyNamesOnResource);
93
+ projectIds.push(accountTitleCategory.project.id);
94
+ additionalPropertyNamesOnResource.forEach((name) => {
95
+ if (!name.match(/^[a-zA-Z]*$/)) {
96
+ // throw new Error(`not matched ${creativeWork.project.id} ${creativeWork.id}`);
97
+ unexpextedprojectIds.push(accountTitleCategory.project.id);
98
+ }
99
+ // tslint:disable-next-line:no-magic-numbers
100
+ if (name.length < 5) {
101
+ // throw new Error(`length matched ${creativeWork.project.id} ${creativeWork.id} ${name}`);
102
+ unexpextedprojectIds.push(accountTitleCategory.project.id);
103
+ }
104
+ });
105
+ }
106
+
107
+ if (Array.isArray(accountTitleSet.hasCategoryCode)) {
108
+ accountTitleSet.hasCategoryCode.forEach((accountTitl) => {
109
+ const additionalPropertyNamesOnSection = accountTitl.additionalProperty?.map((p) => p.name);
110
+ console.log(
111
+ (Array.isArray(additionalPropertyNamesOnSection)) ? additionalPropertyNamesOnSection.length : 0,
112
+ 'additionalPropertyNamesOnSection found',
113
+ accountTitleCategory.project.id,
114
+ accountTitleCategory.codeValue
115
+ );
116
+ if (Array.isArray(additionalPropertyNamesOnSection) && additionalPropertyNamesOnSection.length > 0) {
117
+ console.log(
118
+ additionalPropertyNamesOnSection.length,
119
+ 'additionalPropertyNamesOnSection found',
120
+ accountTitleCategory.project.id,
121
+ accountTitleCategory.codeValue
122
+ );
123
+ additionalPropertyNamesOnTitles.push(...additionalPropertyNamesOnSection);
124
+ projectIdsOnTitles.push(accountTitleCategory.project.id);
125
+ additionalPropertyNamesOnSection.forEach((name) => {
126
+ if (!name.match(/^[a-zA-Z]*$/)) {
127
+ // throw new Error(`not matched ${creativeWork.project.id} ${creativeWork.id}`);
128
+ unexpextedprojectIdsOnTitles.push(accountTitleCategory.project.id);
129
+ }
130
+ // tslint:disable-next-line:no-magic-numbers
131
+ if (name.length < 5) {
132
+ // throw new Error(`length matched ${creativeWork.project.id} ${creativeWork.id} ${name}`);
133
+ unexpextedprojectIdsOnTitles.push(accountTitleCategory.project.id);
134
+ }
135
+ });
136
+ }
137
+ });
138
+ }
139
+ });
140
+ }
141
+ });
142
+ console.log(i, 'places checked');
143
+ console.log(updateCount, 'places updated');
144
+ console.log([...new Set(additionalPropertyNamesOnCategories)], 'categories');
145
+ console.log([...new Set(projectIdsOnCategories)], 'categories');
146
+ console.log([...new Set(unexpextedprojectIdsOnCategories)], 'categories');
147
+ console.log([...new Set(additionalPropertyNames)], 'sets');
148
+ console.log([...new Set(projectIds)], 'sets');
149
+ console.log([...new Set(unexpextedprojectIds)], 'sets');
150
+ console.log([...new Set(additionalPropertyNamesOnTitles)], 'titles');
151
+ console.log([...new Set(projectIdsOnTitles)], 'titles');
152
+ console.log([...new Set(unexpextedprojectIdsOnTitles)], 'titles');
153
+ }
154
+
155
+ main()
156
+ .then()
157
+ .catch(console.error);
@@ -0,0 +1,116 @@
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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ // const customerRepo = new chevre.repository.Customer(mongoose.connection);
15
+ // const sellerRepo = new chevre.repository.Seller(mongoose.connection);
16
+ // const eventRepo = new chevre.repository.Event(mongoose.connection);
17
+ // const creativeWorkRepo = new chevre.repository.CreativeWork(mongoose.connection);
18
+ // const placeRepo = new chevre.repository.Place(mongoose.connection);
19
+ // const offerRepo = new chevre.repository.Offer(mongoose.connection);
20
+ // const categoryCodeRepo = new chevre.repository.CategoryCode(mongoose.connection);
21
+ // const additionalPropertyRepo = new chevre.repository.AdditionalProperty(mongoose.connection);
22
+ // const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
23
+ const merchantReturnPolicyRepo = new chevre.repository.MerchantReturnPolicy(mongoose.connection);
24
+
25
+ // const cursor = customerRepo.getCursor(
26
+ // const cursor = sellerRepo.getCursor(
27
+ // const cursor = eventRepo.getCursor(
28
+ // const cursor = categoryCodeRepo.getCursor(
29
+ // const cursor = offerRepo.getCursor(
30
+ // const cursor = creativeWorkRepo.getCursor(
31
+ // const cursor = placeRepo.getCursor(
32
+ // const cursor = offerCatalogRepo.getCursor(
33
+ const cursor = merchantReturnPolicyRepo.getCursor(
34
+ {
35
+ // 'project.id': { $eq: project.id },
36
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
37
+ // typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
38
+ // starDate: { $gte: new Date() }
39
+ // _id: { $eq: 'al6aff83w' }
40
+ },
41
+ {
42
+ // _id: 1,
43
+ }
44
+ );
45
+ console.log('creativeWorks found');
46
+
47
+ const additionalPropertyNames: string[] = [];
48
+ const projectIds: string[] = [];
49
+ const unexpextedprojectIds: string[] = [];
50
+
51
+ let i = 0;
52
+ let updateCount = 0;
53
+ await cursor.eachAsync(async (doc) => {
54
+ i += 1;
55
+ const creativeWork: chevre.factory.creativeWork.movie.ICreativeWork = doc.toObject();
56
+
57
+ const additionalPropertyNamesOnEvent = creativeWork.additionalProperty?.map((p) => p.name);
58
+ if (Array.isArray(additionalPropertyNamesOnEvent) && additionalPropertyNamesOnEvent.length > 0) {
59
+ console.log(
60
+ additionalPropertyNamesOnEvent.length,
61
+ 'additionalPropertyNamesOnEvent found',
62
+ creativeWork.project.id,
63
+ creativeWork.id
64
+ );
65
+ additionalPropertyNames.push(...additionalPropertyNamesOnEvent);
66
+ projectIds.push(creativeWork.project.id);
67
+ additionalPropertyNamesOnEvent.forEach((name) => {
68
+ if (!name.match(/^[a-zA-Z]*$/)) {
69
+ // throw new Error(`not matched ${creativeWork.project.id} ${creativeWork.id}`);
70
+ unexpextedprojectIds.push(creativeWork.project.id);
71
+ }
72
+ // tslint:disable-next-line:no-magic-numbers
73
+ if (name.length < 5) {
74
+ // throw new Error(`length matched ${creativeWork.project.id} ${creativeWork.id} ${name}`);
75
+ unexpextedprojectIds.push(creativeWork.project.id);
76
+ }
77
+ });
78
+
79
+ // for (const additionalPropertyNameOnEvent of additionalPropertyNamesOnEvent) {
80
+ // const existings = await additionalPropertyRepo.search({
81
+ // project: { id: { $eq: event.project.id } },
82
+ // limit: 1,
83
+ // page: 1,
84
+ // name: { $regex: `^${additionalPropertyNameOnEvent}$` }
85
+ // });
86
+ // if (existings.length > 0) {
87
+ // console.log('already existed', additionalPropertyNameOnEvent, event.id, event.project.id);
88
+ // } else {
89
+ // updateCount += 1;
90
+ // await additionalPropertyRepo.save({
91
+ // attributes: {
92
+ // project: event.project,
93
+ // typeOf: 'CategoryCode',
94
+ // codeValue: additionalPropertyNameOnEvent,
95
+ // inCodeSet: {
96
+ // typeOf: 'CategoryCodeSet',
97
+ // identifier: <any>event.typeOf
98
+ // },
99
+ // name: { ja: additionalPropertyNameOnEvent }
100
+ // }
101
+ // });
102
+ // console.log('created', additionalPropertyNameOnEvent, event.id, event.project.id);
103
+ // }
104
+ // }
105
+ }
106
+ });
107
+ console.log(i, 'events checked');
108
+ console.log(updateCount, 'events updated');
109
+ console.log([...new Set(additionalPropertyNames)]);
110
+ console.log([...new Set(projectIds)]);
111
+ console.log([...new Set(unexpextedprojectIds)]);
112
+ }
113
+
114
+ main()
115
+ .then()
116
+ .catch(console.error);
@@ -0,0 +1,139 @@
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
+ const AVAILABLE_ROLE_NAMES = ['customer', 'pos'];
10
+ const POS_CLIENT_ID = process.env.POS_CLIENT_ID;
11
+ if (typeof POS_CLIENT_ID !== 'string') {
12
+ throw new Error('set POS_CLIENT_ID');
13
+ }
14
+ const MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = 93;
15
+ const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
16
+
17
+ // tslint:disable-next-line:max-func-body-length
18
+ async function main() {
19
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
20
+
21
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
22
+ const memberRepo = new chevre.repository.Member(mongoose.connection);
23
+
24
+ const cursor = eventRepo.getCursor(
25
+ {
26
+ // 'project.id': { $eq: project.id },
27
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
28
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
29
+ startDate: {
30
+ $gte: moment()
31
+ .add(-1, 'month')
32
+ .toDate()
33
+ }
34
+ // _id: { $eq: 'al6aff83w' }
35
+ },
36
+ {
37
+ // _id: 1,
38
+ }
39
+ );
40
+ console.log('events found');
41
+
42
+ let i = 0;
43
+ let updateCount = 0;
44
+ await cursor.eachAsync(async (doc) => {
45
+ i += 1;
46
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
47
+
48
+ // IAMメンバー検索
49
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
50
+ if (eventOffers === undefined) {
51
+ throw new Error('event.offers undefined');
52
+ }
53
+
54
+ const makesOfferFromEvent = eventOffers.seller.makesOffer;
55
+
56
+ const alreadyMigrated = Array.isArray(makesOfferFromEvent)
57
+ && makesOfferFromEvent.length > 0
58
+ && makesOfferFromEvent.every((offer) => {
59
+ return offer.availabilityEnds instanceof Date
60
+ && offer.availabilityStarts instanceof Date
61
+ && offer.validFrom instanceof Date
62
+ && offer.validThrough instanceof Date
63
+ && Array.isArray(offer.availableAtOrFrom)
64
+ && offer.availableAtOrFrom.length === 1;
65
+ });
66
+
67
+ if (alreadyMigrated) {
68
+ console.log(
69
+ 'already exist...', event.project.id, event.id, event.startDate, makesOfferFromEvent.length, i);
70
+ } else {
71
+ let existingApplicationMembers = await memberRepo.search({
72
+ limit: 100,
73
+ page: 1,
74
+ project: { id: { $eq: event.project.id } },
75
+ member: { typeOf: { $eq: chevre.factory.creativeWorkType.WebApplication } }
76
+ });
77
+ // ロールで絞る(customer or pos)
78
+ existingApplicationMembers = existingApplicationMembers
79
+ .filter((m) => {
80
+ return Array.isArray(m.member.hasRole) && m.member.hasRole.some((r) => AVAILABLE_ROLE_NAMES.includes(r.roleName));
81
+ });
82
+ console.log(
83
+ existingApplicationMembers.length,
84
+ 'existingApplicationMembers found.',
85
+ event.project.id,
86
+ existingApplicationMembers.map((m) => m.member.name)
87
+ .join(',')
88
+ );
89
+ const newMakesOffer: chevre.factory.event.screeningEvent.ISellerMakesOffer[] = existingApplicationMembers.map((a) => {
90
+ // posについては有効期間調整
91
+ if (a.member.id === POS_CLIENT_ID) {
92
+ const validFrom4pos: Date = moment(event.startDate)
93
+ .add(-MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS, 'days')
94
+ .toDate();
95
+ const validThrough4pos: Date = moment(event.endDate)
96
+ .add(1, 'month')
97
+ .toDate();
98
+
99
+ return {
100
+ typeOf: chevre.factory.offerType.Offer,
101
+ availableAtOrFrom: [{ id: a.member.id }],
102
+ availabilityEnds: validThrough4pos, // 1 month later from endDate
103
+ availabilityStarts: validFrom4pos, // startのMAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS前
104
+ validFrom: validFrom4pos, // startのMAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS前
105
+ validThrough: validThrough4pos // 1 month later from endDate
106
+ };
107
+ } else {
108
+ return {
109
+ typeOf: chevre.factory.offerType.Offer,
110
+ availableAtOrFrom: [{ id: a.member.id }],
111
+ availabilityEnds: eventOffers.availabilityEnds,
112
+ availabilityStarts: eventOffers.availabilityStarts,
113
+ validFrom: eventOffers.validFrom,
114
+ validThrough: eventOffers.validThrough
115
+ };
116
+ }
117
+ });
118
+ console.log(
119
+ 'updating seller...', event.project.id, event.id, event.startDate, newMakesOffer.length, i);
120
+ await eventRepo.updatePartiallyById({
121
+ id: event.id,
122
+ attributes: <any>{
123
+ typeOf: event.typeOf,
124
+ 'offers.seller.makesOffer': newMakesOffer
125
+ }
126
+ });
127
+ updateCount += 1;
128
+ console.log(
129
+ 'updated...', event.project.id, event.id, event.startDate, newMakesOffer.length, i);
130
+ }
131
+ });
132
+
133
+ console.log(i, 'events checked');
134
+ console.log(updateCount, 'events updated');
135
+ }
136
+
137
+ main()
138
+ .then()
139
+ .catch(console.error);
@@ -0,0 +1,96 @@
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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
13
+
14
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
15
+ const additionalPropertyRepo = new chevre.repository.AdditionalProperty(mongoose.connection);
16
+
17
+ const cursor = eventRepo.getCursor(
18
+ {
19
+ // 'project.id': { $eq: project.id },
20
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
21
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries }
22
+ // typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
23
+ // startDate: {
24
+ // $gte: moment()
25
+ // .add(-1, 'month')
26
+ // .toDate()
27
+ // }
28
+ // _id: { $eq: 'al6aff83w' }
29
+ },
30
+ {
31
+ // _id: 1,
32
+ }
33
+ );
34
+ console.log('events found');
35
+
36
+ const additionalPropertyNames: string[] = [];
37
+ const projectIds: string[] = [];
38
+
39
+ let i = 0;
40
+ let updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ i += 1;
43
+ const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
44
+
45
+ const additionalPropertyNamesOnEvent = event.additionalProperty?.map((p) => p.name);
46
+ if (Array.isArray(additionalPropertyNamesOnEvent) && additionalPropertyNamesOnEvent.length > 0) {
47
+ console.log(additionalPropertyNamesOnEvent.length, 'additionalPropertyNamesOnEvent found', event.project.id);
48
+ additionalPropertyNames.push(...additionalPropertyNamesOnEvent);
49
+ projectIds.push(event.project.id);
50
+ additionalPropertyNamesOnEvent.forEach((name) => {
51
+ if (!name.match(/^[a-zA-Z]*$/)) {
52
+ throw new Error(`not matched ${event.project.id} ${event.id}`);
53
+ }
54
+ // tslint:disable-next-line:no-magic-numbers
55
+ if (name.length < 8) {
56
+ throw new Error(`length matched ${event.project.id} ${event.id} ${name}`);
57
+ }
58
+ });
59
+
60
+ for (const additionalPropertyNameOnEvent of additionalPropertyNamesOnEvent) {
61
+ const existings = await additionalPropertyRepo.search({
62
+ project: { id: { $eq: event.project.id } },
63
+ limit: 1,
64
+ page: 1,
65
+ name: { $regex: `^${additionalPropertyNameOnEvent}$` }
66
+ });
67
+ if (existings.length > 0) {
68
+ console.log('already existed', additionalPropertyNameOnEvent, event.id, event.project.id);
69
+ } else {
70
+ updateCount += 1;
71
+ await additionalPropertyRepo.save({
72
+ attributes: {
73
+ project: event.project,
74
+ typeOf: 'CategoryCode',
75
+ codeValue: additionalPropertyNameOnEvent,
76
+ inCodeSet: {
77
+ typeOf: 'CategoryCodeSet',
78
+ identifier: <any>event.typeOf
79
+ },
80
+ name: { ja: additionalPropertyNameOnEvent }
81
+ }
82
+ });
83
+ console.log('created', additionalPropertyNameOnEvent, event.id, event.project.id);
84
+ }
85
+ }
86
+ }
87
+ });
88
+ console.log(i, 'events checked');
89
+ console.log(updateCount, 'events updated');
90
+ console.log([...new Set(additionalPropertyNames)]);
91
+ console.log([...new Set(projectIds)]);
92
+ }
93
+
94
+ main()
95
+ .then()
96
+ .catch(console.error);