@chevre/domain 20.2.0-alpha.29 → 20.2.0-alpha.30

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,24 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const PROJECT_ID = process.env.PROJECT_ID;
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
+
11
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
12
+
13
+ const ids = await eventRepo.searchIds({
14
+ typeOf: chevre.factory.eventType.ScreeningEvent,
15
+ project: { id: { $eq: PROJECT_ID } },
16
+ id: { $in: ['al6afe7ad', 'al6afe7ae'] }
17
+ });
18
+ console.log(ids);
19
+ console.log(ids.length);
20
+ }
21
+
22
+ main()
23
+ .then(console.log)
24
+ .catch(console.error);
@@ -11,47 +11,27 @@ async function main() {
11
11
 
12
12
  const eventRepo = new chevre.repository.Event(mongoose.connection);
13
13
 
14
- const events = await eventRepo.search({
15
- limit: 100,
16
- page: 1,
17
- sort: { startDate: 1 },
18
- typeOf: chevre.factory.eventType.ScreeningEvent,
19
- project: { id: { $eq: PROJECT_ID } },
20
- offers: {
21
- seller: {
22
- makesOffer: {
23
- $elemMatch: {
24
- 'availableAtOrFrom.id': { $eq: '5h3gs22mu9j3ok7o63uog9o9i3' },
25
- availabilityEnds: {
26
- $gte: moment('2022-11-18T02:20:00.000Z')
27
- .toDate(),
28
- $lte: moment('2022-11-18T02:20:00.000Z')
29
- .toDate()
30
- },
31
- availabilityStarts: {
32
- $gte: moment('2022-11-15T15:00:00.000Z')
33
- .toDate(),
34
- $lte: moment('2022-11-15T15:00:00.000Z')
35
- .toDate()
36
- },
37
- validFrom: {
38
- $gte: moment('2022-11-15T15:00:00.000Z')
39
- .toDate(),
40
- $lte: moment('2022-11-15T15:00:00.000Z')
41
- .toDate()
42
- },
43
- validThrough: {
44
- $gte: moment('2022-11-18T02:20:00.000Z')
45
- .toDate(),
46
- $lte: moment('2022-11-18T02:20:00.000Z')
47
- .toDate()
48
- }
49
- }
50
- }
51
- }
14
+ const event = await eventRepo.findById(
15
+ { id: 'al6aff83y' },
16
+ {
17
+ name: 1
18
+ }
19
+ );
20
+ console.log('event found', event);
21
+
22
+ const events = await eventRepo.search(
23
+ {
24
+ limit: 100,
25
+ page: 1,
26
+ sort: { startDate: 1 },
27
+ typeOf: chevre.factory.eventType.ScreeningEvent,
28
+ project: { id: { $eq: PROJECT_ID } },
29
+ id: { $in: ['al6aff83y'] }
52
30
  },
53
- id: { $in: ['al6aff83y'] }
54
- });
31
+ {
32
+ name: 1
33
+ }
34
+ );
55
35
  console.log(events);
56
36
  console.log(events.length);
57
37
  }
@@ -52,7 +52,11 @@ interface IStatus {
52
52
  export interface IAggregateEvent {
53
53
  statuses: IStatus[];
54
54
  }
55
+ interface IProjection {
56
+ [key: string]: number;
57
+ }
55
58
  export import IMinimizedIndividualEvent = EventFactory.IMinimizedIndividualEvent;
59
+ export declare const PROJECTION_MINIMIZED_EVENT: IProjection;
56
60
  /**
57
61
  * イベントリポジトリ
58
62
  */
@@ -77,17 +81,13 @@ export declare class MongoRepository {
77
81
  save<T extends factory.eventType>(params: {
78
82
  id?: string;
79
83
  attributes: factory.event.IAttributes<T>;
80
- $unset?: {
81
- [key: string]: number;
82
- };
84
+ $unset?: IProjection;
83
85
  upsert?: boolean;
84
86
  }): Promise<factory.event.IEvent<T>>;
85
87
  saveMany<T extends factory.eventType>(params: {
86
88
  id?: string;
87
89
  attributes: factory.event.IAttributes<T>;
88
- $unset?: {
89
- [key: string]: number;
90
- };
90
+ $unset?: IProjection;
91
91
  upsert?: boolean;
92
92
  }[]): Promise<void>;
93
93
  save4ttts(params: {
@@ -98,14 +98,11 @@ export declare class MongoRepository {
98
98
  /**
99
99
  * イベントを検索する
100
100
  */
101
- search<T extends factory.eventType>(params: ISearchConditions<T>, projection?: {
102
- [key: string]: number;
103
- }): Promise<factory.event.IEvent<T>[]>;
101
+ search<T extends factory.eventType>(params: ISearchConditions<T>, projection?: IProjection): Promise<factory.event.IEvent<T>[]>;
102
+ searchIds<T extends factory.eventType>(params: ISearchConditions<T>): Promise<string[]>;
104
103
  findById<T extends factory.eventType>(params: {
105
104
  id: string;
106
- }, projection?: {
107
- [key: string]: number;
108
- }): Promise<factory.event.IEvent<T>>;
105
+ }, projection?: IProjection): Promise<factory.event.IEvent<T>>;
109
106
  findMinimizedIndividualEventById<T extends factory.eventType.ScreeningEvent | factory.eventType.Event>(params: {
110
107
  id: string;
111
108
  }): Promise<IMinimizedIndividualEvent<T>>;
@@ -20,10 +20,26 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  return t;
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.MongoRepository = void 0;
23
+ exports.MongoRepository = exports.PROJECTION_MINIMIZED_EVENT = void 0;
24
24
  const uniqid = require("uniqid");
25
25
  const factory = require("../factory");
26
26
  const event_1 = require("./mongoose/model/event");
27
+ exports.PROJECTION_MINIMIZED_EVENT = {
28
+ project: 1,
29
+ _id: 1,
30
+ typeOf: 1,
31
+ additionalProperty: 1,
32
+ name: 1,
33
+ doorTime: 1,
34
+ endDate: 1,
35
+ eventStatus: 1,
36
+ location: 1,
37
+ startDate: 1,
38
+ superEvent: 1,
39
+ offers: 1,
40
+ coaInfo: 1,
41
+ identifier: 1
42
+ };
27
43
  /**
28
44
  * イベントリポジトリ
29
45
  */
@@ -588,7 +604,15 @@ class MongoRepository {
588
604
  search(params, projection) {
589
605
  return __awaiter(this, void 0, void 0, function* () {
590
606
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
591
- const query = this.eventModel.find({ $and: conditions }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
607
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
608
+ ? Object.keys(projection)
609
+ .some((key) => projection[key] !== 0)
610
+ : false;
611
+ const query = this.eventModel.find({ $and: conditions },
612
+ // :1対応(2023-01-25~)
613
+ (positiveProjectionExists)
614
+ ? projection
615
+ : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
592
616
  if (typeof params.limit === 'number') {
593
617
  const page = (typeof params.page === 'number') ? params.page : 1;
594
618
  query.limit(params.limit)
@@ -612,9 +636,25 @@ class MongoRepository {
612
636
  .then((docs) => docs.map((doc) => doc.toObject()));
613
637
  });
614
638
  }
639
+ searchIds(params) {
640
+ return __awaiter(this, void 0, void 0, function* () {
641
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
642
+ const query = this.eventModel.distinct('_id', { $and: conditions });
643
+ return query.setOptions({ maxTimeMS: 10000 })
644
+ .exec();
645
+ });
646
+ }
615
647
  findById(params, projection) {
616
648
  return __awaiter(this, void 0, void 0, function* () {
617
- const doc = yield this.eventModel.findOne({ _id: params.id }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
649
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
650
+ ? Object.keys(projection)
651
+ .some((key) => projection[key] !== 0)
652
+ : false;
653
+ const doc = yield this.eventModel.findOne({ _id: params.id },
654
+ // :1対応(2023-01-25~)
655
+ (positiveProjectionExists)
656
+ ? projection
657
+ : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
618
658
  .exec();
619
659
  if (doc === null) {
620
660
  throw new factory.errors.NotFound(this.eventModel.modelName);
@@ -624,22 +664,7 @@ class MongoRepository {
624
664
  }
625
665
  findMinimizedIndividualEventById(params) {
626
666
  return __awaiter(this, void 0, void 0, function* () {
627
- const doc = yield this.eventModel.findOne({ _id: params.id }, {
628
- project: 1,
629
- _id: 1,
630
- typeOf: 1,
631
- additionalProperty: 1,
632
- name: 1,
633
- doorTime: 1,
634
- endDate: 1,
635
- eventStatus: 1,
636
- location: 1,
637
- startDate: 1,
638
- superEvent: 1,
639
- offers: 1,
640
- coaInfo: 1,
641
- identifier: 1
642
- })
667
+ const doc = yield this.eventModel.findOne({ _id: params.id }, exports.PROJECTION_MINIMIZED_EVENT)
643
668
  .exec();
644
669
  if (doc === null) {
645
670
  throw new factory.errors.NotFound(this.eventModel.modelName);
@@ -652,9 +677,7 @@ class MongoRepository {
652
677
  */
653
678
  cancel(params) {
654
679
  return __awaiter(this, void 0, void 0, function* () {
655
- yield this.eventModel.findOneAndUpdate({
656
- _id: params.id
657
- }, { eventStatus: factory.eventStatusType.EventCancelled }, { new: true })
680
+ yield this.eventModel.findOneAndUpdate({ _id: params.id }, { eventStatus: factory.eventStatusType.EventCancelled })
658
681
  .exec();
659
682
  });
660
683
  }
@@ -15,6 +15,7 @@ exports.aggregateByEvent = exports.aggregateScreeningEvent = void 0;
15
15
  */
16
16
  const createDebug = require("debug");
17
17
  const moment = require("moment-timezone");
18
+ const event_1 = require("../../../repo/event");
18
19
  const factory = require("../../../factory");
19
20
  const debug = createDebug('chevre-domain:service');
20
21
  /**
@@ -38,6 +39,7 @@ function aggregateScreeningEvent(params) {
38
39
  .add(1, 'hour')
39
40
  .add(-1, 'second')
40
41
  .toDate();
42
+ // 取得属性最適化(2023-01-25~)
41
43
  aggregatingEvents = yield repos.event.search({
42
44
  limit: 100,
43
45
  page: 1,
@@ -47,7 +49,7 @@ function aggregateScreeningEvent(params) {
47
49
  startFrom: startFrom,
48
50
  startThrough: startThrough,
49
51
  location: { branchCode: { $eq: event.location.branchCode } }
50
- });
52
+ }, event_1.PROJECTION_MINIMIZED_EVENT);
51
53
  // ID指定されたイベントについてはEventScheduledでなくても集計したいので、集計対象を調整
52
54
  aggregatingEvents = aggregatingEvents.filter((e) => e.id !== event.id);
53
55
  aggregatingEvents = [event, ...aggregatingEvents];
@@ -356,8 +356,19 @@ function createScreeningEvents(params) {
356
356
  }
357
357
  function cancelDeletedEvents(params) {
358
358
  return (repos) => __awaiter(this, void 0, void 0, function* () {
359
+ // distinctでidのみ取得(2023-01-25~)
359
360
  // COAから削除されたイベントをキャンセル済ステータスへ変更
360
- const ids = yield repos.event.search({
361
+ // const ids = await repos.event.search<factory.eventType.ScreeningEvent>({
362
+ // project: { id: { $eq: params.project.id } },
363
+ // typeOf: factory.eventType.ScreeningEvent,
364
+ // superEvent: {
365
+ // locationBranchCodes: [params.locationBranchCode]
366
+ // },
367
+ // startFrom: params.targetImportFrom,
368
+ // startThrough: params.targetImportThrough
369
+ // })
370
+ // .then((events) => events.map((e) => e.id));
371
+ const ids = yield repos.event.searchIds({
361
372
  project: { id: { $eq: params.project.id } },
362
373
  typeOf: factory.eventType.ScreeningEvent,
363
374
  superEvent: {
@@ -365,8 +376,7 @@ function cancelDeletedEvents(params) {
365
376
  },
366
377
  startFrom: params.targetImportFrom,
367
378
  startThrough: params.targetImportThrough
368
- })
369
- .then((events) => events.map((e) => e.id));
379
+ });
370
380
  const idsShouldBe = params.idsShouldBe;
371
381
  const cancelledIds = difference(ids, idsShouldBe);
372
382
  debug(`cancelling ${cancelledIds.length} events...`);
@@ -16,7 +16,7 @@ declare type IAcceptedPaymentMethod = factory.paymentMethod.paymentCard.movieTic
16
16
  /**
17
17
  * 興行オファー検索
18
18
  */
19
- export declare function searchEventTicketOffers(params: {
19
+ declare function searchEventTicketOffers(params: {
20
20
  /**
21
21
  * どのイベントに対して
22
22
  */
@@ -73,4 +73,4 @@ export declare function searchEventTicketOffers(params: {
73
73
  kbnEisyahousiki: string;
74
74
  };
75
75
  }): ISearchEventTicketOffersOperation<factory.product.ITicketOffer[]>;
76
- export {};
76
+ export { searchEventTicketOffers };
@@ -20,8 +20,7 @@ function searchTransportationEventTicketOffers(params) {
20
20
  // tslint:disable-next-line:max-func-body-length
21
21
  return (repos) => __awaiter(this, void 0, void 0, function* () {
22
22
  var _a, _b, _c;
23
- // const screeningEvent = await repos.event.findById<factory.eventType.Event>({ id: params.eventId });
24
- const screeningEvent = yield repos.event.findMinimizedIndividualEventById({ id: params.eventId });
23
+ const screeningEvent = params.event;
25
24
  const soundFormatTypes = [];
26
25
  const videoFormatTypes = [];
27
26
  let availableOffers = [];
@@ -129,8 +128,9 @@ function searchScreeningEventTicketOffers(params) {
129
128
  var _a, _b, _c;
130
129
  // イベント取得属性最適化(2023-01-23~)
131
130
  // const screeningEvent = await repos.event.findById<factory.eventType.ScreeningEvent>({ id: params.eventId });
132
- const screeningEvent = yield repos.event.findMinimizedIndividualEventById({ id: params.eventId });
133
- const superEvent = yield repos.event.findById({ id: screeningEvent.superEvent.id });
131
+ const screeningEvent = params.event;
132
+ // 取得属性最適化(2023-01-25~)
133
+ const superEvent = yield repos.event.findById({ id: screeningEvent.superEvent.id }, { soundFormat: 1, videoFormat: 1 });
134
134
  const soundFormatTypes = (Array.isArray(superEvent.soundFormat)) ? superEvent.soundFormat.map((f) => f.typeOf) : [];
135
135
  const videoFormatTypes = (Array.isArray(superEvent.videoFormat)) ? superEvent.videoFormat.map((f) => f.typeOf) : [];
136
136
  let availableOffers = [];
@@ -149,10 +149,6 @@ function searchScreeningEventTicketOffers(params) {
149
149
  throw new factory.errors.NotFound('event.offers.itemOffered.id');
150
150
  }
151
151
  const { soundFormatChargeSpecifications, videoFormatChargeSpecifications, movieTicketTypeChargeSpecs } = yield searchPriceSpecs4event({ project: { id: screeningEvent.project.id }, soundFormatTypes, videoFormatTypes })(repos);
152
- const screeningEventOfferSettings = screeningEvent.offers;
153
- if (screeningEventOfferSettings === undefined) {
154
- throw new factory.errors.NotFound('event.offers');
155
- }
156
152
  const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event: screeningEvent });
157
153
  // 不許可決済方法があれば、該当オファーを除外
158
154
  if (Array.isArray(unacceptedPaymentMethod) && unacceptedPaymentMethod.length > 0) {
@@ -204,7 +200,7 @@ function searchScreeningEventTicketOffers(params) {
204
200
  });
205
201
  let offers4event = availableOffers.map((availableOffer) => {
206
202
  return (0, factory_1.createCompoundPriceSpec4event)({
207
- eligibleQuantity: screeningEventOfferSettings.eligibleQuantity,
203
+ eligibleQuantity: eventOffers.eligibleQuantity,
208
204
  offer: availableOffer,
209
205
  videoFormatChargeSpecifications,
210
206
  soundFormatChargeSpecifications,
@@ -371,10 +367,10 @@ function searchEventTicketOffers(params) {
371
367
  default:
372
368
  // Chevreで券種オファーを検索
373
369
  if (event.typeOf === factory.eventType.ScreeningEvent) {
374
- offers = yield searchScreeningEventTicketOffers({ eventId: params.event.id })(repos);
370
+ offers = yield searchScreeningEventTicketOffers({ event })(repos);
375
371
  }
376
372
  else if (event.typeOf === factory.eventType.Event) {
377
- offers = yield searchTransportationEventTicketOffers({ eventId: params.event.id })(repos);
373
+ offers = yield searchTransportationEventTicketOffers({ event })(repos);
378
374
  }
379
375
  else {
380
376
  throw new factory.errors.NotImplemented(`'${event.typeOf}' not implemented`);
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@chevre/factory": "4.283.0",
13
- "@cinerino/sdk": "3.135.0",
13
+ "@cinerino/sdk": "3.136.0",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.29"
123
+ "version": "20.2.0-alpha.30"
124
124
  }