@chevre/domain 20.2.0-alpha.1 → 20.2.0-alpha.2

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.
@@ -0,0 +1,80 @@
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 POS_CLIENT_ID = process.env.POS_CLIENT_ID;
10
+ if (typeof POS_CLIENT_ID !== 'string') {
11
+ throw new Error('set POS_CLIENT_ID');
12
+ }
13
+ const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
14
+
15
+ // tslint:disable-next-line:max-func-body-length
16
+ async function main() {
17
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
18
+
19
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
20
+
21
+ const cursor = eventRepo.getCursor(
22
+ {
23
+ // 'project.id': { $eq: project.id },
24
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
25
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
26
+ startDate: {
27
+ $gte: moment()
28
+ .add(-1, 'month')
29
+ .toDate()
30
+ }
31
+ // _id: { $eq: 'al6aff83w' }
32
+ },
33
+ {
34
+ // _id: 1,
35
+ }
36
+ );
37
+ console.log('events found');
38
+
39
+ let i = 0;
40
+ let updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ i += 1;
43
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
44
+
45
+ // IAMメンバー検索
46
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
47
+ if (eventOffers === undefined) {
48
+ throw new Error('event.offers undefined');
49
+ }
50
+
51
+ const itemOfferedTypeOf = eventOffers.itemOffered.typeOf;
52
+
53
+ const alreadyMigrated = itemOfferedTypeOf === chevre.factory.product.ProductType.EventService;
54
+
55
+ if (alreadyMigrated) {
56
+ console.log(
57
+ 'already exist...', event.project.id, event.id, event.startDate, itemOfferedTypeOf, i);
58
+ } else {
59
+ console.log(
60
+ 'updating seller...', event.project.id, event.id, event.startDate, i);
61
+ await eventRepo.updatePartiallyById({
62
+ id: event.id,
63
+ attributes: <any>{
64
+ typeOf: event.typeOf,
65
+ 'offers.itemOffered.typeOf': chevre.factory.product.ProductType.EventService
66
+ }
67
+ });
68
+ updateCount += 1;
69
+ console.log(
70
+ 'updated...', event.project.id, event.id, event.startDate, i);
71
+ }
72
+ });
73
+
74
+ console.log(i, 'events checked');
75
+ console.log(updateCount, 'events updated');
76
+ }
77
+
78
+ main()
79
+ .then()
80
+ .catch(console.error);
@@ -389,8 +389,11 @@ function createReservation(params) {
389
389
  typeOf: 'CategoryCode'
390
390
  }
391
391
  : undefined;
392
+ const availableChannel = eventOffers.itemOffered.availableChannel;
392
393
  if (params.reservationFor.typeOf === factory.eventType.ScreeningEvent) {
393
- const issuedThrough = Object.assign(Object.assign({ typeOf: factory.product.ProductType.EventService }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined), (typeof eventOffers.itemOffered.id === 'string') ? { id: eventOffers.itemOffered.id } : undefined);
394
+ const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.EventService,
395
+ // 興行IDを追加(2022-09-08~)
396
+ id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
394
397
  return Object.assign(Object.assign(Object.assign(Object.assign({ project: params.project, typeOf: factory.reservationType.EventReservation, id: params.id, issuedThrough, additionalProperty: params.additionalProperty, bookingTime: params.reserveDate, modifiedTime: params.reserveDate, numSeats: 1, price: price4reservation, priceCurrency: factory.priceCurrency.JPY, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, reservedTicket: params.reservedTicket,
395
398
  // 最適化(2022-12-19~)
396
399
  underName: {
@@ -412,7 +415,9 @@ function createReservation(params) {
412
415
  : undefined);
413
416
  }
414
417
  else {
415
- const issuedThrough = Object.assign(Object.assign({ typeOf: factory.product.ProductType.Transportation }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined), (typeof eventOffers.itemOffered.id === 'string') ? { id: eventOffers.itemOffered.id } : undefined);
418
+ const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.Transportation,
419
+ // 興行IDを追加(2022-09-08~)
420
+ id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
416
421
  return Object.assign(Object.assign(Object.assign(Object.assign({ project: params.project, typeOf: factory.reservationType.BusReservation, id: params.id, issuedThrough, additionalProperty: params.additionalProperty, bookingTime: params.reserveDate, modifiedTime: params.reserveDate, numSeats: 1, price: price4reservation, priceCurrency: factory.priceCurrency.JPY, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, reservedTicket: params.reservedTicket, underName: {
417
422
  typeOf: params.agent.typeOf,
418
423
  name: params.agent.name
@@ -172,7 +172,25 @@ function responseBody2acceptedOffers4result(params) {
172
172
  };
173
173
  const additionalProperty = (_c = (_b = requestedOffer.itemOffered) === null || _b === void 0 ? void 0 : _b.serviceOutput) === null || _c === void 0 ? void 0 : _c.additionalProperty;
174
174
  const additionalTicketText = (_e = (_d = requestedOffer.itemOffered) === null || _d === void 0 ? void 0 : _d.serviceOutput) === null || _e === void 0 ? void 0 : _e.additionalTicketText;
175
- const reservation = Object.assign(Object.assign(Object.assign({ project: { typeOf: event.project.typeOf, id: event.project.id }, typeOf: factory.reservationType.EventReservation, id: reservationId, issuedThrough: { typeOf: factory.product.ProductType.EventService }, bookingTime: params.bookingTime }, (Array.isArray(additionalProperty)) ? { additionalProperty } : undefined), (typeof additionalTicketText === 'string') ? { additionalTicketText } : undefined), {
175
+ const issuedThrough = {
176
+ typeOf: factory.product.ProductType.EventService,
177
+ id: '',
178
+ availableChannel: {
179
+ typeOf: 'ServiceChannel',
180
+ serviceLocation: {
181
+ typeOf: reservationFor.location.typeOf,
182
+ branchCode: reservationFor.location.branchCode,
183
+ name: reservationFor.location.name,
184
+ containedInPlace: {
185
+ typeOf: reservationFor.superEvent.location.typeOf,
186
+ id: reservationFor.superEvent.location.id,
187
+ branchCode: reservationFor.superEvent.location.branchCode,
188
+ name: reservationFor.superEvent.location.name
189
+ }
190
+ }
191
+ }
192
+ };
193
+ const reservation = Object.assign(Object.assign(Object.assign({ project: { typeOf: event.project.typeOf, id: event.project.id }, typeOf: factory.reservationType.EventReservation, id: reservationId, issuedThrough, bookingTime: params.bookingTime }, (Array.isArray(additionalProperty)) ? { additionalProperty } : undefined), (typeof additionalTicketText === 'string') ? { additionalTicketText } : undefined), {
176
194
  // numSeats: 1, // 廃止(2022-08-18~)
177
195
  reservationFor: reservationFor, reservationNumber: reservationNumber, reservedTicket: reservedTicket });
178
196
  if (requestedOffer.priceSpecification === undefined) {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.281.0-alpha.1",
12
+ "@chevre/factory": "4.281.0-alpha.2",
13
13
  "@cinerino/sdk": "3.135.0-alpha.6",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.1"
123
+ "version": "20.2.0-alpha.2"
124
124
  }
@@ -1,139 +0,0 @@
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);