@chevre/domain 21.4.0-alpha.6 → 21.4.0-alpha.7

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.
@@ -5,7 +5,7 @@ import * as mongoose from 'mongoose';
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
7
  async function main() {
8
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
9
 
10
10
  const actionRepo = new chevre.repository.Action(mongoose.connection);
11
11
 
@@ -0,0 +1,105 @@
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: true });
13
+
14
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
15
+ const placeRepo = new chevre.repository.Place(mongoose.connection);
16
+
17
+ const cursor = eventRepo.getCursor(
18
+ {
19
+ // 'project.id': { $eq: project.id },
20
+ // 'project.id': { $ne: EXCLUDED_PROJECT_ID },
21
+ typeOf: {
22
+ $in: [
23
+ chevre.factory.eventType.ScreeningEvent,
24
+ chevre.factory.eventType.ScreeningEventSeries
25
+ ]
26
+ }
27
+ // startDate: {
28
+ // $gte: moment()
29
+ // // tslint:disable-next-line:no-magic-numbers
30
+ // .add(-6, 'months')
31
+ // .toDate()
32
+ // }
33
+ },
34
+ {
35
+ _id: 1,
36
+ project: 1,
37
+ location: 1,
38
+ superEvent: 1,
39
+ startDate: 1,
40
+ typeOf: 1,
41
+ organizer: 1
42
+ }
43
+ );
44
+ console.log('events found');
45
+
46
+ let i = 0;
47
+ let updateCount = 0;
48
+ await cursor.eachAsync(async (doc) => {
49
+ i += 1;
50
+ const event: chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEvent
51
+ | chevre.factory.eventType.ScreeningEventSeries> = doc.toObject();
52
+
53
+ const organizerId = event.organizer?.id;
54
+
55
+ const alreadyMigrated = typeof organizerId === 'string';
56
+
57
+ if (alreadyMigrated) {
58
+ console.log('already exist...', event.project.id, event.id, event.startDate, organizerId, i);
59
+ } else {
60
+ let movieTheaterId: string;
61
+ if (event.typeOf === chevre.factory.eventType.ScreeningEventSeries) {
62
+ movieTheaterId = event.location.id;
63
+ } else {
64
+ movieTheaterId = event.superEvent.location.id;
65
+ }
66
+ const movieTheaters = <Pick<chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom, 'parentOrganization'>[]>
67
+ await placeRepo.searchMovieTheaters(
68
+ {
69
+ limit: 1,
70
+ page: 1,
71
+ project: { id: { $eq: event.project.id } },
72
+ id: { $eq: movieTheaterId }
73
+ },
74
+ ['parentOrganization'],
75
+ []
76
+ );
77
+ const movieTheater = movieTheaters.shift();
78
+ const sellerId = movieTheater?.parentOrganization?.id;
79
+ console.log('movieTheater found', event.project.id, event.id, event.startDate, 'sellerId:', sellerId, i);
80
+ if (typeof sellerId !== 'string') {
81
+ throw new Error('movieTheater not found');
82
+ }
83
+ const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
84
+ id: sellerId
85
+ };
86
+ console.log('updating event...', event.project.id, event.id, event.startDate, i);
87
+ await eventRepo.updatePartiallyById({
88
+ id: event.id,
89
+ attributes: <any>{
90
+ typeOf: event.typeOf,
91
+ organizer: newOrganizer
92
+ }
93
+ });
94
+ updateCount += 1;
95
+ console.log('updated.', event.project.id, event.id, event.startDate, i);
96
+ }
97
+ });
98
+
99
+ console.log(i, 'events checked');
100
+ console.log(updateCount, 'events updated');
101
+ }
102
+
103
+ main()
104
+ .then()
105
+ .catch(console.error);
@@ -25,7 +25,7 @@
25
25
  import { Schema } from 'mongoose';
26
26
  declare const modelName = "Event";
27
27
  /**
28
- * イベント(公演など)スキーマ
28
+ * イベントスキーマ
29
29
  */
30
30
  declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
31
31
  collection: string;
@@ -53,11 +53,12 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
53
53
  };
54
54
  }, {
55
55
  typeOf: string;
56
+ project: any;
56
57
  checkInCount: number;
57
58
  attendeeCount: number;
59
+ organizer: any;
58
60
  _id?: string | undefined;
59
61
  name?: any;
60
- project?: any;
61
62
  alternateName?: any;
62
63
  description?: any;
63
64
  additionalProperty?: any;
@@ -77,7 +78,6 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
77
78
  aggregateEntranceGate?: any;
78
79
  aggregateReservation?: any;
79
80
  aggregateOffer?: any;
80
- organizer?: any;
81
81
  maximumAttendeeCapacity?: number | undefined;
82
82
  remainingAttendeeCapacity?: number | undefined;
83
83
  videoFormat?: any;
@@ -87,11 +87,12 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
87
87
  kanaName?: string | undefined;
88
88
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
89
89
  typeOf: string;
90
+ project: any;
90
91
  checkInCount: number;
91
92
  attendeeCount: number;
93
+ organizer: any;
92
94
  _id?: string | undefined;
93
95
  name?: any;
94
- project?: any;
95
96
  alternateName?: any;
96
97
  description?: any;
97
98
  additionalProperty?: any;
@@ -111,7 +112,6 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
111
112
  aggregateEntranceGate?: any;
112
113
  aggregateReservation?: any;
113
114
  aggregateOffer?: any;
114
- organizer?: any;
115
115
  maximumAttendeeCapacity?: number | undefined;
116
116
  remainingAttendeeCapacity?: number | undefined;
117
117
  videoFormat?: any;
@@ -121,11 +121,12 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
121
121
  kanaName?: string | undefined;
122
122
  }>> & Omit<import("mongoose").FlatRecord<{
123
123
  typeOf: string;
124
+ project: any;
124
125
  checkInCount: number;
125
126
  attendeeCount: number;
127
+ organizer: any;
126
128
  _id?: string | undefined;
127
129
  name?: any;
128
- project?: any;
129
130
  alternateName?: any;
130
131
  description?: any;
131
132
  additionalProperty?: any;
@@ -145,7 +146,6 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
145
146
  aggregateEntranceGate?: any;
146
147
  aggregateReservation?: any;
147
148
  aggregateOffer?: any;
148
- organizer?: any;
149
149
  maximumAttendeeCapacity?: number | undefined;
150
150
  remainingAttendeeCapacity?: number | undefined;
151
151
  videoFormat?: any;
@@ -7,10 +7,17 @@ const factory = require("../../../factory");
7
7
  const modelName = 'Event';
8
8
  exports.modelName = modelName;
9
9
  /**
10
- * イベント(公演など)スキーマ
10
+ * イベントスキーマ
11
11
  */
12
12
  const schema = new mongoose_1.Schema({
13
- project: mongoose_1.SchemaTypes.Mixed,
13
+ project: {
14
+ type: mongoose_1.SchemaTypes.Mixed,
15
+ required: true
16
+ },
17
+ organizer: {
18
+ type: mongoose_1.SchemaTypes.Mixed,
19
+ required: true
20
+ },
14
21
  _id: String,
15
22
  typeOf: {
16
23
  type: String,
@@ -46,7 +53,6 @@ const schema = new mongoose_1.Schema({
46
53
  aggregateEntranceGate: mongoose_1.SchemaTypes.Mixed,
47
54
  aggregateReservation: mongoose_1.SchemaTypes.Mixed,
48
55
  aggregateOffer: mongoose_1.SchemaTypes.Mixed,
49
- organizer: mongoose_1.SchemaTypes.Mixed,
50
56
  coaInfo: mongoose_1.SchemaTypes.Mixed
51
57
  }, {
52
58
  collection: 'events',
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.4.0-alpha.6"
120
+ "version": "21.4.0-alpha.7"
121
121
  }
@@ -1,90 +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 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
- // tslint:disable-next-line:no-magic-numbers
25
- .add(-6, 'months')
26
- .toDate()
27
- }
28
- // _id: { $eq: 'al6aff83w' }
29
- },
30
- {
31
- // _id: 1,
32
- }
33
- );
34
- console.log('events found');
35
-
36
- let i = 0;
37
- let updateCount = 0;
38
- await cursor.eachAsync(async (doc) => {
39
- i += 1;
40
- const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
41
-
42
- const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
43
- if (eventOffers === undefined) {
44
- throw new Error('event.offers undefined');
45
- }
46
-
47
- const availableChannel = eventOffers.itemOffered.availableChannel;
48
-
49
- const alreadyMigrated = availableChannel?.typeOf === 'ServiceChannel';
50
-
51
- if (alreadyMigrated) {
52
- console.log(
53
- 'already exist...', event.project.id, event.id, event.startDate, availableChannel.serviceLocation.branchCode, i);
54
- } else {
55
- const newAvailableChannel: chevre.factory.reservation.IServiceChannel = {
56
- typeOf: 'ServiceChannel',
57
- serviceLocation: {
58
- typeOf: event.location.typeOf,
59
- branchCode: event.location.branchCode,
60
- name: event.location.name,
61
- containedInPlace: {
62
- typeOf: event.superEvent.location.typeOf,
63
- id: event.superEvent.location.id,
64
- branchCode: event.superEvent.location.branchCode,
65
- name: event.superEvent.location.name
66
- }
67
- }
68
- };
69
- console.log(
70
- 'updating seller...', event.project.id, event.id, event.startDate, newAvailableChannel.serviceLocation.branchCode, i);
71
- await eventRepo.updatePartiallyById({
72
- id: event.id,
73
- attributes: <any>{
74
- typeOf: event.typeOf,
75
- 'offers.itemOffered.availableChannel': newAvailableChannel
76
- }
77
- });
78
- updateCount += 1;
79
- console.log(
80
- 'updated...', event.project.id, event.id, event.startDate, i);
81
- }
82
- });
83
-
84
- console.log(i, 'events checked');
85
- console.log(updateCount, 'events updated');
86
- }
87
-
88
- main()
89
- .then()
90
- .catch(console.error);