@chevre/domain 22.5.0-alpha.21 → 22.5.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+ // const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const sellerRepo = await chevre.repository.Seller.createInstance(mongoose.connection);
14
+
15
+ const cursor = sellerRepo.getCursor(
16
+ {
17
+ _id: { $eq: '59d20831e53ebc2b4e774466' }
18
+ },
19
+ {
20
+ _id: 1,
21
+ makesOffer: 1,
22
+ startDate: 1,
23
+ project: 1,
24
+ typeOf: 1
25
+ }
26
+ );
27
+ console.log('docs found');
28
+
29
+ let i = 0;
30
+ let updateCount = 0;
31
+ await cursor.eachAsync(async (doc) => {
32
+ i += 1;
33
+ const seller: Pick<
34
+ chevre.factory.seller.ISeller,
35
+ 'id' | 'typeOf' | 'name' | 'project' | 'makesOffer'
36
+ > = doc.toObject();
37
+
38
+ console.log(
39
+ 'alreadyMigrated?', seller.project.id, seller.typeOf, seller.id, seller.name?.ja, i);
40
+ const originMakesOffer = seller.makesOffer;
41
+ const alreadyMigrated = !Array.isArray(originMakesOffer)
42
+ || (Array.isArray(originMakesOffer)
43
+ && originMakesOffer.every(
44
+ ({ availableAtOrFrom }) => !Array.isArray(availableAtOrFrom) && typeof availableAtOrFrom?.id === 'string'
45
+ ));
46
+
47
+ if (alreadyMigrated) {
48
+ console.log(
49
+ 'already migrated.', seller.project.id, seller.typeOf, seller.id, seller.name?.ja, i);
50
+ } else {
51
+ if (Array.isArray(originMakesOffer)) {
52
+ const newMakesOffer: chevre.factory.seller.IMakesOffer[] = originMakesOffer.map((offer) => {
53
+ let newAvailableAtOrFrom: { id: string } | undefined;
54
+ if (Array.isArray(offer.availableAtOrFrom)) {
55
+ newAvailableAtOrFrom = offer.availableAtOrFrom.at(0);
56
+ }
57
+ if (newAvailableAtOrFrom === undefined) {
58
+ throw new Error('newAvailableAtOrFrom undefined');
59
+ }
60
+
61
+ return {
62
+ ...offer,
63
+ availableAtOrFrom: newAvailableAtOrFrom
64
+ };
65
+ });
66
+ console.log(
67
+ 'updating project...',
68
+ seller.project.id, seller.typeOf, seller.id, seller.name?.ja, i, newMakesOffer);
69
+ // await sellerRepo.save({
70
+ // id: String(seller.id),
71
+ // attributes: <any>{
72
+ // makesOffer: newMakesOffer
73
+ // }
74
+ // });
75
+ updateCount += 1;
76
+ console.log(
77
+ 'updated.',
78
+ seller.project.id, seller.typeOf, seller.id, seller.name?.ja, i);
79
+ }
80
+ }
81
+ });
82
+
83
+ console.log(i, 'docs checked');
84
+ console.log(updateCount, 'docs updated');
85
+ }
86
+
87
+ main()
88
+ .then()
89
+ .catch(console.error);
@@ -36,8 +36,7 @@ async function main() {
36
36
  // paymentAccepted: { paymentMethodType: { $eq: 'Cash' } },
37
37
  // hasMerchantReturnPolicy: { applicablePaymentMethod: {} }
38
38
  },
39
- [],
40
- ['hasMerchantReturnPolicy', 'additionalProperty', 'project', 'name', 'typeOf', 'url', 'telephone']
39
+ ['id', 'typeOf']
41
40
  );
42
41
  console.log('sellers found', sellers, sellers[0]?.hasMerchantReturnPolicy);
43
42
  console.log(sellers.length, 'sellers found');
@@ -4,6 +4,8 @@ import * as mongoose from 'mongoose';
4
4
 
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
+ const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
8
+
7
9
  async function main() {
8
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
11
 
@@ -12,6 +14,7 @@ async function main() {
12
14
  let updateResult: any;
13
15
  updateResult = await eventRepo.unsetUnnecessaryFields({
14
16
  filter: {
17
+ 'project.id': { $ne: excludedProject.id },
15
18
  'offers.validFrom': { $exists: true },
16
19
  startDate: {
17
20
  $gte: moment()
@@ -6,6 +6,7 @@ const PROJECT_ID = String(process.env.PROJECT_ID);
6
6
 
7
7
  // tslint:disable-next-line:max-func-body-length
8
8
  async function main() {
9
+ const now = new Date();
9
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
11
 
11
12
  const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
@@ -14,8 +15,8 @@ async function main() {
14
15
  {
15
16
  additionalProperty: [
16
17
  {
17
- name: 'createId',
18
- value: 'akeuu512i-10-202409151130-01'
18
+ name: 'sampleCreateId',
19
+ value: 'akeuu512i-202410171410-01'
19
20
  }
20
21
  ],
21
22
  project: {
@@ -23,10 +24,10 @@ async function main() {
23
24
  typeOf: chevre.factory.organizationType.Project
24
25
  },
25
26
  typeOf: chevre.factory.eventType.ScreeningEvent,
26
- doorTime: new Date('2024-09-15T02:30:00.000Z'),
27
- endDate: new Date('2024-09-15T11:45:00.000Z'),
28
- // eventStatus: chevre.factory.eventStatusType.EventScheduled,
29
- eventStatus: chevre.factory.eventStatusType.EventCancelled,
27
+ doorTime: new Date('2024-10-17T05:30:00.000Z'),
28
+ endDate: new Date('2024-10-17T05:45:00.000Z'),
29
+ eventStatus: chevre.factory.eventStatusType.EventScheduled,
30
+ // eventStatus: chevre.factory.eventStatusType.EventCancelled,
30
31
  location: {
31
32
  typeOf: chevre.factory.placeType.ScreeningRoom,
32
33
  branchCode: '10',
@@ -106,7 +107,16 @@ async function main() {
106
107
  ja: 'シネモーション赤坂',
107
108
  en: 'CineMotion Akasaka'
108
109
  },
109
- makesOffer: []
110
+ makesOffer: [
111
+ {
112
+ typeOf: chevre.factory.offerType.Offer,
113
+ availableAtOrFrom: { id: '51qbjcfr72h62m06vtv5kkhgje' },
114
+ availabilityEnds: now,
115
+ availabilityStarts: now,
116
+ validFrom: now,
117
+ validThrough: now
118
+ }
119
+ ]
110
120
  },
111
121
  unacceptedPaymentMethod: [
112
122
  'MovieTicket'
@@ -115,7 +125,7 @@ async function main() {
115
125
  organizer: {
116
126
  id: '59d20831e53ebc2b4e774466'
117
127
  },
118
- startDate: new Date('2024-09-15T02:30:00.000Z'),
128
+ startDate: new Date('2024-10-17T05:30:00.000Z'),
119
129
  superEvent: {
120
130
  typeOf: chevre.factory.eventType.ScreeningEventSeries,
121
131
  id: 'akeuu512i',
@@ -163,13 +173,14 @@ async function main() {
163
173
  }
164
174
  }
165
175
  ],
166
- additionalPropertyFilter: { name: 'createId' },
176
+ additionalPropertyFilter: { name: 'sampleCreateId' },
167
177
  eventSeries: {
168
178
  id: 'akeuu512i'
169
179
  },
170
180
  screeningRoom: {
171
181
  branchCode: '10'
172
- }
182
+ },
183
+ options: { updateOffersSeller: false }
173
184
  });
174
185
  // tslint:disable-next-line:no-null-keyword
175
186
  console.dir(result, { depth: null });
@@ -116,6 +116,9 @@ export declare class EventRepo {
116
116
  */
117
117
  branchCode: string;
118
118
  };
119
+ options: {
120
+ updateOffersSeller: boolean;
121
+ };
119
122
  }): Promise<{
120
123
  bulkWriteResult: BulkWriteResult;
121
124
  modifiedEvents: {
@@ -387,8 +387,10 @@ class EventRepo {
387
387
  * 施設コンテンツとルームは1つに限定
388
388
  * 存在すれば、特定の属性のみ更新する
389
389
  */
390
+ // tslint:disable-next-line:max-func-body-length
390
391
  upsertManyByAdditionalProperty(params) {
391
392
  return __awaiter(this, void 0, void 0, function* () {
393
+ const { updateOffersSeller } = params.options;
392
394
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
393
395
  const bulkWriteOps = [];
394
396
  const additionalProperties = [];
@@ -406,7 +408,7 @@ class EventRepo {
406
408
  additionalProperties.push({ name: additionalPropertyFilter.name, value: additionalPropertyValue });
407
409
  const { coaInfo, // ←適用しない
408
410
  maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation, // ←適用しない
409
- eventStatus, superEvent } = creatingEventParams, setOnInsertFields = __rest(creatingEventParams, ["coaInfo", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation", "eventStatus", "superEvent"]);
411
+ eventStatus, superEvent, offers } = creatingEventParams, setOnInsertFields = __rest(creatingEventParams, ["coaInfo", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation", "eventStatus", "superEvent", "offers"]);
410
412
  if (superEvent.id !== eventSeries.id) {
411
413
  throw new factory.errors.Argument('superEvent.id', 'superEvent.id not matched');
412
414
  }
@@ -424,17 +426,23 @@ class EventRepo {
424
426
  },
425
427
  'superEvent.id': { $exists: true, $eq: superEvent.id } // add superEvent.id(2024-09-15~)
426
428
  };
427
- const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() });
429
+ let setOnInsert;
430
+ if (updateOffersSeller) {
431
+ setOnInsert = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, setOnInsertFields), { 'offers.typeOf': offers.typeOf, 'offers.eligibleQuantity': offers.eligibleQuantity, 'offers.itemOffered': offers.itemOffered }), (offers.offeredThrough !== undefined) ? { 'offers.offeredThrough': offers.offeredThrough } : undefined), (offers.unacceptedPaymentMethod !== undefined)
432
+ ? { 'offers.unacceptedPaymentMethod': offers.unacceptedPaymentMethod }
433
+ : undefined), { _id: uniqid() });
434
+ }
435
+ else {
436
+ setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { offers, _id: uniqid() });
437
+ }
428
438
  bulkWriteOps.push({
429
439
  updateOne: {
430
440
  filter,
431
441
  update: {
432
442
  $setOnInsert: setOnInsert,
433
443
  // 変更可能な属性のみ上書き
434
- $set: {
435
- eventStatus,
436
- superEvent // add superEvent(2024-09-15~)
437
- }
444
+ $set: Object.assign({ eventStatus,
445
+ superEvent }, (updateOffersSeller) ? { 'offers.seller': offers.seller } : undefined)
438
446
  },
439
447
  upsert: true
440
448
  }
@@ -672,7 +680,13 @@ class EventRepo {
672
680
  positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PUBLIC_PROJECT_FIELDS.includes(key));
673
681
  projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
674
682
  if (includeOffers) {
675
- projection = Object.assign(Object.assign(Object.assign({}, projection), { 'offers.typeOf': 1, 'offers.availabilityEnds': 1, 'offers.availabilityStarts': 1, 'offers.eligibleQuantity': 1, 'offers.itemOffered': 1, 'offers.offeredThrough': 1, 'offers.validFrom': 1, 'offers.validThrough': 1, 'offers.unacceptedPaymentMethod': 1, 'offers.seller.typeOf': 1, 'offers.seller.id': 1, 'offers.seller.name': 1 }), (includeSellerMakesOffer)
683
+ projection = Object.assign(Object.assign(Object.assign({}, projection), { 'offers.typeOf': 1,
684
+ // 'offers.availabilityEnds': 1,
685
+ // 'offers.availabilityStarts': 1,
686
+ 'offers.eligibleQuantity': 1, 'offers.itemOffered': 1, 'offers.offeredThrough': 1,
687
+ // 'offers.validFrom': 1,
688
+ // 'offers.validThrough': 1,
689
+ 'offers.unacceptedPaymentMethod': 1, 'offers.seller.typeOf': 1, 'offers.seller.id': 1, 'offers.seller.name': 1 }), (includeSellerMakesOffer)
676
690
  ? Object.assign({}, (Array.isArray(sellerMakesOfferAvailableAtIn))
677
691
  ? {
678
692
  'offers.seller.makesOffer': {
@@ -165,51 +165,6 @@ const indexes = [
165
165
  { endDate: 1, startDate: 1 },
166
166
  { name: 'searchByEndDate' }
167
167
  ],
168
- [
169
- { 'offers.availabilityEnds': 1, startDate: 1 },
170
- {
171
- name: 'searchByOffersAvailabilityEnds-v2',
172
- partialFilterExpression: {
173
- 'offers.availabilityEnds': { $exists: true }
174
- }
175
- }
176
- ],
177
- [
178
- { 'offers.availabilityStarts': 1, startDate: 1 },
179
- {
180
- name: 'searchByOffersAvailabilityStarts-v2',
181
- partialFilterExpression: {
182
- 'offers.availabilityStarts': { $exists: true }
183
- }
184
- }
185
- ],
186
- [
187
- { 'offers.validThrough': 1, startDate: 1 },
188
- {
189
- name: 'searchByOffersValidThrough-v2',
190
- partialFilterExpression: {
191
- 'offers.validThrough': { $exists: true }
192
- }
193
- }
194
- ],
195
- [
196
- { 'offers.validFrom': 1, startDate: 1 },
197
- {
198
- name: 'searchByOffersValidFrom-v2',
199
- partialFilterExpression: {
200
- 'offers.validFrom': { $exists: true }
201
- }
202
- }
203
- ],
204
- [
205
- { 'offers.id': 1, startDate: 1 },
206
- {
207
- name: 'searchByOffersId-v2',
208
- partialFilterExpression: {
209
- 'offers.id': { $exists: true }
210
- }
211
- }
212
- ],
213
168
  [
214
169
  {
215
170
  'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': 1,
@@ -75,7 +75,7 @@ export declare class SellerRepo {
75
75
  /**
76
76
  * 販売者検索
77
77
  */
78
- projectFields(conditions: factory.seller.ISearchConditions & IMemberSearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<ISellerWithId[]>;
78
+ projectFields(conditions: factory.seller.ISearchConditions & IMemberSearchConditions, inclusion: IKeyOfProjection[]): Promise<ISellerWithId[]>;
79
79
  /**
80
80
  * 販売者を削除する
81
81
  */
@@ -274,7 +274,7 @@ class SellerRepo {
274
274
  /**
275
275
  * 販売者検索
276
276
  */
277
- projectFields(conditions, inclusion, exclusion) {
277
+ projectFields(conditions, inclusion) {
278
278
  var _a;
279
279
  return __awaiter(this, void 0, void 0, function* () {
280
280
  const andConditions = SellerRepo.CREATE_MONGO_CONDITIONS(conditions);
@@ -283,37 +283,18 @@ class SellerRepo {
283
283
  positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
284
284
  }
285
285
  else {
286
- if (Array.isArray(exclusion) && exclusion.length > 0) {
287
- positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
288
- }
286
+ // discontinue(2024-10-19~)
287
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
288
+ // positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
289
+ // }
289
290
  }
290
291
  const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
291
- // let projection: { [key: string]: number } = {};
292
- // if (Array.isArray(inclusion) && inclusion.length > 0) {
293
- // inclusion.forEach((field) => {
294
- // projection[field] = 1;
295
- // });
296
- // } else {
297
- // projection = {
298
- // __v: 0,
299
- // createdAt: 0,
300
- // updatedAt: 0,
301
- // paymentAccepted: 0 // 除外(2023-12-01~)
302
- // };
303
- // if (Array.isArray(exclusion) && exclusion.length > 0) {
304
- // exclusion.forEach((field) => {
305
- // projection[field] = 0;
306
- // });
307
- // }
308
- // }
309
292
  const query = this.sellerModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
310
293
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
311
294
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
312
295
  query.limit(conditions.limit)
313
296
  .skip(conditions.limit * (page - 1));
314
297
  }
315
- // tslint:disable-next-line:no-single-line-block-comment
316
- /* istanbul ignore else */
317
298
  if (((_a = conditions.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
318
299
  query.sort({ branchCode: conditions.sort.branchCode });
319
300
  }
@@ -167,7 +167,7 @@ function processUpdateMovieTheater(params) {
167
167
  page: 1,
168
168
  project: { id: { $eq: params.project.id } },
169
169
  branchCode: { $eq: params.locationBranchCode }
170
- }, ['id'], []);
170
+ }, ['id']);
171
171
  const sellerWithSameBranchCode = sellersWithSameBranchCode.shift();
172
172
  if (typeof (sellerWithSameBranchCode === null || sellerWithSameBranchCode === void 0 ? void 0 : sellerWithSameBranchCode.id) !== 'string') {
173
173
  throw new factory.errors.NotFound('Seller', `Seller with branchCode '${params.locationBranchCode}' not found`);
@@ -32,7 +32,7 @@ function start(params) {
32
32
  limit: 1,
33
33
  page: 1,
34
34
  id: { $eq: params.seller.id }
35
- }, ['name', 'typeOf'], []);
35
+ }, ['name', 'typeOf']);
36
36
  const seller = sellers.shift();
37
37
  if (seller === undefined) {
38
38
  throw new factory.errors.NotFound(factory.organizationType.Corporation);
@@ -72,12 +72,14 @@ function validateStartRequest(params) {
72
72
  page: 1,
73
73
  project: { id: { $eq: params.project.id } },
74
74
  id: { $eq: params.seller.id }
75
- }, ['name', 'project', 'typeOf', 'makesOffer', 'additionalProperty'], [])).shift();
75
+ }, ['name', 'project', 'typeOf', 'makesOffer', 'additionalProperty'])).shift();
76
76
  if (seller === undefined) {
77
77
  throw new factory.errors.NotFound(factory.organizationType.Corporation);
78
78
  }
79
+ // support non-array(2024-10-19~)
79
80
  const sellerMakesOffer = (_b = seller.makesOffer) === null || _b === void 0 ? void 0 : _b.find(({ availableAtOrFrom }) => {
80
- return availableAtOrFrom === null || availableAtOrFrom === void 0 ? void 0 : availableAtOrFrom.some(({ id }) => id === clientId);
81
+ return (Array.isArray(availableAtOrFrom) && (availableAtOrFrom === null || availableAtOrFrom === void 0 ? void 0 : availableAtOrFrom.some(({ id }) => id === clientId)))
82
+ || (!Array.isArray(availableAtOrFrom) && (availableAtOrFrom === null || availableAtOrFrom === void 0 ? void 0 : availableAtOrFrom.id) === clientId);
81
83
  });
82
84
  if (sellerMakesOffer === undefined) {
83
85
  throw new factory.errors.Argument('seller', 'seller makes no offers');
@@ -40,7 +40,7 @@ function preStart(params) {
40
40
  limit: 1,
41
41
  page: 1,
42
42
  id: { $eq: String(orders[0].seller.id) }
43
- }, ['name', 'project', 'hasMerchantReturnPolicy', 'typeOf'], []);
43
+ }, ['name', 'project', 'hasMerchantReturnPolicy', 'typeOf']);
44
44
  const seller = sellers.shift();
45
45
  if (seller === undefined) {
46
46
  throw new factory.errors.NotFound(factory.organizationType.Corporation);
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.386.0-alpha.9",
15
- "@cinerino/sdk": "10.13.0-alpha.11",
14
+ "@chevre/factory": "4.387.0-alpha.0",
15
+ "@cinerino/sdk": "10.13.0",
16
16
  "@motionpicture/coa-service": "9.5.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
18
18
  "@sendgrid/mail": "6.4.0",
@@ -108,5 +108,5 @@
108
108
  "postversion": "git push origin --tags",
109
109
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
110
110
  },
111
- "version": "22.5.0-alpha.21"
111
+ "version": "22.5.0-alpha.23"
112
112
  }