@chevre/domain 20.4.0-alpha.14 → 20.4.0-alpha.15
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.
- package/example/src/chevre/aggregateEventReservation.ts +1 -1
- package/example/src/chevre/deleteMovieTicketCategoryChargePriceSpecs.ts +21 -0
- package/example/src/chevre/searchEventTicketOffers.ts +1 -1
- package/lib/chevre/repo/event.d.ts +1 -1
- package/lib/chevre/repo/priceSpecification.d.ts +10 -0
- package/lib/chevre/repo/priceSpecification.js +10 -0
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +43 -82
- package/lib/chevre/settings.d.ts +2 -0
- package/lib/chevre/settings.js +4 -0
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ async function main() {
|
|
|
16
16
|
|
|
17
17
|
// const now = new Date();
|
|
18
18
|
await chevre.service.aggregation.event.aggregateScreeningEvent({
|
|
19
|
-
id: '
|
|
19
|
+
id: 'blaqxj0ak'
|
|
20
20
|
})({
|
|
21
21
|
event: new chevre.repository.Event(mongoose.connection),
|
|
22
22
|
eventAvailability: new chevre.repository.itemAvailability.ScreeningEvent(client),
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
const priceSpecificationRepo = new chevre.repository.PriceSpecification(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const result = await priceSpecificationRepo.deleteUnnecessaryMovieTicketTypeChargePriceSpecs({
|
|
14
|
+
project: { id: 'cinerino' }
|
|
15
|
+
});
|
|
16
|
+
console.log('deleted', result);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
main()
|
|
20
|
+
.then()
|
|
21
|
+
.catch(console.error);
|
|
@@ -22,7 +22,7 @@ async function main() {
|
|
|
22
22
|
const productRepo = new chevre.repository.Product(mongoose.connection);
|
|
23
23
|
|
|
24
24
|
const { ticketOffers } = await chevre.service.offer.event.searchEventTicketOffers({
|
|
25
|
-
event: { id: '
|
|
25
|
+
event: { id: 'ale5c99n2' },
|
|
26
26
|
onlyValid: true,
|
|
27
27
|
sort: false,
|
|
28
28
|
validateOfferRateLimit: true,
|
|
@@ -10,7 +10,7 @@ export interface IUpdateAggregateReservationParams {
|
|
|
10
10
|
$set: {
|
|
11
11
|
updatedAt: Date;
|
|
12
12
|
aggregateReservation: factory.event.screeningEvent.IAggregateReservation;
|
|
13
|
-
aggregateOffer
|
|
13
|
+
aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
|
|
14
14
|
maximumAttendeeCapacity?: number;
|
|
15
15
|
remainingAttendeeCapacity?: number;
|
|
16
16
|
checkInCount?: number;
|
|
@@ -30,5 +30,15 @@ export declare class MongoRepository {
|
|
|
30
30
|
id: string;
|
|
31
31
|
};
|
|
32
32
|
}): Promise<void>;
|
|
33
|
+
deleteUnnecessaryMovieTicketTypeChargePriceSpecs(params: {
|
|
34
|
+
project: {
|
|
35
|
+
id: string;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<{
|
|
38
|
+
ok?: number | undefined;
|
|
39
|
+
n?: number | undefined;
|
|
40
|
+
} & {
|
|
41
|
+
deletedCount?: number | undefined;
|
|
42
|
+
}>;
|
|
33
43
|
getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
|
|
34
44
|
}
|
|
@@ -277,6 +277,16 @@ class MongoRepository {
|
|
|
277
277
|
.exec();
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
|
+
deleteUnnecessaryMovieTicketTypeChargePriceSpecs(params) {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
return this.priceSpecificationModel.deleteMany({
|
|
283
|
+
'project.id': { $eq: params.project.id },
|
|
284
|
+
typeOf: { $eq: factory.priceSpecificationType.MovieTicketTypeChargeSpecification },
|
|
285
|
+
price: { $eq: 0 }
|
|
286
|
+
})
|
|
287
|
+
.exec();
|
|
288
|
+
});
|
|
289
|
+
}
|
|
280
290
|
getCursor(conditions, projection) {
|
|
281
291
|
return this.priceSpecificationModel.find(conditions, projection)
|
|
282
292
|
.sort({ price: factory.sortType.Ascending })
|
|
@@ -17,6 +17,7 @@ const createDebug = require("debug");
|
|
|
17
17
|
const moment = require("moment-timezone");
|
|
18
18
|
const event_1 = require("../../../repo/event");
|
|
19
19
|
const factory = require("../../../factory");
|
|
20
|
+
const settings_1 = require("../../../settings");
|
|
20
21
|
const debug = createDebug('chevre-domain:service');
|
|
21
22
|
/**
|
|
22
23
|
* イベントデータをID指定で集計する
|
|
@@ -28,31 +29,34 @@ function aggregateScreeningEvent(params) {
|
|
|
28
29
|
// const event = await repos.event.findById<factory.eventType.ScreeningEvent | factory.eventType.Event>(params);
|
|
29
30
|
const event = yield repos.event.findMinimizedIndividualEventById(params);
|
|
30
31
|
let aggregatingEvents = [event];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
// プロジェクト限定(2023-02-22~)
|
|
33
|
+
if (settings_1.settings.useOfferRateLimitProjects.includes(event.project.id)) {
|
|
34
|
+
const availableOffers = yield findOffers({ event })(repos);
|
|
35
|
+
const offerRateLimitExists = availableOffers.some((o) => { var _a; return typeof ((_a = o.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope) === 'string'; });
|
|
36
|
+
if (offerRateLimitExists) {
|
|
37
|
+
// 同location、かつ同時間帯、のイベントに関しても集計する(ttts暫定対応)
|
|
38
|
+
const startFrom = moment(event.startDate)
|
|
39
|
+
.startOf('hour')
|
|
40
|
+
.toDate();
|
|
41
|
+
const startThrough = moment(startFrom)
|
|
42
|
+
.add(1, 'hour')
|
|
43
|
+
.add(-1, 'second')
|
|
44
|
+
.toDate();
|
|
45
|
+
// 取得属性最適化(2023-01-25~)
|
|
46
|
+
aggregatingEvents = yield repos.event.search({
|
|
47
|
+
limit: 100,
|
|
48
|
+
page: 1,
|
|
49
|
+
project: { id: { $eq: event.project.id } },
|
|
50
|
+
typeOf: event.typeOf,
|
|
51
|
+
eventStatuses: [factory.eventStatusType.EventScheduled],
|
|
52
|
+
startFrom: startFrom,
|
|
53
|
+
startThrough: startThrough,
|
|
54
|
+
location: { branchCode: { $eq: event.location.branchCode } }
|
|
55
|
+
}, event_1.PROJECTION_MINIMIZED_EVENT);
|
|
56
|
+
// ID指定されたイベントについてはEventScheduledでなくても集計したいので、集計対象を調整
|
|
57
|
+
aggregatingEvents = aggregatingEvents.filter((e) => e.id !== event.id);
|
|
58
|
+
aggregatingEvents = [event, ...aggregatingEvents];
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
debug(aggregatingEvents.length, 'aggregatingEvents found', aggregatingEvents.map((e) => e.id));
|
|
58
62
|
for (const aggregatingEvent of aggregatingEvents) {
|
|
@@ -79,41 +83,29 @@ function aggregateByEvent(params) {
|
|
|
79
83
|
branchCode: { $eq: event.location.branchCode },
|
|
80
84
|
containedInPlace: { id: { $eq: movieTheaterId } }
|
|
81
85
|
});
|
|
82
|
-
// 施設取得
|
|
83
|
-
// const movieTheater = await findLocation(params)(repos);
|
|
84
|
-
// // 万が一施設が存在しなければ処理終了
|
|
85
|
-
// if (movieTheater === undefined) {
|
|
86
|
-
// return;
|
|
87
|
-
// }
|
|
88
|
-
// const screeningRoom = <factory.place.screeningRoom.IPlace | undefined>
|
|
89
|
-
// movieTheater.containsPlace.find((p) => p.branchCode === event.location.branchCode);
|
|
90
|
-
// if (screeningRoom === undefined) {
|
|
91
|
-
// // 基本的にありえないはずだが、万が一スクリーンが見つからなければcapacityは0のまま
|
|
92
|
-
// // tslint:disable-next-line:no-console
|
|
93
|
-
// console.error(new Error(`Screening room not found. branchCode: ${event.location.branchCode}`));
|
|
94
|
-
// return;
|
|
95
|
-
// }
|
|
96
86
|
// 予約集計
|
|
97
87
|
const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByEvent({
|
|
98
88
|
aggregateDate: now,
|
|
99
89
|
event: event,
|
|
100
90
|
screeningRoom: screeningRoom
|
|
101
91
|
})(repos);
|
|
92
|
+
// プロジェクト限定(2023-02-22~)
|
|
102
93
|
// オファーごとの集計
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
let aggregateOffer;
|
|
95
|
+
if (settings_1.settings.useAggregateOfferProjects.includes(event.project.id)) {
|
|
96
|
+
aggregateOffer = yield aggregateOfferByEvent({
|
|
97
|
+
aggregateDate: now,
|
|
98
|
+
event: Object.assign(Object.assign({}, event), { maximumAttendeeCapacity,
|
|
99
|
+
remainingAttendeeCapacity }),
|
|
100
|
+
screeningRoom: screeningRoom
|
|
101
|
+
})(repos);
|
|
102
|
+
debug('offers aggregated', aggregateOffer);
|
|
103
|
+
}
|
|
110
104
|
// 値がundefinedの場合に更新しないように注意
|
|
111
105
|
const update = {
|
|
112
|
-
$set: Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date(), // $setオブジェクトが空だとMongoエラーになるので
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
aggregateOffer }, (maximumAttendeeCapacity !== undefined) ? { maximumAttendeeCapacity: maximumAttendeeCapacity } : undefined), (remainingAttendeeCapacity !== undefined) ? { remainingAttendeeCapacity: remainingAttendeeCapacity } : undefined), (aggregateReservation.checkInCount !== undefined) ? { checkInCount: aggregateReservation.checkInCount } : undefined), (aggregateReservation.attendeeCount !== undefined) ? { attendeeCount: aggregateReservation.attendeeCount } : undefined),
|
|
116
|
-
$unset: Object.assign(Object.assign({ noExistingAttributeName: 1 }, (maximumAttendeeCapacity === undefined) ? { maximumAttendeeCapacity: '' } : undefined), (remainingAttendeeCapacity === undefined) ? { remainingAttendeeCapacity: '' } : undefined)
|
|
106
|
+
$set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date(), // $setオブジェクトが空だとMongoエラーになるので
|
|
107
|
+
aggregateReservation }, (typeof (aggregateOffer === null || aggregateOffer === void 0 ? void 0 : aggregateOffer.typeOf) === 'string') ? { aggregateOffer: aggregateOffer } : undefined), (maximumAttendeeCapacity !== undefined) ? { maximumAttendeeCapacity: maximumAttendeeCapacity } : undefined), (remainingAttendeeCapacity !== undefined) ? { remainingAttendeeCapacity: remainingAttendeeCapacity } : undefined), (aggregateReservation.checkInCount !== undefined) ? { checkInCount: aggregateReservation.checkInCount } : undefined), (aggregateReservation.attendeeCount !== undefined) ? { attendeeCount: aggregateReservation.attendeeCount } : undefined),
|
|
108
|
+
$unset: Object.assign(Object.assign(Object.assign({ noExistingAttributeName: 1 }, (typeof (aggregateOffer === null || aggregateOffer === void 0 ? void 0 : aggregateOffer.typeOf) !== 'string') ? { aggregateOffer: '' } : undefined), (maximumAttendeeCapacity === undefined) ? { maximumAttendeeCapacity: '' } : undefined), (remainingAttendeeCapacity === undefined) ? { remainingAttendeeCapacity: '' } : undefined)
|
|
117
109
|
};
|
|
118
110
|
debug('update:', update);
|
|
119
111
|
// 保管
|
|
@@ -125,37 +117,6 @@ function aggregateByEvent(params) {
|
|
|
125
117
|
});
|
|
126
118
|
}
|
|
127
119
|
exports.aggregateByEvent = aggregateByEvent;
|
|
128
|
-
/**
|
|
129
|
-
* イベントロケーション取得
|
|
130
|
-
* NotFoundエラーをハンドリングする
|
|
131
|
-
*/
|
|
132
|
-
// function findLocation(params: {
|
|
133
|
-
// event: factory.event.screeningEvent.IEvent | factory.event.event.IEvent;
|
|
134
|
-
// }) {
|
|
135
|
-
// return async (repos: {
|
|
136
|
-
// place: PlaceRepo;
|
|
137
|
-
// }): Promise<factory.place.movieTheater.IPlace | undefined> => {
|
|
138
|
-
// let movieTheater: factory.place.movieTheater.IPlace | undefined;
|
|
139
|
-
// try {
|
|
140
|
-
// if (params.event.typeOf === factory.eventType.ScreeningEvent) {
|
|
141
|
-
// movieTheater = await repos.place.findById({ id: params.event.superEvent.location.id });
|
|
142
|
-
// } else {
|
|
143
|
-
// const movieTheaterId: string =
|
|
144
|
-
// String(params.event.offers?.itemOffered.availableChannel.serviceLocation.containedInPlace.id);
|
|
145
|
-
// movieTheater = await repos.place.findById({ id: movieTheaterId });
|
|
146
|
-
// }
|
|
147
|
-
// } catch (error) {
|
|
148
|
-
// let throwsError = true;
|
|
149
|
-
// if (error instanceof factory.errors.NotFound) {
|
|
150
|
-
// throwsError = false;
|
|
151
|
-
// }
|
|
152
|
-
// if (throwsError) {
|
|
153
|
-
// throw error;
|
|
154
|
-
// }
|
|
155
|
-
// }
|
|
156
|
-
// return movieTheater;
|
|
157
|
-
// };
|
|
158
|
-
// }
|
|
159
120
|
/**
|
|
160
121
|
* 集計後アクション
|
|
161
122
|
*/
|
package/lib/chevre/settings.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export declare type ISettings = factory.project.ISettings & {
|
|
|
24
24
|
useEventWorkPerformed: boolean;
|
|
25
25
|
useOffersAppliedToMovieTicketWithoutChargeSpecification: boolean;
|
|
26
26
|
useAggregateEntranceGateProjects: string[];
|
|
27
|
+
useAggregateOfferProjects: string[];
|
|
28
|
+
useOfferRateLimitProjects: string[];
|
|
27
29
|
};
|
|
28
30
|
export declare const DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD: string;
|
|
29
31
|
export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
package/lib/chevre/settings.js
CHANGED
|
@@ -96,4 +96,8 @@ exports.settings = Object.assign(Object.assign({ transactionWebhookUrls, onOrder
|
|
|
96
96
|
? { maxNumCreditCardPaymentMethod: MAX_NUM_CREDIT_CARD_PAYMENT_METHOD }
|
|
97
97
|
: undefined), { useEventWorkPerformed: process.env.USE_EVENT_WORK_PERFORMED === '1', useOffersAppliedToMovieTicketWithoutChargeSpecification: process.env.USE_OFFERS_APPLIED_TO_MOVIE_TICKET_WITHOUT_PRICE_SPEC === '1', useAggregateEntranceGateProjects: (typeof process.env.USE_AGGREGATE_ENTRANCE_GATE_PROJECTS === 'string')
|
|
98
98
|
? process.env.USE_AGGREGATE_ENTRANCE_GATE_PROJECTS.split(',')
|
|
99
|
+
: [], useAggregateOfferProjects: (typeof process.env.USE_AGGREGATE_OFFER_PROJECTS === 'string')
|
|
100
|
+
? process.env.USE_AGGREGATE_OFFER_PROJECTS.split(',')
|
|
101
|
+
: [], useOfferRateLimitProjects: (typeof process.env.USE_OFFER_RATE_LIMIT_PROJECTS === 'string')
|
|
102
|
+
? process.env.USE_OFFER_RATE_LIMIT_PROJECTS.split(',')
|
|
99
103
|
: [] });
|
package/package.json
CHANGED