@chevre/domain 22.9.0-alpha.102 → 22.9.0-alpha.103
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/reIndex.ts +1 -1
- package/example/src/chevre/stockHolder/getSize.ts +16 -16
- package/example/src/chevre/stockHolder/playAroundStockHolder.ts +1 -1
- package/lib/chevre/errorHandler.js +4 -0
- package/lib/chevre/repo/pendingReservation.d.ts +1 -19
- package/lib/chevre/repo/pendingReservation.js +70 -56
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ mongoose.Model.on('index', (...args) => {
|
|
|
11
11
|
async function main() {
|
|
12
12
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
13
|
|
|
14
|
-
await chevre.repository.
|
|
14
|
+
await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
15
15
|
console.log('success!');
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -9,7 +9,7 @@ const today = moment()
|
|
|
9
9
|
.tz('Asia/Tokyo')
|
|
10
10
|
.format('YYYYMMDD');
|
|
11
11
|
const project = { id: String(process.env.PROJECT_ID) };
|
|
12
|
-
const eventId = `sampleEventId${today}:
|
|
12
|
+
const eventId = `sampleEventId${today}:02`;
|
|
13
13
|
const eventStartDate = new Date('2025-05-01T00:00:00Z');
|
|
14
14
|
const seatSection = 'SampleSectionNameXXXXXXXXXXXXXXXXXXX';
|
|
15
15
|
// tslint:disable-next-line:no-magic-numbers prefer-array-literal
|
|
@@ -84,21 +84,21 @@ async function main() {
|
|
|
84
84
|
console.log('searchHoldersResult:', searchHoldersResult, searchHoldersResult.length);
|
|
85
85
|
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
86
86
|
|
|
87
|
-
startTime = process.hrtime();
|
|
88
|
-
const searchHolders2Result = await pendingReservationRepo.searchHolders2({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
diff = process.hrtime(startTime);
|
|
100
|
-
console.log('searchHolders2:', searchHolders2Result, searchHolders2Result.length);
|
|
101
|
-
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
87
|
+
// startTime = process.hrtime();
|
|
88
|
+
// const searchHolders2Result = await pendingReservationRepo.searchHolders2({
|
|
89
|
+
// project: { id: project.id },
|
|
90
|
+
// eventId,
|
|
91
|
+
// startDate: eventStartDate,
|
|
92
|
+
// hasTicketedSeat: true,
|
|
93
|
+
// offers: [
|
|
94
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
95
|
+
// ...allSeatNumbers.slice(0, 10)
|
|
96
|
+
// .map((seatNumber) => ({ seatSection, seatNumber }))
|
|
97
|
+
// ]
|
|
98
|
+
// });
|
|
99
|
+
// diff = process.hrtime(startTime);
|
|
100
|
+
// console.log('searchHolders2:', searchHolders2Result, searchHolders2Result.length);
|
|
101
|
+
// console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
main()
|
|
@@ -8,7 +8,7 @@ const today = moment()
|
|
|
8
8
|
.tz('Asia/Tokyo')
|
|
9
9
|
.format('YYYYMMDD');
|
|
10
10
|
const project = { id: String(process.env.PROJECT_ID) };
|
|
11
|
-
const eventId = `sampleEventId${today}:
|
|
11
|
+
const eventId = `sampleEventId${today}:02`;
|
|
12
12
|
const eventStartDate = new Date('2025-05-01T00:00:00Z');
|
|
13
13
|
const seatSection = 'SampleSectionNameXXXXXXXXXXXXXXXXXXX';
|
|
14
14
|
// tslint:disable-next-line:no-magic-numbers prefer-array-literal
|
|
@@ -177,6 +177,10 @@ function handleMvtkReserveError(error) {
|
|
|
177
177
|
case http_status_1.TOO_MANY_REQUESTS: // 429
|
|
178
178
|
handledError = new factory_1.errors.RateLimitExceeded(message);
|
|
179
179
|
break;
|
|
180
|
+
// handle 504(2025-04-25~)
|
|
181
|
+
case http_status_1.GATEWAY_TIMEOUT: // 504
|
|
182
|
+
handledError = new factory_1.errors.GatewayTimeout(message);
|
|
183
|
+
break;
|
|
180
184
|
default:
|
|
181
185
|
handledError = new factory_1.errors.Internal(message);
|
|
182
186
|
}
|
|
@@ -34,15 +34,6 @@ export declare class PendingReservationRepo implements AbstractStockHolderRepo {
|
|
|
34
34
|
limit?: number;
|
|
35
35
|
}): Promise<number>;
|
|
36
36
|
getHolder(params: Omit<IUnlockKey, 'holder'>): Promise<string | null | undefined>;
|
|
37
|
-
searchHolders2(params: {
|
|
38
|
-
project: {
|
|
39
|
-
id: string;
|
|
40
|
-
};
|
|
41
|
-
eventId: string;
|
|
42
|
-
startDate: Date;
|
|
43
|
-
hasTicketedSeat: boolean;
|
|
44
|
-
offers: IOffer[];
|
|
45
|
-
}): Promise<IGetHolderResult[]>;
|
|
46
37
|
searchHolders(params: {
|
|
47
38
|
project: {
|
|
48
39
|
id: string;
|
|
@@ -51,16 +42,7 @@ export declare class PendingReservationRepo implements AbstractStockHolderRepo {
|
|
|
51
42
|
startDate: Date;
|
|
52
43
|
hasTicketedSeat: boolean;
|
|
53
44
|
offers: IOffer[];
|
|
54
|
-
}): Promise<
|
|
55
|
-
searchHoldersByDistinct(params: {
|
|
56
|
-
project: {
|
|
57
|
-
id: string;
|
|
58
|
-
};
|
|
59
|
-
eventId: string;
|
|
60
|
-
startDate: Date;
|
|
61
|
-
hasTicketedSeat: boolean;
|
|
62
|
-
offers: IOffer[];
|
|
63
|
-
}): Promise<unknown[]>;
|
|
45
|
+
}): Promise<IGetHolderResult[]>;
|
|
64
46
|
private aggregateNumSeats;
|
|
65
47
|
private createReservationPackageIfPossible;
|
|
66
48
|
private deleteReservationPackage;
|
|
@@ -230,48 +230,6 @@ class PendingReservationRepo {
|
|
|
230
230
|
return (doc !== null) ? doc.reservationNumber : undefined;
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
|
-
searchHolders2(params) {
|
|
234
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
const { eventId, offers, hasTicketedSeat } = params;
|
|
236
|
-
const reservationIdentifiers = offers.map((offer) => PendingReservationRepo.offer2identifier(offer, hasTicketedSeat));
|
|
237
|
-
const aggregate = this.pendingReservationModel.aggregate([
|
|
238
|
-
// unwind,matchの順序
|
|
239
|
-
// unwind->matchでは遅い?
|
|
240
|
-
// match->limit->unwind->matchにする
|
|
241
|
-
{
|
|
242
|
-
$unwind: {
|
|
243
|
-
path: '$subReservation'
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
$match: {
|
|
248
|
-
'reservationFor.id': { $eq: eventId },
|
|
249
|
-
'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
{ $limit: reservationIdentifiers.length },
|
|
253
|
-
{
|
|
254
|
-
$project: {
|
|
255
|
-
_id: 0,
|
|
256
|
-
// reservationNumber: '$reservationNumber',
|
|
257
|
-
identifier: '$subReservation.identifier'
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
]);
|
|
261
|
-
const docs = yield aggregate
|
|
262
|
-
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
263
|
-
.exec();
|
|
264
|
-
debug('searchHolders: aggregated.', docs, docs.length, 'docs');
|
|
265
|
-
// reservationNumberを正確に返す必要はなく、存在しているかどうかだけ分かればよい(stringを返せばよい)
|
|
266
|
-
return reservationIdentifiers.map((reservationIdentifier) => {
|
|
267
|
-
const doc = docs.find(({ identifier }) => identifier === reservationIdentifier);
|
|
268
|
-
// tslint:disable-next-line:no-null-keyword
|
|
269
|
-
// return (doc !== undefined) ? doc.reservationNumber : null;
|
|
270
|
-
// tslint:disable-next-line:no-null-keyword
|
|
271
|
-
return (doc !== undefined) ? doc.identifier : null;
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
233
|
searchHolders(params) {
|
|
276
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
235
|
const { eventId, offers, hasTicketedSeat } = params;
|
|
@@ -318,20 +276,76 @@ class PendingReservationRepo {
|
|
|
318
276
|
});
|
|
319
277
|
});
|
|
320
278
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
279
|
+
// public async searchHolders2(params: {
|
|
280
|
+
// project: { id: string };
|
|
281
|
+
// eventId: string;
|
|
282
|
+
// startDate: Date;
|
|
283
|
+
// hasTicketedSeat: boolean;
|
|
284
|
+
// offers: IOffer[];
|
|
285
|
+
// }): Promise<IGetHolderResult[]> {
|
|
286
|
+
// const { eventId, offers, hasTicketedSeat } = params;
|
|
287
|
+
// const reservationIdentifiers = offers.map((offer) => PendingReservationRepo.offer2identifier(offer, hasTicketedSeat));
|
|
288
|
+
// const aggregate = this.pendingReservationModel.aggregate<{
|
|
289
|
+
// // reservationNumber: string;
|
|
290
|
+
// identifier: string;
|
|
291
|
+
// }>([
|
|
292
|
+
// // unwind,matchの順序
|
|
293
|
+
// // unwind->matchでは遅い?
|
|
294
|
+
// // match->limit->unwind->matchにする
|
|
295
|
+
// {
|
|
296
|
+
// $unwind: {
|
|
297
|
+
// path: '$subReservation'
|
|
298
|
+
// }
|
|
299
|
+
// },
|
|
300
|
+
// {
|
|
301
|
+
// $match: {
|
|
302
|
+
// 'reservationFor.id': { $eq: eventId },
|
|
303
|
+
// 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
|
|
304
|
+
// }
|
|
305
|
+
// },
|
|
306
|
+
// { $limit: reservationIdentifiers.length },
|
|
307
|
+
// {
|
|
308
|
+
// $project: {
|
|
309
|
+
// _id: 0,
|
|
310
|
+
// // reservationNumber: '$reservationNumber',
|
|
311
|
+
// identifier: '$subReservation.identifier'
|
|
312
|
+
// }
|
|
313
|
+
// }
|
|
314
|
+
// ]);
|
|
315
|
+
// const docs = await aggregate
|
|
316
|
+
// .option({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
317
|
+
// .exec();
|
|
318
|
+
// debug('searchHolders: aggregated.', docs, docs.length, 'docs');
|
|
319
|
+
// // reservationNumberを正確に返す必要はなく、存在しているかどうかだけ分かればよい(stringを返せばよい)
|
|
320
|
+
// return reservationIdentifiers.map((reservationIdentifier) => {
|
|
321
|
+
// const doc = docs.find(({ identifier }) => identifier === reservationIdentifier);
|
|
322
|
+
// // tslint:disable-next-line:no-null-keyword
|
|
323
|
+
// // return (doc !== undefined) ? doc.reservationNumber : null;
|
|
324
|
+
// // tslint:disable-next-line:no-null-keyword
|
|
325
|
+
// return (doc !== undefined) ? doc.identifier : null;
|
|
326
|
+
// });
|
|
327
|
+
// }
|
|
328
|
+
// public async searchHoldersByDistinct(params: {
|
|
329
|
+
// project: { id: string };
|
|
330
|
+
// eventId: string;
|
|
331
|
+
// startDate: Date;
|
|
332
|
+
// hasTicketedSeat: boolean;
|
|
333
|
+
// offers: IOffer[];
|
|
334
|
+
// }) {
|
|
335
|
+
// const { eventId, offers, hasTicketedSeat } = params;
|
|
336
|
+
// const reservationIdentifiers = offers.map((offer) => PendingReservationRepo.offer2identifier(offer, hasTicketedSeat));
|
|
337
|
+
// const doc = await this.pendingReservationModel.distinct(
|
|
338
|
+
// 'subReservation.identifier',
|
|
339
|
+
// {
|
|
340
|
+
// 'reservationFor.id': { $eq: eventId },
|
|
341
|
+
// 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
|
|
342
|
+
// }
|
|
343
|
+
// )
|
|
344
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
345
|
+
// .exec();
|
|
346
|
+
// debug('searchHolders: distinct.', doc);
|
|
347
|
+
// return doc;
|
|
348
|
+
// }
|
|
335
349
|
// public async getSize(params: Omit<IUnlockKey, 'holder' | 'offer'>) {
|
|
336
350
|
// const { eventId } = params;
|
|
337
351
|
// const aggregate = this.aggregateReservationModel.aggregate([
|
package/package.json
CHANGED