@chevre/domain 22.13.0-alpha.0 → 22.13.0-alpha.10

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,96 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ // tslint:disable-next-line:max-func-body-length
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
13
+
14
+ const cursor = eventRepo.getCursor(
15
+ {
16
+ // _id: { $eq: 'blwz44d0k' },
17
+ 'project.id': { $eq: project.id }
18
+ },
19
+ {
20
+ _id: 1,
21
+ startDate: 1,
22
+ project: 1,
23
+ identifier: 1,
24
+ additionalProperty: 1,
25
+ typeOf: 1
26
+ }
27
+ );
28
+ console.log('events found');
29
+
30
+ let i = 0;
31
+ let updateCount = 0;
32
+ await cursor.eachAsync(async (doc) => {
33
+ i += 1;
34
+ const event: Pick<
35
+ chevre.factory.event.screeningEvent.IEvent,
36
+ 'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
37
+ > = doc.toObject();
38
+
39
+ console.log(
40
+ 'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
41
+ const isValidProject = event.project.id.substring(0, 5) === 'ttts-';
42
+ if (!isValidProject) {
43
+ throw new Error(`${event.project.id} ${event.id} invalid project.`);
44
+ }
45
+ const eventIdentifier = event.identifier;
46
+ const oldEventId = event.additionalProperty?.find(({ name }) => name === 'oldEventId')?.value;
47
+ const tourNumber = event.additionalProperty?.find(({ name }) => name === 'tourNumber')?.value;
48
+ if (typeof oldEventId !== 'string' || oldEventId === '') {
49
+ throw new Error(`${event.project.id} ${event.id} oldEventId required: ${oldEventId}`);
50
+ }
51
+ if (typeof tourNumber !== 'string' || tourNumber === '') {
52
+ throw new Error(`${event.project.id} ${event.id} tourNumber required: ${tourNumber}`);
53
+ }
54
+
55
+ const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === oldEventId;
56
+
57
+ if (alreadyMigrated) {
58
+ console.log(
59
+ 'already migrated.', event.project.id, event.id, event.startDate, i);
60
+ } else {
61
+ console.log(
62
+ 'updating... oldEventId:',
63
+ oldEventId, event.project.id, event.id, event.startDate, i);
64
+ await eventRepo.updatePartiallyById({
65
+ project: { id: event.project.id },
66
+ id: event.id,
67
+ attributes: {
68
+ typeOf: event.typeOf,
69
+ ...{
70
+ identifier: oldEventId
71
+ }
72
+ }
73
+ });
74
+ updateCount += 1;
75
+ console.log(
76
+ 'updated.',
77
+ event.project.id, event.id, event.startDate, i);
78
+ }
79
+ });
80
+
81
+ console.log(i, 'events checked');
82
+ console.log(updateCount, 'events updated');
83
+
84
+ // await eventRepo.projectEventFields<chevre.factory.eventType.ScreeningEvent>(
85
+ // {
86
+ // project: { id: { $eq: project.id } },
87
+ // typeOf: chevre.factory.eventType.ScreeningEvent,
88
+ // // id
89
+ // },
90
+ // ['identifier']
91
+ // );
92
+ }
93
+
94
+ main()
95
+ .then()
96
+ .catch(console.error);
@@ -0,0 +1,191 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import * as moment from 'moment-timezone';
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 ADDITIONAL_PROPERTY_NAME = 'sampleCreateId';
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 eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
15
+
16
+ const today = moment()
17
+ .tz('Asia/Tokyo')
18
+ .format('YYYY-MM-DD');
19
+ const identifier = `fromSamples:${moment()
20
+ .format('YYYY-MM-DD HH:mm')}`;
21
+ const settingEvent: chevre.factory.event.screeningEvent.IAttributes = {
22
+ identifier,
23
+ additionalProperty: [
24
+ { name: ADDITIONAL_PROPERTY_NAME, value: identifier }
25
+ ],
26
+ project: {
27
+ id: project.id,
28
+ typeOf: chevre.factory.organizationType.Project
29
+ },
30
+ organizer: {
31
+ id: '59d20831e53ebc2b4e774466'
32
+ },
33
+ typeOf: chevre.factory.eventType.ScreeningEvent,
34
+ name: {
35
+ en: 'pet IMAX2D',
36
+ ja: 'ペット IMAX2D'
37
+ },
38
+ doorTime: moment(`${today}T13:00:00Z`)
39
+ .toDate(),
40
+ startDate: moment(`${today}T13:00:00Z`)
41
+ .toDate(),
42
+ endDate: moment(`${today}T14:00:00Z`)
43
+ .toDate(),
44
+ eventStatus: chevre.factory.eventStatusType.EventScheduled,
45
+ location: {
46
+ typeOf: chevre.factory.placeType.ScreeningRoom,
47
+ branchCode: '70',
48
+ name: {
49
+ ja: 'シネマ7',
50
+ en: 'CINEMA7'
51
+ },
52
+ address: {
53
+ ja: '',
54
+ en: ''
55
+ }
56
+ },
57
+ superEvent: {
58
+ typeOf: chevre.factory.eventType.ScreeningEventSeries,
59
+ id: 'al9s38bj6',
60
+ videoFormat: [
61
+ {
62
+ typeOf: '2D',
63
+ name: '2D'
64
+ },
65
+ {
66
+ typeOf: 'IMAX',
67
+ name: 'IMAX'
68
+ }
69
+ ],
70
+ soundFormat: [],
71
+ workPerformed: {
72
+ typeOf: chevre.factory.creativeWorkType.Movie,
73
+ identifier: '1622100',
74
+ id: '5bfb841d5a78d7948369980a',
75
+ name: {
76
+ en: 'Pet',
77
+ ja: 'ペット'
78
+ },
79
+ duration: 'PT2H3M'
80
+ },
81
+ location: {
82
+ typeOf: chevre.factory.placeType.MovieTheater,
83
+ id: '5bfb841d5a78d7948369979a',
84
+ branchCode: '118',
85
+ name: {
86
+ ja: 'シネモーション赤坂 ',
87
+ en: 'CineMotion Akasaka'
88
+ }
89
+ },
90
+ kanaName: 'ペット IMAX2D',
91
+ name: {
92
+ en: 'pet IMAX2D',
93
+ ja: 'ペット IMAX2D'
94
+ },
95
+ additionalProperty: [],
96
+ startDate: moment('2022-09-30T15:00:00.000Z')
97
+ .toDate(),
98
+ endDate: moment('2029-07-31T15:00:00.000Z')
99
+ .toDate(),
100
+ headline: {
101
+ ja: 'IMAX2D上映'
102
+ }
103
+ },
104
+ offers: {
105
+ typeOf: chevre.factory.offerType.Offer,
106
+ eligibleQuantity: {
107
+ typeOf: 'QuantitativeValue',
108
+ unitCode: chevre.factory.unitCode.C62,
109
+ maxValue: 6
110
+ },
111
+ itemOffered: {
112
+ id: '655dc6b02cbb99d946cb6081',
113
+ name: {
114
+ ja: '通常興行カタログ(サブカタログ版)'
115
+ },
116
+ serviceOutput: {
117
+ typeOf: chevre.factory.reservationType.EventReservation,
118
+ reservedTicket: {
119
+ typeOf: 'Ticket',
120
+ ticketedSeat: {
121
+ typeOf: chevre.factory.placeType.Seat
122
+ }
123
+ }
124
+ },
125
+ typeOf: chevre.factory.product.ProductType.EventService,
126
+ availableChannel: {
127
+ typeOf: 'ServiceChannel',
128
+ serviceLocation: {
129
+ typeOf: chevre.factory.placeType.ScreeningRoom,
130
+ branchCode: '70',
131
+ name: {
132
+ ja: 'シネマ7',
133
+ en: 'CINEMA7'
134
+ },
135
+ containedInPlace: {
136
+ typeOf: chevre.factory.placeType.MovieTheater,
137
+ id: '5bfb841d5a78d7948369979a',
138
+ branchCode: '118',
139
+ name: {
140
+ ja: 'シネモーション赤坂 ',
141
+ en: 'CineMotion Akasaka'
142
+ }
143
+ }
144
+ }
145
+ }
146
+ },
147
+ seller: {
148
+ typeOf: chevre.factory.organizationType.Corporation,
149
+ id: '59d20831e53ebc2b4e774466',
150
+ name: {
151
+ ja: 'シネモーション赤坂',
152
+ en: 'CineMotion Akasaka'
153
+ },
154
+ makesOffer: [
155
+ ]
156
+ }
157
+ }
158
+ };
159
+
160
+ const createResult = await eventRepo.upsertManyScreeningEventByIdentifier(
161
+ [
162
+ {
163
+ $set: settingEvent,
164
+ $unset: {}
165
+ }
166
+ ],
167
+ { update: false }
168
+ );
169
+ // tslint:disable-next-line:no-null-keyword
170
+ console.dir(createResult, { depth: null });
171
+
172
+ const updateResult = await eventRepo.upsertManyScreeningEventByIdentifier(
173
+ [
174
+ {
175
+ $set: {
176
+ ...settingEvent,
177
+ eventStatus: chevre.factory.eventStatusType.EventCancelled
178
+ },
179
+ $unset: {}
180
+ }
181
+ ],
182
+ { update: true }
183
+ );
184
+ // tslint:disable-next-line:no-null-keyword
185
+ console.dir(updateResult, { depth: null });
186
+
187
+ }
188
+
189
+ main()
190
+ .then()
191
+ .catch(console.error);
@@ -8,23 +8,11 @@ async function main() {
8
8
 
9
9
  const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
10
 
11
- // const roleNames = [
12
- // chevre.factory.role.organizationRole.RoleName.InventoryManager,
13
- // chevre.factory.role.organizationRole.RoleName.SellersOwner,
14
- // chevre.factory.role.organizationRole.RoleName.SellersInventoryManager
15
- // ];
16
- // for (const roleName of roleNames) {
17
- // const result = await roleRepo.addPermissionIfNotExists({
18
- // roleName: { $eq: roleName },
19
- // permission: 'eventOffers.*'
20
- // });
21
- // console.log(result, roleName);
22
- // }
23
- let roleNames = [
11
+ const roleNames = [
24
12
  chevre.factory.role.organizationRole.RoleName.InventoryManager
25
13
  ];
26
- let permissions = [
27
- 'admin.creativeWorks.*'
14
+ const permissions = [
15
+ 'sellerMakesOffer.*'
28
16
  ];
29
17
  for (const roleName of roleNames) {
30
18
  for (const permission of permissions) {
@@ -36,23 +24,23 @@ async function main() {
36
24
  }
37
25
  }
38
26
 
39
- roleNames = [
40
- chevre.factory.role.organizationRole.RoleName.InventoryManager,
41
- chevre.factory.role.organizationRole.RoleName.SellersOwner,
42
- chevre.factory.role.organizationRole.RoleName.SellersInventoryManager
43
- ];
44
- permissions = [
45
- 'admin.sellers.eventSeries.*'
46
- ];
47
- for (const roleName of roleNames) {
48
- for (const permission of permissions) {
49
- const result = await roleRepo.addPermissionIfNotExists({
50
- roleName: { $eq: roleName },
51
- permission
52
- });
53
- console.log('permission added.', result, roleName);
54
- }
55
- }
27
+ // roleNames = [
28
+ // chevre.factory.role.organizationRole.RoleName.InventoryManager,
29
+ // chevre.factory.role.organizationRole.RoleName.SellersOwner,
30
+ // chevre.factory.role.organizationRole.RoleName.SellersInventoryManager
31
+ // ];
32
+ // permissions = [
33
+ // 'admin.sellers.eventSeries.*'
34
+ // ];
35
+ // for (const roleName of roleNames) {
36
+ // for (const permission of permissions) {
37
+ // const result = await roleRepo.addPermissionIfNotExists({
38
+ // roleName: { $eq: roleName },
39
+ // permission
40
+ // });
41
+ // console.log('permission added.', result, roleName);
42
+ // }
43
+ // }
56
44
  }
57
45
 
58
46
  main()
@@ -56,6 +56,9 @@ type IKeyOfProjection4minimizedEvent<T extends AvailableEventType> = T extends f
56
56
  type IUnset<T extends AvailableEventType> = {
57
57
  [key in keyof factory.event.IEvent<T>]?: 1;
58
58
  };
59
+ export type ICreatingEvent4ttts = Pick<factory.event.IAttributes<factory.eventType.ScreeningEvent>, 'additionalProperty' | 'doorTime' | 'endDate' | 'eventStatus' | 'location' | 'name' | 'offers' | 'organizer' | 'project' | 'startDate' | 'superEvent' | 'typeOf'> & {
60
+ identifier: string;
61
+ };
59
62
  /**
60
63
  * イベントリポジトリ
61
64
  */
@@ -104,6 +107,26 @@ export declare class EventRepo {
104
107
  id: string;
105
108
  }[];
106
109
  } | void>;
110
+ /**
111
+ * イベントコードをキーにして冪等置換
112
+ */
113
+ upsertManyScreeningEventByIdentifier(params: {
114
+ $set: factory.event.screeningEvent.IAttributes & {
115
+ id?: never;
116
+ };
117
+ $unset: IUnset<factory.eventType.ScreeningEvent>;
118
+ }[], options: {
119
+ /**
120
+ * falseの場合setOnInsertのみ
121
+ * trueの場合setのみ
122
+ */
123
+ update: boolean;
124
+ }): Promise<{
125
+ bulkWriteResult: BulkWriteResult;
126
+ modifiedEvents: {
127
+ id: string;
128
+ }[];
129
+ } | void>;
107
130
  /**
108
131
  * イベント部分更新
109
132
  */
@@ -128,15 +151,20 @@ export declare class EventRepo {
128
151
  }): Promise<{
129
152
  id: string;
130
153
  }>;
131
- saveManyEvents<T extends AvailableEventType>(params: {
154
+ /**
155
+ * sskts専用
156
+ */
157
+ saveManyEvents(params: {
132
158
  id: string;
133
- attributes: factory.event.IAttributes<T>;
134
- $unset?: IUnset<T>;
159
+ attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
160
+ $unset?: IUnset<factory.eventType.ScreeningEvent>;
135
161
  upsert: boolean;
136
162
  }[]): Promise<void>;
137
- save4ttts(params: {
138
- oldEventId: string;
139
- attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
163
+ /**
164
+ * tttsイベントを識別子によって冪等作成する
165
+ */
166
+ saveEventByIdentifier4ttts(params: {
167
+ attributes: ICreatingEvent4ttts;
140
168
  }): Promise<{
141
169
  id: string;
142
170
  }>;