@chevre/domain 22.13.0-alpha.1 → 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);
@@ -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
  }>;
@@ -43,7 +43,7 @@ class EventRepo {
43
43
  }
44
44
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
45
45
  static CREATE_MONGO_CONDITIONS(conditions) {
46
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
46
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28;
47
47
  const andConditions = [];
48
48
  const typeOfEq = conditions.typeOf;
49
49
  if (typeof typeOfEq === 'string') {
@@ -73,6 +73,10 @@ class EventRepo {
73
73
  if (Array.isArray(idIn)) {
74
74
  andConditions.push({ _id: { $in: idIn } });
75
75
  }
76
+ const identifierIn = (_g = conditions.identifier) === null || _g === void 0 ? void 0 : _g.$in;
77
+ if (Array.isArray(identifierIn)) {
78
+ andConditions.push({ identifier: { $exists: true, $in: identifierIn } });
79
+ }
76
80
  // tslint:disable-next-line:no-single-line-block-comment
77
81
  /* istanbul ignore else */
78
82
  if (Array.isArray(conditions.eventStatuses)) {
@@ -122,11 +126,11 @@ class EventRepo {
122
126
  endDate: { $lte: conditions.endThrough }
123
127
  });
124
128
  }
125
- const locationBranchCodeEq = (_h = (_g = conditions.location) === null || _g === void 0 ? void 0 : _g.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
129
+ const locationBranchCodeEq = (_j = (_h = conditions.location) === null || _h === void 0 ? void 0 : _h.branchCode) === null || _j === void 0 ? void 0 : _j.$eq;
126
130
  if (typeof locationBranchCodeEq === 'string') {
127
131
  andConditions.push({ 'location.branchCode': { $exists: true, $eq: locationBranchCodeEq } });
128
132
  }
129
- const locationBranchCodeIn = (_k = (_j = conditions.location) === null || _j === void 0 ? void 0 : _j.branchCode) === null || _k === void 0 ? void 0 : _k.$in;
133
+ const locationBranchCodeIn = (_l = (_k = conditions.location) === null || _k === void 0 ? void 0 : _k.branchCode) === null || _l === void 0 ? void 0 : _l.$in;
130
134
  if (Array.isArray(locationBranchCodeIn)) {
131
135
  andConditions.push({ 'location.branchCode': { $exists: true, $in: locationBranchCodeIn } });
132
136
  }
@@ -140,7 +144,7 @@ class EventRepo {
140
144
  // }
141
145
  // });
142
146
  // }
143
- const additionalPropertyElemMatch = (_l = conditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
147
+ const additionalPropertyElemMatch = (_m = conditions.additionalProperty) === null || _m === void 0 ? void 0 : _m.$elemMatch;
144
148
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
145
149
  andConditions.push({
146
150
  additionalProperty: {
@@ -156,7 +160,7 @@ class EventRepo {
156
160
  // tslint:disable-next-line:no-single-line-block-comment
157
161
  /* istanbul ignore else */
158
162
  if (params.offers !== undefined) {
159
- const itemOfferedIdIn4event = (_o = (_m = params.offers.itemOffered) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$in;
163
+ const itemOfferedIdIn4event = (_p = (_o = params.offers.itemOffered) === null || _o === void 0 ? void 0 : _o.id) === null || _p === void 0 ? void 0 : _p.$in;
160
164
  if (Array.isArray(itemOfferedIdIn4event)) {
161
165
  andConditions.push({
162
166
  'offers.itemOffered.id': {
@@ -206,8 +210,8 @@ class EventRepo {
206
210
  }
207
211
  }
208
212
  }
209
- const sellerMakesOfferElemMatch4event = (_r = (_q = (_p = params.offers) === null || _p === void 0 ? void 0 : _p.seller) === null || _q === void 0 ? void 0 : _q.makesOffer) === null || _r === void 0 ? void 0 : _r.$elemMatch;
210
- if (typeof ((_s = sellerMakesOfferElemMatch4event === null || sellerMakesOfferElemMatch4event === void 0 ? void 0 : sellerMakesOfferElemMatch4event['availableAtOrFrom.id']) === null || _s === void 0 ? void 0 : _s.$eq) === 'string') {
213
+ const sellerMakesOfferElemMatch4event = (_s = (_r = (_q = params.offers) === null || _q === void 0 ? void 0 : _q.seller) === null || _r === void 0 ? void 0 : _r.makesOffer) === null || _s === void 0 ? void 0 : _s.$elemMatch;
214
+ if (typeof ((_t = sellerMakesOfferElemMatch4event === null || sellerMakesOfferElemMatch4event === void 0 ? void 0 : sellerMakesOfferElemMatch4event['availableAtOrFrom.id']) === null || _t === void 0 ? void 0 : _t.$eq) === 'string') {
211
215
  andConditions.push({
212
216
  'offers.seller.makesOffer': {
213
217
  $exists: true,
@@ -215,7 +219,7 @@ class EventRepo {
215
219
  }
216
220
  });
217
221
  }
218
- const reservationForIdentifierEq = (_x = (_w = (_v = (_u = (_t = params.offers) === null || _t === void 0 ? void 0 : _t.itemOffered) === null || _u === void 0 ? void 0 : _u.serviceOutput) === null || _v === void 0 ? void 0 : _v.reservationFor) === null || _w === void 0 ? void 0 : _w.identifier) === null || _x === void 0 ? void 0 : _x.$eq;
222
+ const reservationForIdentifierEq = (_y = (_x = (_w = (_v = (_u = params.offers) === null || _u === void 0 ? void 0 : _u.itemOffered) === null || _v === void 0 ? void 0 : _v.serviceOutput) === null || _w === void 0 ? void 0 : _w.reservationFor) === null || _x === void 0 ? void 0 : _x.identifier) === null || _y === void 0 ? void 0 : _y.$eq;
219
223
  if (typeof reservationForIdentifierEq === 'string') {
220
224
  andConditions.push({
221
225
  'offers.itemOffered.serviceOutput.reservationFor.identifier': {
@@ -224,7 +228,7 @@ class EventRepo {
224
228
  }
225
229
  });
226
230
  }
227
- const reservationForArrivalBusStopBranchCodeEq = (_3 = (_2 = (_1 = (_0 = (_z = (_y = params.offers) === null || _y === void 0 ? void 0 : _y.itemOffered) === null || _z === void 0 ? void 0 : _z.serviceOutput) === null || _0 === void 0 ? void 0 : _0.reservationFor) === null || _1 === void 0 ? void 0 : _1.arrivalBusStop) === null || _2 === void 0 ? void 0 : _2.branchCode) === null || _3 === void 0 ? void 0 : _3.$eq;
231
+ const reservationForArrivalBusStopBranchCodeEq = (_4 = (_3 = (_2 = (_1 = (_0 = (_z = params.offers) === null || _z === void 0 ? void 0 : _z.itemOffered) === null || _0 === void 0 ? void 0 : _0.serviceOutput) === null || _1 === void 0 ? void 0 : _1.reservationFor) === null || _2 === void 0 ? void 0 : _2.arrivalBusStop) === null || _3 === void 0 ? void 0 : _3.branchCode) === null || _4 === void 0 ? void 0 : _4.$eq;
228
232
  if (typeof reservationForArrivalBusStopBranchCodeEq === 'string') {
229
233
  andConditions.push({
230
234
  'offers.itemOffered.serviceOutput.reservationFor.arrivalBusStop.branchCode': {
@@ -233,7 +237,7 @@ class EventRepo {
233
237
  }
234
238
  });
235
239
  }
236
- const reservationForDepartureBusStopBranchCodeEq = (_9 = (_8 = (_7 = (_6 = (_5 = (_4 = params.offers) === null || _4 === void 0 ? void 0 : _4.itemOffered) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.reservationFor) === null || _7 === void 0 ? void 0 : _7.departureBusStop) === null || _8 === void 0 ? void 0 : _8.branchCode) === null || _9 === void 0 ? void 0 : _9.$eq;
240
+ const reservationForDepartureBusStopBranchCodeEq = (_10 = (_9 = (_8 = (_7 = (_6 = (_5 = params.offers) === null || _5 === void 0 ? void 0 : _5.itemOffered) === null || _6 === void 0 ? void 0 : _6.serviceOutput) === null || _7 === void 0 ? void 0 : _7.reservationFor) === null || _8 === void 0 ? void 0 : _8.departureBusStop) === null || _9 === void 0 ? void 0 : _9.branchCode) === null || _10 === void 0 ? void 0 : _10.$eq;
237
241
  if (typeof reservationForDepartureBusStopBranchCodeEq === 'string') {
238
242
  andConditions.push({
239
243
  'offers.itemOffered.serviceOutput.reservationFor.departureBusStop.branchCode': {
@@ -267,7 +271,7 @@ class EventRepo {
267
271
  }
268
272
  // tslint:disable-next-line:no-single-line-block-comment
269
273
  /* istanbul ignore else */
270
- const superEventLocationIdEq = (_12 = (_11 = (_10 = params.superEvent) === null || _10 === void 0 ? void 0 : _10.location) === null || _11 === void 0 ? void 0 : _11.id) === null || _12 === void 0 ? void 0 : _12.$eq;
274
+ const superEventLocationIdEq = (_13 = (_12 = (_11 = params.superEvent) === null || _11 === void 0 ? void 0 : _11.location) === null || _12 === void 0 ? void 0 : _12.id) === null || _13 === void 0 ? void 0 : _13.$eq;
271
275
  if (typeof superEventLocationIdEq === 'string') {
272
276
  andConditions.push({
273
277
  'superEvent.location.id': {
@@ -310,7 +314,7 @@ class EventRepo {
310
314
  });
311
315
  }
312
316
  }
313
- const itemOfferedIdIn = (_15 = (_14 = (_13 = params.offers) === null || _13 === void 0 ? void 0 : _13.itemOffered) === null || _14 === void 0 ? void 0 : _14.id) === null || _15 === void 0 ? void 0 : _15.$in;
317
+ const itemOfferedIdIn = (_16 = (_15 = (_14 = params.offers) === null || _14 === void 0 ? void 0 : _14.itemOffered) === null || _15 === void 0 ? void 0 : _15.id) === null || _16 === void 0 ? void 0 : _16.$in;
314
318
  if (Array.isArray(itemOfferedIdIn)) {
315
319
  andConditions.push({
316
320
  'offers.itemOffered.id': {
@@ -319,7 +323,7 @@ class EventRepo {
319
323
  }
320
324
  });
321
325
  }
322
- const itemOfferedTicketedSeatTypeOfIn = (_20 = (_19 = (_18 = (_17 = (_16 = params.offers) === null || _16 === void 0 ? void 0 : _16.itemOffered) === null || _17 === void 0 ? void 0 : _17.serviceOutput) === null || _18 === void 0 ? void 0 : _18.reservedTicket) === null || _19 === void 0 ? void 0 : _19.ticketedSeat) === null || _20 === void 0 ? void 0 : _20.typeOfs;
326
+ const itemOfferedTicketedSeatTypeOfIn = (_21 = (_20 = (_19 = (_18 = (_17 = params.offers) === null || _17 === void 0 ? void 0 : _17.itemOffered) === null || _18 === void 0 ? void 0 : _18.serviceOutput) === null || _19 === void 0 ? void 0 : _19.reservedTicket) === null || _20 === void 0 ? void 0 : _20.ticketedSeat) === null || _21 === void 0 ? void 0 : _21.typeOfs;
323
327
  if (Array.isArray(itemOfferedTicketedSeatTypeOfIn)) {
324
328
  andConditions.push({
325
329
  'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
@@ -328,7 +332,7 @@ class EventRepo {
328
332
  }
329
333
  });
330
334
  }
331
- const itemOfferedServiceTypeIdIn = (_23 = (_22 = (_21 = params.offers) === null || _21 === void 0 ? void 0 : _21.itemOffered) === null || _22 === void 0 ? void 0 : _22.serviceType) === null || _23 === void 0 ? void 0 : _23.ids;
335
+ const itemOfferedServiceTypeIdIn = (_24 = (_23 = (_22 = params.offers) === null || _22 === void 0 ? void 0 : _22.itemOffered) === null || _23 === void 0 ? void 0 : _23.serviceType) === null || _24 === void 0 ? void 0 : _24.ids;
332
336
  if (Array.isArray(itemOfferedServiceTypeIdIn)) {
333
337
  andConditions.push({
334
338
  'offers.itemOffered.serviceType.id': {
@@ -337,8 +341,8 @@ class EventRepo {
337
341
  }
338
342
  });
339
343
  }
340
- const sellerMakesOfferElemMatch = (_26 = (_25 = (_24 = params.offers) === null || _24 === void 0 ? void 0 : _24.seller) === null || _25 === void 0 ? void 0 : _25.makesOffer) === null || _26 === void 0 ? void 0 : _26.$elemMatch;
341
- if (typeof ((_27 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _27 === void 0 ? void 0 : _27.$eq) === 'string') {
344
+ const sellerMakesOfferElemMatch = (_27 = (_26 = (_25 = params.offers) === null || _25 === void 0 ? void 0 : _25.seller) === null || _26 === void 0 ? void 0 : _26.makesOffer) === null || _27 === void 0 ? void 0 : _27.$elemMatch;
345
+ if (typeof ((_28 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _28 === void 0 ? void 0 : _28.$eq) === 'string') {
342
346
  andConditions.push({
343
347
  'offers.seller.makesOffer': {
344
348
  $exists: true,
@@ -482,6 +486,71 @@ class EventRepo {
482
486
  }
483
487
  });
484
488
  }
489
+ /**
490
+ * イベントコードをキーにして冪等置換
491
+ */
492
+ upsertManyScreeningEventByIdentifier(params, options) {
493
+ return __awaiter(this, void 0, void 0, function* () {
494
+ const { update } = options;
495
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
496
+ const bulkWriteOps = [];
497
+ const queryFilters = [];
498
+ if (Array.isArray(params)) {
499
+ params.forEach(({ $set, $unset }) => {
500
+ const { project, identifier } = $set;
501
+ if (typeof identifier !== 'string' || identifier.length === 0) {
502
+ throw new factory.errors.ArgumentNull('identifier');
503
+ }
504
+ // リソースのユニークネスを保証するfilter
505
+ const filter = {
506
+ 'project.id': { $eq: project.id },
507
+ identifier: { $exists: true, $eq: identifier }
508
+ };
509
+ queryFilters.push({
510
+ 'project.id': { $eq: project.id },
511
+ identifier: { $exists: true, $eq: identifier }
512
+ });
513
+ if (update === true) {
514
+ const { maximumPhysicalAttendeeCapacity, additionalProperty, eventStatus, location, name, superEvent, offers, doorTime, endDate, startDate } = $set;
515
+ const setFields = {
516
+ maximumPhysicalAttendeeCapacity, additionalProperty,
517
+ eventStatus, location, name, superEvent, offers,
518
+ doorTime, endDate, startDate
519
+ };
520
+ const updateOne = {
521
+ filter,
522
+ update: Object.assign({ $set: setFields }, ($unset !== undefined) ? { $unset } : undefined),
523
+ upsert: false
524
+ };
525
+ bulkWriteOps.push({ updateOne });
526
+ }
527
+ else {
528
+ const { id, coaInfo, description, maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation } = $set, setOnInsertFields = __rest($set, ["id", "coaInfo", "description", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation"]);
529
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { identifier, _id: uniqid() });
530
+ const updateOne = {
531
+ filter,
532
+ update: {
533
+ $setOnInsert: setOnInsert
534
+ },
535
+ upsert: true
536
+ };
537
+ bulkWriteOps.push({ updateOne });
538
+ }
539
+ });
540
+ }
541
+ if (bulkWriteOps.length > 0) {
542
+ const bulkWriteResult = yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
543
+ // modifiedの場合upsertedIdsに含まれないので、idを検索する
544
+ const modifiedEvents = yield this.eventModel.find({ $or: queryFilters }, {
545
+ _id: 0,
546
+ id: { $toString: '$_id' }
547
+ })
548
+ .lean()
549
+ .exec();
550
+ return { bulkWriteResult, modifiedEvents };
551
+ }
552
+ });
553
+ }
485
554
  /**
486
555
  * イベント部分更新
487
556
  */
@@ -553,6 +622,9 @@ class EventRepo {
553
622
  return { id: savedEventId }; // optimize(2024-07-31~)
554
623
  });
555
624
  }
625
+ /**
626
+ * sskts専用
627
+ */
556
628
  saveManyEvents(params) {
557
629
  return __awaiter(this, void 0, void 0, function* () {
558
630
  const bulkWriteOps = [];
@@ -586,25 +658,45 @@ class EventRepo {
586
658
  }
587
659
  });
588
660
  }
589
- save4ttts(params) {
661
+ /**
662
+ * tttsイベントを識別子によって冪等作成する
663
+ */
664
+ saveEventByIdentifier4ttts(params) {
590
665
  return __awaiter(this, void 0, void 0, function* () {
591
- // let doc: Document | null;
592
- const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
666
+ // const { oldEventId } = params;
667
+ const _a = params.attributes, { project, typeOf, eventStatus, identifier, organizer } = _a, updateFields = __rest(_a, ["project", "typeOf", "eventStatus", "identifier", "organizer"]);
668
+ // const identifier = oldEventId;
669
+ if (typeof identifier !== 'string' || identifier.length === 0) {
670
+ throw new factory.errors.ArgumentNull('identifier');
671
+ }
593
672
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
594
673
  const id = uniqid();
595
- const doc = yield this.eventModel.findOneAndUpdate({
674
+ const doc = yield this.eventModel.findOneAndUpdate(
675
+ // 全イベントにidentifierを保証したので、additionalPropertyによるフィルターからidentifierによるフィルターへ変更(2025-09-05~)
676
+ // {
677
+ // 'project.id': { $eq: project.id },
678
+ // typeOf: { $eq: typeOf },
679
+ // // 追加特性をキーに更新
680
+ // additionalProperty: {
681
+ // $exists: true,
682
+ // $all: [{ name: 'oldEventId', value: identifier }]
683
+ // }
684
+ // },
685
+ {
596
686
  'project.id': { $eq: project.id },
597
- typeOf: { $eq: typeOf },
598
- // 追加特性をキーに更新
599
- additionalProperty: {
600
- $exists: true,
601
- $all: [{ name: 'oldEventId', value: params.oldEventId }]
602
- }
687
+ identifier: { $exists: true, $eq: identifier }
603
688
  },
604
689
  // upsertの場合、createがありうるので属性を除外しない
605
690
  {
606
- $setOnInsert: Object.assign({ _id: id, typeOf,
607
- project }, (typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined),
691
+ $setOnInsert: {
692
+ _id: id,
693
+ typeOf,
694
+ project,
695
+ eventStatus,
696
+ organizer,
697
+ identifier // イベントコードを必ず追加(2025-09-03~)
698
+ // ...(typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined
699
+ },
608
700
  $set: updateFields
609
701
  }, { upsert: true, new: true, projection: { _id: 1 } })
610
702
  .lean()