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

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,89 @@
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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
10
+
11
+ // tslint:disable-next-line:max-func-body-length
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
14
+
15
+ const eventRepo = new chevre.repository.Event(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.ScreeningEvent },
22
+ startDate: {
23
+ $gte: moment()
24
+ .add(-1, 'month')
25
+ .toDate()
26
+ }
27
+ // _id: { $eq: 'al6aff83w' }
28
+ },
29
+ {
30
+ // _id: 1,
31
+ }
32
+ );
33
+ console.log('events found');
34
+
35
+ let i = 0;
36
+ let updateCount = 0;
37
+ await cursor.eachAsync(async (doc) => {
38
+ i += 1;
39
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
40
+
41
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
42
+ if (eventOffers === undefined) {
43
+ throw new Error('event.offers undefined');
44
+ }
45
+
46
+ const availableChannel = eventOffers.itemOffered.availableChannel;
47
+
48
+ const alreadyMigrated = availableChannel?.typeOf === 'ServiceChannel';
49
+
50
+ if (alreadyMigrated) {
51
+ console.log(
52
+ 'already exist...', event.project.id, event.id, event.startDate, availableChannel.serviceLocation.branchCode, i);
53
+ } else {
54
+ const newAvailableChannel: chevre.factory.reservation.IServiceChannel = {
55
+ typeOf: 'ServiceChannel',
56
+ serviceLocation: {
57
+ typeOf: event.location.typeOf,
58
+ branchCode: event.location.branchCode,
59
+ name: event.location.name,
60
+ containedInPlace: {
61
+ typeOf: event.superEvent.location.typeOf,
62
+ id: event.superEvent.location.id,
63
+ branchCode: event.superEvent.location.branchCode,
64
+ name: event.superEvent.location.name
65
+ }
66
+ }
67
+ };
68
+ console.log(
69
+ 'updating seller...', event.project.id, event.id, event.startDate, newAvailableChannel.serviceLocation.branchCode, i);
70
+ await eventRepo.updatePartiallyById({
71
+ id: event.id,
72
+ attributes: <any>{
73
+ typeOf: event.typeOf,
74
+ 'offers.itemOffered.availableChannel': newAvailableChannel
75
+ }
76
+ });
77
+ updateCount += 1;
78
+ console.log(
79
+ 'updated...', event.project.id, event.id, event.startDate, i);
80
+ }
81
+ });
82
+
83
+ console.log(i, 'events checked');
84
+ console.log(updateCount, 'events updated');
85
+ }
86
+
87
+ main()
88
+ .then()
89
+ .catch(console.error);
@@ -18,7 +18,6 @@ async function main() {
18
18
  // 'project.id': { $eq: project.id },
19
19
  'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
20
  typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
21
- // typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
22
21
  startDate: {
23
22
  $gte: moment()
24
23
  .add(-1, 'month')
@@ -36,18 +35,37 @@ async function main() {
36
35
  let updateCount = 0;
37
36
  await cursor.eachAsync(async (doc) => {
38
37
  i += 1;
39
- const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
38
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
40
39
 
41
- const locationProjectId = (<any>event.location).project?.id;
42
- if (typeof locationProjectId !== 'string') {
43
- console.log('already deleted', event.id, event.startDate, event.project.id, i);
40
+ // IAMメンバー検索
41
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
42
+ if (eventOffers === undefined) {
43
+ throw new Error('event.offers undefined');
44
+ }
45
+
46
+ const itemOfferedTypeOf = eventOffers.itemOffered.typeOf;
47
+
48
+ const alreadyMigrated = itemOfferedTypeOf === chevre.factory.product.ProductType.EventService;
49
+
50
+ if (alreadyMigrated) {
51
+ console.log(
52
+ 'already exist...', event.project.id, event.id, event.startDate, itemOfferedTypeOf, i);
44
53
  } else {
54
+ console.log(
55
+ 'updating seller...', event.project.id, event.id, event.startDate, i);
56
+ await eventRepo.updatePartiallyById({
57
+ id: event.id,
58
+ attributes: <any>{
59
+ typeOf: event.typeOf,
60
+ 'offers.itemOffered.typeOf': chevre.factory.product.ProductType.EventService
61
+ }
62
+ });
45
63
  updateCount += 1;
46
- console.log('deleting project...', event.id, event.startDate, event.project.id, i);
47
- await eventRepo.deleteUnnecessaryProjectAttributesById({ id: event.id });
48
- console.log('project deleted', event.id, event.startDate, event.project.id, i);
64
+ console.log(
65
+ 'updated...', event.project.id, event.id, event.startDate, i);
49
66
  }
50
67
  });
68
+
51
69
  console.log(i, 'events checked');
52
70
  console.log(updateCount, 'events updated');
53
71
  }
@@ -38,9 +38,7 @@ class MongoRepository {
38
38
  const andConditions = [{ typeOf: { $eq: factory.placeType.MovieTheater } }];
39
39
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
40
40
  if (typeof projectIdEq === 'string') {
41
- andConditions.push({
42
- 'project.id': { $eq: projectIdEq }
43
- });
41
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
44
42
  }
45
43
  const branchCodeEq = (_c = params.branchCode) === null || _c === void 0 ? void 0 : _c.$eq;
46
44
  if (typeof branchCodeEq === 'string') {
@@ -435,22 +433,17 @@ class MongoRepository {
435
433
  }
436
434
  // tslint:disable-next-line:max-func-body-length
437
435
  searchScreeningRoomSections(searchConditions) {
438
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
436
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
439
437
  return __awaiter(this, void 0, void 0, function* () {
440
- const matchStages = [];
441
- if (searchConditions.project !== undefined) {
442
- if (searchConditions.project.id !== undefined) {
443
- if (typeof searchConditions.project.id.$eq === 'string') {
444
- matchStages.push({
445
- $match: {
446
- 'project.id': { $eq: searchConditions.project.id.$eq }
447
- }
448
- });
449
- }
450
- }
438
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
439
+ const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
440
+ if (typeof projectIdEq === 'string') {
441
+ matchStages.push({
442
+ $match: { 'project.id': { $eq: projectIdEq } }
443
+ });
451
444
  }
452
445
  // 施設コード
453
- const movieTheaterBranchCodeEq = (_c = (_b = (_a = searchConditions.containedInPlace) === null || _a === void 0 ? void 0 : _a.containedInPlace) === null || _b === void 0 ? void 0 : _b.branchCode) === null || _c === void 0 ? void 0 : _c.$eq;
446
+ const movieTheaterBranchCodeEq = (_e = (_d = (_c = searchConditions.containedInPlace) === null || _c === void 0 ? void 0 : _c.containedInPlace) === null || _d === void 0 ? void 0 : _d.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
454
447
  if (typeof movieTheaterBranchCodeEq === 'string') {
455
448
  matchStages.push({
456
449
  $match: {
@@ -462,7 +455,7 @@ class MongoRepository {
462
455
  });
463
456
  }
464
457
  // スクリーンコード
465
- const containedInPlaceBranchCodeEq = (_e = (_d = searchConditions.containedInPlace) === null || _d === void 0 ? void 0 : _d.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
458
+ const containedInPlaceBranchCodeEq = (_g = (_f = searchConditions.containedInPlace) === null || _f === void 0 ? void 0 : _f.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
466
459
  if (typeof containedInPlaceBranchCodeEq === 'string') {
467
460
  matchStages.push({
468
461
  $match: {
@@ -474,7 +467,7 @@ class MongoRepository {
474
467
  });
475
468
  }
476
469
  // セクションコード
477
- const sectionBranchCodeEq = (_f = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _f === void 0 ? void 0 : _f.$eq;
470
+ const sectionBranchCodeEq = (_h = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
478
471
  if (typeof sectionBranchCodeEq === 'string') {
479
472
  matchStages.push({
480
473
  $match: {
@@ -485,7 +478,7 @@ class MongoRepository {
485
478
  }
486
479
  });
487
480
  }
488
- const nameCodeRegex = (_g = searchConditions.name) === null || _g === void 0 ? void 0 : _g.$regex;
481
+ const nameCodeRegex = (_j = searchConditions.name) === null || _j === void 0 ? void 0 : _j.$regex;
489
482
  if (typeof nameCodeRegex === 'string') {
490
483
  matchStages.push({
491
484
  $match: {
@@ -506,7 +499,7 @@ class MongoRepository {
506
499
  }
507
500
  });
508
501
  }
509
- const branchCodeRegex = (_h = searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$regex;
502
+ const branchCodeRegex = (_k = searchConditions.branchCode) === null || _k === void 0 ? void 0 : _k.$regex;
510
503
  if (typeof branchCodeRegex === 'string') {
511
504
  matchStages.push({
512
505
  $match: {
@@ -517,7 +510,7 @@ class MongoRepository {
517
510
  }
518
511
  });
519
512
  }
520
- const additionalPropertyElemMatch = (_j = searchConditions.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
513
+ const additionalPropertyElemMatch = (_l = searchConditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
521
514
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
522
515
  matchStages.push({
523
516
  $match: {
@@ -543,7 +536,7 @@ class MongoRepository {
543
536
  branchCode: '$branchCode',
544
537
  name: '$name'
545
538
  }
546
- }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_k = searchConditions.$projection) === null || _k === void 0 ? void 0 : _k.seatCount) === 1)
539
+ }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.seatCount) === 1)
547
540
  ? {
548
541
  seatCount: {
549
542
  $cond: {
@@ -595,7 +588,7 @@ class MongoRepository {
595
588
  searchScreeningRooms(searchConditions) {
596
589
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
597
590
  return __awaiter(this, void 0, void 0, function* () {
598
- const matchStages = [];
591
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
599
592
  const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
600
593
  if (typeof projectIdEq === 'string') {
601
594
  matchStages.push({
@@ -855,21 +848,16 @@ class MongoRepository {
855
848
  }
856
849
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
857
850
  searchSeats(params) {
858
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
851
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
859
852
  return __awaiter(this, void 0, void 0, function* () {
860
- const matchStages = [];
861
- if (params.project !== undefined) {
862
- if (params.project.id !== undefined) {
863
- if (typeof params.project.id.$eq === 'string') {
864
- matchStages.push({
865
- $match: {
866
- 'project.id': { $eq: params.project.id.$eq }
867
- }
868
- });
869
- }
870
- }
853
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
854
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
855
+ if (typeof projectIdEq === 'string') {
856
+ matchStages.push({
857
+ $match: { 'project.id': { $eq: projectIdEq } }
858
+ });
871
859
  }
872
- const containedInPlaceBranchCodeEq = (_b = (_a = params.containedInPlace) === null || _a === void 0 ? void 0 : _a.branchCode) === null || _b === void 0 ? void 0 : _b.$eq;
860
+ const containedInPlaceBranchCodeEq = (_d = (_c = params.containedInPlace) === null || _c === void 0 ? void 0 : _c.branchCode) === null || _d === void 0 ? void 0 : _d.$eq;
873
861
  if (typeof containedInPlaceBranchCodeEq === 'string') {
874
862
  matchStages.push({
875
863
  $match: {
@@ -880,7 +868,7 @@ class MongoRepository {
880
868
  }
881
869
  });
882
870
  }
883
- const containedInPlaceBranchCodeIn = (_d = (_c = params.containedInPlace) === null || _c === void 0 ? void 0 : _c.branchCode) === null || _d === void 0 ? void 0 : _d.$in;
871
+ const containedInPlaceBranchCodeIn = (_f = (_e = params.containedInPlace) === null || _e === void 0 ? void 0 : _e.branchCode) === null || _f === void 0 ? void 0 : _f.$in;
884
872
  if (Array.isArray(containedInPlaceBranchCodeIn)) {
885
873
  matchStages.push({
886
874
  $match: {
@@ -934,7 +922,7 @@ class MongoRepository {
934
922
  });
935
923
  }
936
924
  }
937
- const branchCodeIn = (_e = params.branchCode) === null || _e === void 0 ? void 0 : _e.$in;
925
+ const branchCodeIn = (_g = params.branchCode) === null || _g === void 0 ? void 0 : _g.$in;
938
926
  if (Array.isArray(branchCodeIn)) {
939
927
  matchStages.push({
940
928
  $match: {
@@ -945,7 +933,7 @@ class MongoRepository {
945
933
  }
946
934
  });
947
935
  }
948
- const branchCodeRegex = (_f = params.branchCode) === null || _f === void 0 ? void 0 : _f.$regex;
936
+ const branchCodeRegex = (_h = params.branchCode) === null || _h === void 0 ? void 0 : _h.$regex;
949
937
  if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
950
938
  matchStages.push({
951
939
  $match: {
@@ -956,7 +944,7 @@ class MongoRepository {
956
944
  }
957
945
  });
958
946
  }
959
- const nameRegex = (_g = params.name) === null || _g === void 0 ? void 0 : _g.$regex;
947
+ const nameRegex = (_j = params.name) === null || _j === void 0 ? void 0 : _j.$regex;
960
948
  if (typeof nameRegex === 'string' && nameRegex.length > 0) {
961
949
  matchStages.push({
962
950
  $match: {
@@ -977,7 +965,7 @@ class MongoRepository {
977
965
  }
978
966
  });
979
967
  }
980
- const seatingTypeEq = (_h = params.seatingType) === null || _h === void 0 ? void 0 : _h.$eq;
968
+ const seatingTypeEq = (_k = params.seatingType) === null || _k === void 0 ? void 0 : _k.$eq;
981
969
  if (typeof seatingTypeEq === 'string') {
982
970
  matchStages.push({
983
971
  $match: {
@@ -993,7 +981,7 @@ class MongoRepository {
993
981
  && params.$projection['containedInPlace.containedInPlace'] === 0) {
994
982
  includeScreeningRooms = false;
995
983
  }
996
- const additionalPropertyElemMatch = (_j = params.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
984
+ const additionalPropertyElemMatch = (_l = params.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
997
985
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
998
986
  matchStages.push({
999
987
  $match: {
@@ -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.3"
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);