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

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,112 @@
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: Pick<
51
+ chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEvent>,
52
+ 'id' | 'project' | 'location' | 'startDate' | 'typeOf' | 'organizer' | 'superEvent'
53
+ > | Pick<
54
+ chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEventSeries>,
55
+ 'id' | 'project' | 'location' | 'startDate' | 'typeOf' | 'organizer'
56
+ > = doc.toObject();
57
+
58
+ const organizerId = event.organizer?.id;
59
+ const alreadyMigrated = typeof organizerId === 'string';
60
+
61
+ if (alreadyMigrated) {
62
+ console.log('already exist...', event.project.id, event.id, event.startDate, organizerId, i);
63
+ } else {
64
+ let movieTheaterId: string;
65
+ if (event.typeOf === chevre.factory.eventType.ScreeningEventSeries) {
66
+ movieTheaterId = event.location.id;
67
+ } else {
68
+ movieTheaterId = event.superEvent.location.id;
69
+ }
70
+ const movieTheaters = <Pick<chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom, 'parentOrganization'>[]>
71
+ await placeRepo.searchMovieTheaters(
72
+ {
73
+ limit: 1,
74
+ page: 1,
75
+ project: { id: { $eq: event.project.id } },
76
+ id: { $eq: movieTheaterId }
77
+ },
78
+ ['parentOrganization'],
79
+ []
80
+ );
81
+ const movieTheater = movieTheaters.shift();
82
+ const sellerId = movieTheater?.parentOrganization?.id;
83
+ console.log('movieTheater found', event.project.id, event.id, event.startDate, 'sellerId:', sellerId, i);
84
+ // if (typeof sellerId !== 'string') {
85
+ // throw new Error('movieTheater not found');
86
+ // }
87
+ if (typeof sellerId === 'string') {
88
+ const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
89
+ id: sellerId
90
+ };
91
+ console.log('updating event...', event.project.id, event.id, event.startDate, i);
92
+ await eventRepo.updatePartiallyById({
93
+ project: { id: event.project.id },
94
+ id: event.id,
95
+ attributes: <any>{
96
+ typeOf: event.typeOf,
97
+ organizer: newOrganizer
98
+ }
99
+ });
100
+ updateCount += 1;
101
+ console.log('updated.', event.project.id, event.id, event.startDate, i);
102
+ }
103
+ }
104
+ });
105
+
106
+ console.log(i, 'events checked');
107
+ console.log(updateCount, 'events updated');
108
+ }
109
+
110
+ main()
111
+ .then()
112
+ .catch(console.error);
@@ -10,14 +10,6 @@ async function main() {
10
10
 
11
11
  const eventRepo = new chevre.repository.Event(mongoose.connection);
12
12
 
13
- const event = await eventRepo.findById(
14
- { id: 'al6aff83y' },
15
- {
16
- name: 1
17
- }
18
- );
19
- console.log('event found', event);
20
-
21
13
  const events = await eventRepo.search(
22
14
  {
23
15
  limit: 100,
@@ -25,7 +17,7 @@ async function main() {
25
17
  sort: { startDate: 1 },
26
18
  typeOf: chevre.factory.eventType.ScreeningEvent,
27
19
  project: { id: { $eq: PROJECT_ID } },
28
- id: { $in: ['al6aff83y'] }
20
+ id: { $eq: 'al6aff83y' }
29
21
  },
30
22
  {
31
23
  name: 1
@@ -121,6 +121,9 @@ export declare class MongoRepository {
121
121
  * イベント部分更新
122
122
  */
123
123
  updatePartiallyById<T extends factory.eventType>(params: {
124
+ project: {
125
+ id: string;
126
+ };
124
127
  id: string;
125
128
  attributes: IAttributes4patchUpdate<T>;
126
129
  }): Promise<factory.event.IEvent<T>>;
@@ -143,15 +146,11 @@ export declare class MongoRepository {
143
146
  oldEventId: string;
144
147
  attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
145
148
  }): Promise<factory.event.IEvent<factory.eventType.ScreeningEvent>>;
146
- count<T extends factory.eventType>(params: ISearchConditions<T>): Promise<number>;
147
149
  /**
148
150
  * イベントを検索する
149
151
  */
150
152
  search<T extends factory.eventType>(params: ISearchConditions<T>, projection?: IProjection): Promise<factory.event.IEvent<T>[]>;
151
153
  searchIds<T extends factory.eventType>(params: ISearchConditions<T>): Promise<string[]>;
152
- findById<T extends factory.eventType>(params: {
153
- id: string;
154
- }, projection?: IProjection): Promise<factory.event.IEvent<T>>;
155
154
  findMinimizedIndividualEventById<T extends factory.eventType.ScreeningEvent | factory.eventType.Event>(params: {
156
155
  id: string;
157
156
  }): Promise<IMinimizedIndividualEvent<T>>;
@@ -159,9 +158,15 @@ export declare class MongoRepository {
159
158
  * イベントをキャンセルする
160
159
  */
161
160
  cancel(params: {
161
+ project: {
162
+ id: string;
163
+ };
162
164
  id: string;
163
165
  }): Promise<void>;
164
166
  deleteById(params: {
167
+ project: {
168
+ id: string;
169
+ };
165
170
  id: string;
166
171
  }): Promise<void>;
167
172
  deleteByProject(params: {
@@ -51,25 +51,23 @@ class MongoRepository {
51
51
  }
52
52
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
53
53
  static CREATE_MONGO_CONDITIONS(conditions) {
54
- 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, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41;
54
+ 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, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42;
55
55
  const andConditions = [{ typeOf: { $eq: conditions.typeOf } }];
56
56
  const projectIdEq = (_b = (_a = conditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
57
57
  if (typeof projectIdEq === 'string') {
58
- andConditions.push({
59
- 'project.id': { $eq: projectIdEq }
60
- });
58
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
61
59
  }
62
60
  const organizerIdEq = (_d = (_c = conditions.organizer) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
63
61
  if (typeof organizerIdEq === 'string') {
64
- andConditions.push({
65
- 'organizer.id': { $exists: true, $eq: organizerIdEq }
66
- });
62
+ andConditions.push({ 'organizer.id': { $exists: true, $eq: organizerIdEq } });
67
63
  }
68
- const idIn = (_e = conditions.id) === null || _e === void 0 ? void 0 : _e.$in;
64
+ const idEq = (_e = conditions.id) === null || _e === void 0 ? void 0 : _e.$eq;
65
+ if (typeof idEq === 'string') {
66
+ andConditions.push({ _id: { $eq: idEq } });
67
+ }
68
+ const idIn = (_f = conditions.id) === null || _f === void 0 ? void 0 : _f.$in;
69
69
  if (Array.isArray(idIn)) {
70
- andConditions.push({
71
- _id: { $in: idIn }
72
- });
70
+ andConditions.push({ _id: { $in: idIn } });
73
71
  }
74
72
  // tslint:disable-next-line:no-single-line-block-comment
75
73
  /* istanbul ignore else */
@@ -120,17 +118,17 @@ class MongoRepository {
120
118
  endDate: { $lte: conditions.endThrough }
121
119
  });
122
120
  }
123
- const locationBranchCodeEq = (_g = (_f = conditions.location) === null || _f === void 0 ? void 0 : _f.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
121
+ const locationBranchCodeEq = (_h = (_g = conditions.location) === null || _g === void 0 ? void 0 : _g.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
124
122
  if (typeof locationBranchCodeEq === 'string') {
125
123
  andConditions.push({ 'location.branchCode': { $exists: true, $eq: locationBranchCodeEq } });
126
124
  }
127
- const locationBranchCodeIn = (_j = (_h = conditions.location) === null || _h === void 0 ? void 0 : _h.branchCode) === null || _j === void 0 ? void 0 : _j.$in;
125
+ const locationBranchCodeIn = (_k = (_j = conditions.location) === null || _j === void 0 ? void 0 : _j.branchCode) === null || _k === void 0 ? void 0 : _k.$in;
128
126
  if (Array.isArray(locationBranchCodeIn)) {
129
127
  andConditions.push({ 'location.branchCode': { $exists: true, $in: locationBranchCodeIn } });
130
128
  }
131
129
  // tslint:disable-next-line:no-single-line-block-comment
132
130
  /* istanbul ignore else */
133
- const hasOfferCatalogIdEq = (_l = (_k = conditions.hasOfferCatalog) === null || _k === void 0 ? void 0 : _k.id) === null || _l === void 0 ? void 0 : _l.$eq;
131
+ const hasOfferCatalogIdEq = (_m = (_l = conditions.hasOfferCatalog) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$eq;
134
132
  if (typeof hasOfferCatalogIdEq === 'string') {
135
133
  andConditions.push({
136
134
  'hasOfferCatalog.id': {
@@ -139,7 +137,7 @@ class MongoRepository {
139
137
  }
140
138
  });
141
139
  }
142
- const additionalPropertyElemMatch = (_m = conditions.additionalProperty) === null || _m === void 0 ? void 0 : _m.$elemMatch;
140
+ const additionalPropertyElemMatch = (_o = conditions.additionalProperty) === null || _o === void 0 ? void 0 : _o.$elemMatch;
143
141
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
144
142
  andConditions.push({
145
143
  additionalProperty: {
@@ -155,7 +153,7 @@ class MongoRepository {
155
153
  // tslint:disable-next-line:no-single-line-block-comment
156
154
  /* istanbul ignore else */
157
155
  if (params.offers !== undefined) {
158
- const itemOfferedIdIn4event = (_p = (_o = params.offers.itemOffered) === null || _o === void 0 ? void 0 : _o.id) === null || _p === void 0 ? void 0 : _p.$in;
156
+ const itemOfferedIdIn4event = (_q = (_p = params.offers.itemOffered) === null || _p === void 0 ? void 0 : _p.id) === null || _q === void 0 ? void 0 : _q.$in;
159
157
  if (Array.isArray(itemOfferedIdIn4event)) {
160
158
  andConditions.push({
161
159
  'offers.itemOffered.id': {
@@ -205,8 +203,8 @@ class MongoRepository {
205
203
  }
206
204
  }
207
205
  }
208
- 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;
209
- if (typeof ((_t = sellerMakesOfferElemMatch4event === null || sellerMakesOfferElemMatch4event === void 0 ? void 0 : sellerMakesOfferElemMatch4event['availableAtOrFrom.id']) === null || _t === void 0 ? void 0 : _t.$eq) === 'string') {
206
+ const sellerMakesOfferElemMatch4event = (_t = (_s = (_r = params.offers) === null || _r === void 0 ? void 0 : _r.seller) === null || _s === void 0 ? void 0 : _s.makesOffer) === null || _t === void 0 ? void 0 : _t.$elemMatch;
207
+ if (typeof ((_u = sellerMakesOfferElemMatch4event === null || sellerMakesOfferElemMatch4event === void 0 ? void 0 : sellerMakesOfferElemMatch4event['availableAtOrFrom.id']) === null || _u === void 0 ? void 0 : _u.$eq) === 'string') {
210
208
  andConditions.push({
211
209
  'offers.seller.makesOffer': {
212
210
  $exists: true,
@@ -214,7 +212,7 @@ class MongoRepository {
214
212
  }
215
213
  });
216
214
  }
217
- 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;
215
+ const reservationForIdentifierEq = (_z = (_y = (_x = (_w = (_v = params.offers) === null || _v === void 0 ? void 0 : _v.itemOffered) === null || _w === void 0 ? void 0 : _w.serviceOutput) === null || _x === void 0 ? void 0 : _x.reservationFor) === null || _y === void 0 ? void 0 : _y.identifier) === null || _z === void 0 ? void 0 : _z.$eq;
218
216
  if (typeof reservationForIdentifierEq === 'string') {
219
217
  andConditions.push({
220
218
  'offers.itemOffered.serviceOutput.reservationFor.identifier': {
@@ -223,7 +221,7 @@ class MongoRepository {
223
221
  }
224
222
  });
225
223
  }
226
- 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;
224
+ const reservationForArrivalBusStopBranchCodeEq = (_5 = (_4 = (_3 = (_2 = (_1 = (_0 = params.offers) === null || _0 === void 0 ? void 0 : _0.itemOffered) === null || _1 === void 0 ? void 0 : _1.serviceOutput) === null || _2 === void 0 ? void 0 : _2.reservationFor) === null || _3 === void 0 ? void 0 : _3.arrivalBusStop) === null || _4 === void 0 ? void 0 : _4.branchCode) === null || _5 === void 0 ? void 0 : _5.$eq;
227
225
  if (typeof reservationForArrivalBusStopBranchCodeEq === 'string') {
228
226
  andConditions.push({
229
227
  'offers.itemOffered.serviceOutput.reservationFor.arrivalBusStop.branchCode': {
@@ -232,7 +230,7 @@ class MongoRepository {
232
230
  }
233
231
  });
234
232
  }
235
- 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;
233
+ const reservationForDepartureBusStopBranchCodeEq = (_11 = (_10 = (_9 = (_8 = (_7 = (_6 = params.offers) === null || _6 === void 0 ? void 0 : _6.itemOffered) === null || _7 === void 0 ? void 0 : _7.serviceOutput) === null || _8 === void 0 ? void 0 : _8.reservationFor) === null || _9 === void 0 ? void 0 : _9.departureBusStop) === null || _10 === void 0 ? void 0 : _10.branchCode) === null || _11 === void 0 ? void 0 : _11.$eq;
236
234
  if (typeof reservationForDepartureBusStopBranchCodeEq === 'string') {
237
235
  andConditions.push({
238
236
  'offers.itemOffered.serviceOutput.reservationFor.departureBusStop.branchCode': {
@@ -266,7 +264,7 @@ class MongoRepository {
266
264
  }
267
265
  // tslint:disable-next-line:no-single-line-block-comment
268
266
  /* istanbul ignore else */
269
- 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;
267
+ const superEventLocationIdEq = (_14 = (_13 = (_12 = params.superEvent) === null || _12 === void 0 ? void 0 : _12.location) === null || _13 === void 0 ? void 0 : _13.id) === null || _14 === void 0 ? void 0 : _14.$eq;
270
268
  if (typeof superEventLocationIdEq === 'string') {
271
269
  andConditions.push({
272
270
  'superEvent.location.id': {
@@ -309,7 +307,7 @@ class MongoRepository {
309
307
  });
310
308
  }
311
309
  }
312
- 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;
310
+ const itemOfferedIdIn = (_17 = (_16 = (_15 = params.offers) === null || _15 === void 0 ? void 0 : _15.itemOffered) === null || _16 === void 0 ? void 0 : _16.id) === null || _17 === void 0 ? void 0 : _17.$in;
313
311
  if (Array.isArray(itemOfferedIdIn)) {
314
312
  andConditions.push({
315
313
  'offers.itemOffered.id': {
@@ -318,7 +316,7 @@ class MongoRepository {
318
316
  }
319
317
  });
320
318
  }
321
- 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;
319
+ const itemOfferedTicketedSeatTypeOfIn = (_22 = (_21 = (_20 = (_19 = (_18 = params.offers) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceOutput) === null || _20 === void 0 ? void 0 : _20.reservedTicket) === null || _21 === void 0 ? void 0 : _21.ticketedSeat) === null || _22 === void 0 ? void 0 : _22.typeOfs;
322
320
  if (Array.isArray(itemOfferedTicketedSeatTypeOfIn)) {
323
321
  andConditions.push({
324
322
  'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
@@ -327,7 +325,7 @@ class MongoRepository {
327
325
  }
328
326
  });
329
327
  }
330
- 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;
328
+ const itemOfferedServiceTypeIdIn = (_25 = (_24 = (_23 = params.offers) === null || _23 === void 0 ? void 0 : _23.itemOffered) === null || _24 === void 0 ? void 0 : _24.serviceType) === null || _25 === void 0 ? void 0 : _25.ids;
331
329
  if (Array.isArray(itemOfferedServiceTypeIdIn)) {
332
330
  andConditions.push({
333
331
  'offers.itemOffered.serviceType.id': {
@@ -336,8 +334,8 @@ class MongoRepository {
336
334
  }
337
335
  });
338
336
  }
339
- 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;
340
- if (typeof ((_28 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _28 === void 0 ? void 0 : _28.$eq) === 'string') {
337
+ const sellerMakesOfferElemMatch = (_28 = (_27 = (_26 = params.offers) === null || _26 === void 0 ? void 0 : _26.seller) === null || _27 === void 0 ? void 0 : _27.makesOffer) === null || _28 === void 0 ? void 0 : _28.$elemMatch;
338
+ if (typeof ((_29 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _29 === void 0 ? void 0 : _29.$eq) === 'string') {
341
339
  andConditions.push({
342
340
  'offers.seller.makesOffer': {
343
341
  $exists: true,
@@ -374,7 +372,7 @@ class MongoRepository {
374
372
  ]
375
373
  });
376
374
  }
377
- const locationIdEq = (_30 = (_29 = params.location) === null || _29 === void 0 ? void 0 : _29.id) === null || _30 === void 0 ? void 0 : _30.$eq;
375
+ const locationIdEq = (_31 = (_30 = params.location) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
378
376
  // tslint:disable-next-line:no-single-line-block-comment
379
377
  /* istanbul ignore else */
380
378
  if (typeof locationIdEq === 'string') {
@@ -396,7 +394,7 @@ class MongoRepository {
396
394
  });
397
395
  }
398
396
  }
399
- const workPerformedIdentifierIn = (_31 = params.workPerformed) === null || _31 === void 0 ? void 0 : _31.identifiers;
397
+ const workPerformedIdentifierIn = (_32 = params.workPerformed) === null || _32 === void 0 ? void 0 : _32.identifiers;
400
398
  // tslint:disable-next-line:no-single-line-block-comment
401
399
  /* istanbul ignore else */
402
400
  if (Array.isArray(workPerformedIdentifierIn)) {
@@ -404,13 +402,13 @@ class MongoRepository {
404
402
  'workPerformed.identifier': { $exists: true, $in: workPerformedIdentifierIn }
405
403
  });
406
404
  }
407
- const workPerformedVersionEq = (_33 = (_32 = params.workPerformed) === null || _32 === void 0 ? void 0 : _32.version) === null || _33 === void 0 ? void 0 : _33.$eq;
405
+ const workPerformedVersionEq = (_34 = (_33 = params.workPerformed) === null || _33 === void 0 ? void 0 : _33.version) === null || _34 === void 0 ? void 0 : _34.$eq;
408
406
  if (typeof workPerformedVersionEq === 'string') {
409
407
  andConditions.push({
410
408
  'workPerformed.version': { $exists: true, $eq: workPerformedVersionEq }
411
409
  });
412
410
  }
413
- const videoFormatTypeOfEq = (_35 = (_34 = params.videoFormat) === null || _34 === void 0 ? void 0 : _34.typeOf) === null || _35 === void 0 ? void 0 : _35.$eq;
411
+ const videoFormatTypeOfEq = (_36 = (_35 = params.videoFormat) === null || _35 === void 0 ? void 0 : _35.typeOf) === null || _36 === void 0 ? void 0 : _36.$eq;
414
412
  if (typeof videoFormatTypeOfEq === 'string') {
415
413
  andConditions.push({
416
414
  'videoFormat.typeOf': {
@@ -419,7 +417,7 @@ class MongoRepository {
419
417
  }
420
418
  });
421
419
  }
422
- const videoFormatTypeOfIn = (_37 = (_36 = params.videoFormat) === null || _36 === void 0 ? void 0 : _36.typeOf) === null || _37 === void 0 ? void 0 : _37.$in;
420
+ const videoFormatTypeOfIn = (_38 = (_37 = params.videoFormat) === null || _37 === void 0 ? void 0 : _37.typeOf) === null || _38 === void 0 ? void 0 : _38.$in;
423
421
  if (Array.isArray(videoFormatTypeOfIn)) {
424
422
  andConditions.push({
425
423
  'videoFormat.typeOf': {
@@ -428,7 +426,7 @@ class MongoRepository {
428
426
  }
429
427
  });
430
428
  }
431
- const soundFormatTypeOfEq = (_39 = (_38 = params.soundFormat) === null || _38 === void 0 ? void 0 : _38.typeOf) === null || _39 === void 0 ? void 0 : _39.$eq;
429
+ const soundFormatTypeOfEq = (_40 = (_39 = params.soundFormat) === null || _39 === void 0 ? void 0 : _39.typeOf) === null || _40 === void 0 ? void 0 : _40.$eq;
432
430
  if (typeof soundFormatTypeOfEq === 'string') {
433
431
  andConditions.push({
434
432
  'soundFormat.typeOf': {
@@ -437,7 +435,7 @@ class MongoRepository {
437
435
  }
438
436
  });
439
437
  }
440
- const soundFormatTypeOfIn = (_41 = (_40 = params.soundFormat) === null || _40 === void 0 ? void 0 : _40.typeOf) === null || _41 === void 0 ? void 0 : _41.$in;
438
+ const soundFormatTypeOfIn = (_42 = (_41 = params.soundFormat) === null || _41 === void 0 ? void 0 : _41.typeOf) === null || _42 === void 0 ? void 0 : _42.$in;
441
439
  if (Array.isArray(soundFormatTypeOfIn)) {
442
440
  andConditions.push({
443
441
  'soundFormat.typeOf': {
@@ -592,6 +590,7 @@ class MongoRepository {
592
590
  const _a = params.attributes, { typeOf } = _a, updateFields = __rest(_a, ["typeOf"]);
593
591
  doc = yield this.eventModel.findOneAndUpdate({
594
592
  _id: params.id,
593
+ 'project.id': { $eq: params.project.id },
595
594
  typeOf: params.attributes.typeOf
596
595
  }, {
597
596
  $set: updateFields
@@ -694,6 +693,7 @@ class MongoRepository {
694
693
  const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
695
694
  const id = uniqid();
696
695
  doc = yield this.eventModel.findOneAndUpdate({
696
+ 'project.id': { $eq: params.attributes.project.id },
697
697
  typeOf: params.attributes.typeOf,
698
698
  // 追加特性をキーに更新
699
699
  additionalProperty: {
@@ -717,14 +717,16 @@ class MongoRepository {
717
717
  return doc.toObject();
718
718
  });
719
719
  }
720
- count(params) {
721
- return __awaiter(this, void 0, void 0, function* () {
722
- const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
723
- return this.eventModel.countDocuments({ $and: conditions })
724
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
725
- .exec();
726
- });
727
- }
720
+ // public async count<T extends factory.eventType>(
721
+ // params: ISearchConditions<T>
722
+ // ): Promise<number> {
723
+ // const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
724
+ // return this.eventModel.countDocuments(
725
+ // { $and: conditions }
726
+ // )
727
+ // .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
728
+ // .exec();
729
+ // }
728
730
  /**
729
731
  * イベントを検索する
730
732
  */
@@ -772,24 +774,39 @@ class MongoRepository {
772
774
  .exec();
773
775
  });
774
776
  }
775
- findById(params, projection) {
776
- return __awaiter(this, void 0, void 0, function* () {
777
- const positiveProjectionExists = (projection !== undefined && projection !== null)
778
- ? Object.values(projection)
779
- .some((value) => value !== 0)
780
- : false;
781
- const doc = yield this.eventModel.findOne({ _id: params.id },
782
- // :1対応(2023-01-25~)
783
- (positiveProjectionExists)
784
- ? projection
785
- : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }))
786
- .exec();
787
- if (doc === null) {
788
- throw new factory.errors.NotFound(this.eventModel.modelName);
789
- }
790
- return doc.toObject();
791
- });
792
- }
777
+ // searchに置き換え(2023-07-13~)
778
+ // public async findById<T extends factory.eventType>(
779
+ // params: {
780
+ // project: { id: string };
781
+ // id: string;
782
+ // },
783
+ // projection?: IProjection
784
+ // ): Promise<factory.event.IEvent<T>> {
785
+ // const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
786
+ // ? Object.values(projection)
787
+ // .some((value) => value !== 0)
788
+ // : false;
789
+ // const doc = await this.eventModel.findOne(
790
+ // {
791
+ // _id: params.id,
792
+ // 'project.id': { $eq: params.project.id }
793
+ // },
794
+ // // :1対応(2023-01-25~)
795
+ // (positiveProjectionExists)
796
+ // ? projection
797
+ // : {
798
+ // ...projection,
799
+ // __v: 0,
800
+ // createdAt: 0,
801
+ // updatedAt: 0
802
+ // }
803
+ // )
804
+ // .exec();
805
+ // if (doc === null) {
806
+ // throw new factory.errors.NotFound(this.eventModel.modelName);
807
+ // }
808
+ // return doc.toObject();
809
+ // }
793
810
  findMinimizedIndividualEventById(params) {
794
811
  return __awaiter(this, void 0, void 0, function* () {
795
812
  const doc = yield this.eventModel.findOne({ _id: params.id }, exports.PROJECTION_MINIMIZED_EVENT)
@@ -805,13 +822,19 @@ class MongoRepository {
805
822
  */
806
823
  cancel(params) {
807
824
  return __awaiter(this, void 0, void 0, function* () {
808
- yield this.eventModel.findOneAndUpdate({ _id: params.id }, { eventStatus: factory.eventStatusType.EventCancelled })
825
+ yield this.eventModel.findOneAndUpdate({
826
+ _id: params.id,
827
+ 'project.id': { $eq: params.project.id }
828
+ }, { eventStatus: factory.eventStatusType.EventCancelled })
809
829
  .exec();
810
830
  });
811
831
  }
812
832
  deleteById(params) {
813
833
  return __awaiter(this, void 0, void 0, function* () {
814
- yield this.eventModel.findOneAndDelete({ _id: params.id })
834
+ yield this.eventModel.findOneAndDelete({
835
+ _id: params.id,
836
+ 'project.id': { $eq: params.project.id }
837
+ })
815
838
  .exec();
816
839
  });
817
840
  }
@@ -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',
@@ -379,16 +379,6 @@ function cancelDeletedEvents(params) {
379
379
  return (repos) => __awaiter(this, void 0, void 0, function* () {
380
380
  // distinctでidのみ取得(2023-01-25~)
381
381
  // COAから削除されたイベントをキャンセル済ステータスへ変更
382
- // const ids = await repos.event.search<factory.eventType.ScreeningEvent>({
383
- // project: { id: { $eq: params.project.id } },
384
- // typeOf: factory.eventType.ScreeningEvent,
385
- // superEvent: {
386
- // locationBranchCodes: [params.locationBranchCode]
387
- // },
388
- // startFrom: params.targetImportFrom,
389
- // startThrough: params.targetImportThrough
390
- // })
391
- // .then((events) => events.map((e) => e.id));
392
382
  const ids = yield repos.event.searchIds({
393
383
  project: { id: { $eq: params.project.id } },
394
384
  typeOf: factory.eventType.ScreeningEvent,
@@ -403,7 +393,10 @@ function cancelDeletedEvents(params) {
403
393
  debug(`cancelling ${cancelledIds.length} events...`);
404
394
  for (const cancelledId of cancelledIds) {
405
395
  try {
406
- yield repos.event.cancel({ id: cancelledId });
396
+ yield repos.event.cancel({
397
+ id: cancelledId,
398
+ project: { id: params.project.id }
399
+ });
407
400
  }
408
401
  catch (error) {
409
402
  // tslint:disable-next-line:no-single-line-block-comment
@@ -53,7 +53,21 @@ function searchEventTicketOffersByEvent(params) {
53
53
  let videoFormatTypes = [];
54
54
  if (event.typeOf === factory.eventType.ScreeningEvent) {
55
55
  // 取得属性最適化(2023-01-25~)
56
- const superEvent = yield repos.event.findById({ id: event.superEvent.id }, { soundFormat: 1, videoFormat: 1 });
56
+ // const superEvent: Pick<factory.event.IEvent<factory.eventType.ScreeningEventSeries>, 'soundFormat' | 'videoFormat'> =
57
+ // await repos.event.findById<factory.eventType.ScreeningEventSeries>(
58
+ // { id: event.superEvent.id },
59
+ // { soundFormat: 1, videoFormat: 1 }
60
+ // );
61
+ const superEvents = yield repos.event.search({
62
+ limit: 1,
63
+ page: 1,
64
+ id: { $eq: event.superEvent.id },
65
+ typeOf: factory.eventType.ScreeningEventSeries
66
+ }, { soundFormat: 1, videoFormat: 1 });
67
+ const superEvent = superEvents.shift();
68
+ if (superEvent === undefined) {
69
+ throw new factory.errors.NotFound(factory.eventType.ScreeningEventSeries);
70
+ }
57
71
  soundFormatTypes = (Array.isArray(superEvent.soundFormat)) ? superEvent.soundFormat.map((f) => f.typeOf) : [];
58
72
  videoFormatTypes = (Array.isArray(superEvent.videoFormat)) ? superEvent.videoFormat.map((f) => f.typeOf) : [];
59
73
  }
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.315.0-alpha.0",
13
- "@cinerino/sdk": "3.160.0-alpha.2",
12
+ "@chevre/factory": "4.315.0-alpha.1",
13
+ "@cinerino/sdk": "3.160.0-alpha.3",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -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.8"
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);
@@ -1,75 +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
- startDate: {
22
- $gte: moment()
23
- .add(-1, 'month')
24
- .toDate()
25
- }
26
- // _id: { $eq: 'al6aff83w' }
27
- },
28
- {
29
- // _id: 1,
30
- }
31
- );
32
- console.log('events found');
33
-
34
- let i = 0;
35
- let updateCount = 0;
36
- await cursor.eachAsync(async (doc) => {
37
- i += 1;
38
- const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
39
-
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);
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
- });
63
- updateCount += 1;
64
- console.log(
65
- 'updated...', event.project.id, event.id, event.startDate, i);
66
- }
67
- });
68
-
69
- console.log(i, 'events checked');
70
- console.log(updateCount, 'events updated');
71
- }
72
-
73
- main()
74
- .then()
75
- .catch(console.error);
@@ -1,64 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- const project = { id: String(process.env.PROJECT_ID) };
7
- const DELETING_PROPERTY_NAME: string = 'COA_ENDPOINT';
8
-
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const eventRepo = new chevre.repository.Event(mongoose.connection);
13
-
14
- const cursor = eventRepo.getCursor(
15
- {
16
- 'project.id': { $eq: project.id },
17
- typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries }
18
- // typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
19
- // startDate: { $gte: new Date() }
20
- },
21
- {
22
- // _id: 1,
23
- }
24
- );
25
- console.log('events found');
26
-
27
- let i = 0;
28
- let updateCount = 0;
29
- await cursor.eachAsync(async (doc) => {
30
- i += 1;
31
- const event: chevre.factory.event.IEvent<chevre.factory.eventType> = doc.toObject();
32
-
33
- const coaEndpointPropert = event.additionalProperty?.find((p) => p.name === DELETING_PROPERTY_NAME);
34
-
35
- if (coaEndpointPropert !== undefined) {
36
- const newAdditionalProperty: chevre.factory.propertyValue.IPropertyValue<string>[] =
37
- (Array.isArray(event.additionalProperty))
38
- ? event.additionalProperty.filter((p) => {
39
- return p.name !== DELETING_PROPERTY_NAME;
40
- })
41
- : [];
42
- console.log(
43
- 'updating event...', event.project.id, event.id, event.startDate, coaEndpointPropert.value, newAdditionalProperty, i);
44
- await eventRepo.updatePartiallyById({
45
- id: event.id,
46
- attributes: <any>{
47
- typeOf: event.typeOf,
48
- additionalProperty: newAdditionalProperty
49
- }
50
- });
51
- updateCount += 1;
52
- console.log('event updated', event.project.id, event.id, event.startDate, i);
53
- } else {
54
- console.log('no property...', event.project.id, event.id, event.startDate, i);
55
- }
56
- });
57
-
58
- console.log(i, 'events checked');
59
- console.log(updateCount, 'events updated');
60
- }
61
-
62
- main()
63
- .then()
64
- .catch(console.error);
@@ -1,79 +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 = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
8
-
9
- const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
10
-
11
- async function main() {
12
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
-
14
- const eventRepo = new chevre.repository.Event(mongoose.connection);
15
-
16
- const cursor = eventRepo.getCursor(
17
- {
18
- 'project.id': {
19
- // $eq: project.id,
20
- $ne: EXCLUDED_PROJECT_ID
21
- },
22
- typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
23
- 'workPerformed.version': { $exists: false }
24
- // _id: { $eq: 'bl7ed6sq9' }
25
- },
26
- {
27
- _id: 1,
28
- workPerformed: 1,
29
- project: 1,
30
- location: 1,
31
- startDate: 1,
32
- typeOf: 1
33
- }
34
- );
35
- console.log('events found');
36
-
37
- let i = 0;
38
- let updateCount = 0;
39
- await cursor.eachAsync(async (doc) => {
40
- i += 1;
41
- const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
42
- const version = event.workPerformed.version;
43
-
44
- const alreadyMigrated = typeof version === 'string' && version.length > 0;
45
-
46
- if (alreadyMigrated) {
47
- console.log('alreadyMigrated.', event.project.id, event.id, event.startDate, version, i);
48
- } else {
49
- // 既存施設コンテンツバージョンを検索
50
- const { maxVersion } = await eventRepo.aggregateScreeningEventMaxVersion({
51
- project: { id: { $eq: event.project.id } },
52
- workPerformed: { identifier: { $eq: event.workPerformed.identifier } },
53
- location: { branchCode: { $in: [event.location.branchCode] } }
54
- });
55
- console.log('maxVersion:', maxVersion);
56
-
57
- const newVersion: string = `${Number(maxVersion) + 1}`;
58
- console.log('updating event...', event.project.id, event.id, event.startDate, newVersion, i);
59
- await eventRepo.updatePartiallyById({
60
- id: event.id,
61
- attributes: <any>{
62
- typeOf: event.typeOf,
63
- 'workPerformed.version': newVersion
64
- }
65
- });
66
- updateCount += 1;
67
- console.log('updated.', event.project.id, event.id, event.startDate, newVersion, i);
68
- }
69
- });
70
-
71
- console.log(i, 'events checked');
72
- console.log(updateCount, 'events updated');
73
- }
74
-
75
- main()
76
- .then(() => {
77
- console.log('success!');
78
- })
79
- .catch(console.error);