@chevre/domain 20.2.0-alpha.2 → 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);
@@ -5,11 +5,6 @@ import * as mongoose from 'mongoose';
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
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
8
  const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
14
9
 
15
10
  // tslint:disable-next-line:max-func-body-length
@@ -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: {
package/package.json CHANGED
@@ -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.2"
123
+ "version": "20.2.0-alpha.3"
124
124
  }
@@ -1,57 +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
- 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
-
16
- const cursor = eventRepo.getCursor(
17
- {
18
- // 'project.id': { $eq: project.id },
19
- 'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
- typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
21
- // typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
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.screeningEventSeries.IEvent = doc.toObject();
40
-
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);
44
- } else {
45
- 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);
49
- }
50
- });
51
- console.log(i, 'events checked');
52
- console.log(updateCount, 'events updated');
53
- }
54
-
55
- main()
56
- .then()
57
- .catch(console.error);