@chevre/domain 20.4.0-alpha.36 → 20.4.0-alpha.37
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 +2 -1
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -0
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +63 -29
- package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -0
- package/package.json +1 -1
|
@@ -16,11 +16,12 @@ async function main() {
|
|
|
16
16
|
|
|
17
17
|
// const now = new Date();
|
|
18
18
|
await chevre.service.aggregation.event.aggregateScreeningEvent({
|
|
19
|
-
id:
|
|
19
|
+
id: String(process.env.EVENT_ID)
|
|
20
20
|
})({
|
|
21
21
|
event: new chevre.repository.Event(mongoose.connection),
|
|
22
22
|
eventAvailability: new chevre.repository.itemAvailability.ScreeningEvent(client),
|
|
23
23
|
offer: new chevre.repository.Offer(mongoose.connection),
|
|
24
|
+
offerCatalog: new chevre.repository.OfferCatalog(mongoose.connection),
|
|
24
25
|
offerRateLimit: new chevre.repository.rateLimit.Offer(client),
|
|
25
26
|
place: new chevre.repository.Place(mongoose.connection),
|
|
26
27
|
product: new chevre.repository.Product(mongoose.connection),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MongoRepository as EventRepo } from '../../../repo/event';
|
|
2
2
|
import { RedisRepository as EventAvailabilityRepo } from '../../../repo/itemAvailability/screeningEvent';
|
|
3
3
|
import { MongoRepository as OfferRepo } from '../../../repo/offer';
|
|
4
|
+
import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
|
|
4
5
|
import { MongoRepository as PlaceRepo } from '../../../repo/place';
|
|
5
6
|
import { MongoRepository as ProductRepo } from '../../../repo/product';
|
|
6
7
|
import { MongoRepository as ProjectRepo } from '../../../repo/project';
|
|
@@ -12,6 +13,7 @@ export declare type IAggregateScreeningEventOperation<T> = (repos: {
|
|
|
12
13
|
event: EventRepo;
|
|
13
14
|
eventAvailability: EventAvailabilityRepo;
|
|
14
15
|
offer: OfferRepo;
|
|
16
|
+
offerCatalog: OfferCatalogRepo;
|
|
15
17
|
offerRateLimit: OfferRateLimitRepo;
|
|
16
18
|
place: PlaceRepo;
|
|
17
19
|
product: ProductRepo;
|
|
@@ -89,18 +89,15 @@ function aggregateByEvent(params) {
|
|
|
89
89
|
event: event,
|
|
90
90
|
screeningRoom: screeningRoom
|
|
91
91
|
})(repos);
|
|
92
|
-
// プロジェクト限定(2023-02-22~)
|
|
93
92
|
// オファーごとの集計
|
|
94
93
|
let aggregateOffer;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
debug('offers aggregated', aggregateOffer);
|
|
103
|
-
}
|
|
94
|
+
aggregateOffer = yield aggregateOfferByEvent({
|
|
95
|
+
aggregateDate: now,
|
|
96
|
+
event: Object.assign(Object.assign({}, event), { maximumAttendeeCapacity,
|
|
97
|
+
remainingAttendeeCapacity }),
|
|
98
|
+
screeningRoom: screeningRoom
|
|
99
|
+
})(repos);
|
|
100
|
+
debug('offers aggregated', aggregateOffer);
|
|
104
101
|
// 値がundefinedの場合に更新しないように注意
|
|
105
102
|
const update = {
|
|
106
103
|
$set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date(), // $setオブジェクトが空だとMongoエラーになるので
|
|
@@ -133,26 +130,36 @@ function reservedSeatsAvailable(params) {
|
|
|
133
130
|
function aggregateOfferByEvent(params) {
|
|
134
131
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
135
132
|
var _a, _b, _c;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
// プロジェクト限定(2023-02-22~)
|
|
134
|
+
if (settings_1.settings.useAggregateOfferProjects.includes(params.event.project.id)) {
|
|
135
|
+
const availableOffers = yield findOffers(params)(repos);
|
|
136
|
+
// オファーごとの予約集計
|
|
137
|
+
const offersWithAggregateReservation = [];
|
|
138
|
+
for (const o of availableOffers) {
|
|
139
|
+
const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByOffer({
|
|
140
|
+
aggregateDate: params.aggregateDate,
|
|
141
|
+
event: params.event,
|
|
142
|
+
screeningRoom: params.screeningRoom,
|
|
143
|
+
offer: o
|
|
144
|
+
})(repos);
|
|
145
|
+
offersWithAggregateReservation.push(Object.assign(Object.assign(Object.assign({ typeOf: o.typeOf, id: o.id, identifier: o.identifier, aggregateReservation: aggregateReservation, name: {
|
|
146
|
+
en: (_a = o.name) === null || _a === void 0 ? void 0 : _a.en,
|
|
147
|
+
ja: (_b = o.name) === null || _b === void 0 ? void 0 : _b.ja
|
|
148
|
+
} }, (typeof maximumAttendeeCapacity === 'number') ? { maximumAttendeeCapacity } : undefined), (typeof remainingAttendeeCapacity === 'number') ? { remainingAttendeeCapacity } : undefined), (typeof ((_c = o.category) === null || _c === void 0 ? void 0 : _c.codeValue) === 'string') ? { category: o.category } : undefined));
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
152
|
+
offerCount: availableOffers.length,
|
|
153
|
+
offers: offersWithAggregateReservation
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const { offerCount } = yield calculateOfferCount({ event: params.event })(repos);
|
|
158
|
+
return {
|
|
159
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
160
|
+
offerCount
|
|
161
|
+
};
|
|
150
162
|
}
|
|
151
|
-
return {
|
|
152
|
-
typeOf: factory.offerType.AggregateOffer,
|
|
153
|
-
offerCount: availableOffers.length,
|
|
154
|
-
offers: offersWithAggregateReservation
|
|
155
|
-
};
|
|
156
163
|
});
|
|
157
164
|
}
|
|
158
165
|
/**
|
|
@@ -194,6 +201,33 @@ function findOffers(params) {
|
|
|
194
201
|
return availableOffers;
|
|
195
202
|
});
|
|
196
203
|
}
|
|
204
|
+
function calculateOfferCount(params) {
|
|
205
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
var _a, _b, _c;
|
|
207
|
+
let offerCount = 0;
|
|
208
|
+
try {
|
|
209
|
+
const eventOffers = params.event.offers;
|
|
210
|
+
if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
|
|
211
|
+
const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id });
|
|
212
|
+
if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
|
|
213
|
+
const catalogs = yield repos.offerCatalog.search({
|
|
214
|
+
limit: 1,
|
|
215
|
+
page: 1,
|
|
216
|
+
id: { $in: [eventService.hasOfferCatalog.id] }
|
|
217
|
+
});
|
|
218
|
+
const numberOfItems = (_c = catalogs.shift()) === null || _c === void 0 ? void 0 : _c.numberOfItems;
|
|
219
|
+
if (typeof numberOfItems === 'number') {
|
|
220
|
+
offerCount = numberOfItems;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
return { offerCount };
|
|
229
|
+
});
|
|
230
|
+
}
|
|
197
231
|
function aggregateReservationByOffer(params) {
|
|
198
232
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
199
233
|
let reservationCount4offer;
|
|
@@ -14,6 +14,7 @@ const factory = require("../../factory");
|
|
|
14
14
|
const event_1 = require("../../repo/event");
|
|
15
15
|
const screeningEvent_1 = require("../../repo/itemAvailability/screeningEvent");
|
|
16
16
|
const offer_1 = require("../../repo/offer");
|
|
17
|
+
const offerCatalog_1 = require("../../repo/offerCatalog");
|
|
17
18
|
const place_1 = require("../../repo/place");
|
|
18
19
|
const product_1 = require("../../repo/product");
|
|
19
20
|
const project_1 = require("../../repo/project");
|
|
@@ -33,6 +34,7 @@ function call(data) {
|
|
|
33
34
|
event: new event_1.MongoRepository(settings.connection),
|
|
34
35
|
eventAvailability: new screeningEvent_1.RedisRepository(settings.redisClient),
|
|
35
36
|
offer: new offer_1.MongoRepository(settings.connection),
|
|
37
|
+
offerCatalog: new offerCatalog_1.MongoRepository(settings.connection),
|
|
36
38
|
offerRateLimit: new offer_2.RedisRepository(settings.redisClient),
|
|
37
39
|
place: new place_1.MongoRepository(settings.connection),
|
|
38
40
|
product: new product_1.MongoRepository(settings.connection),
|
package/package.json
CHANGED