@chevre/domain 21.2.0-alpha.121 → 21.2.0-alpha.123
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/lockStockHolder.ts +2 -1
- package/example/src/chevre/searchEventSeats.ts +2 -1
- package/lib/chevre/repo/mongoose/schemas/holdReservation.d.ts +6 -6
- package/lib/chevre/repo/mongoose/schemas/holdReservation.js +8 -2
- package/lib/chevre/repo/stockHolder.d.ts +46 -0
- package/lib/chevre/repo/stockHolder.js +53 -6
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +1 -0
- package/lib/chevre/service/assetTransaction/reserve.js +3 -0
- package/lib/chevre/service/offer.js +1 -0
- package/lib/chevre/service/reserve/cancelReservation.js +6 -0
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import * as redis from 'redis';
|
|
|
5
5
|
|
|
6
6
|
import { chevre } from '../../../lib/index';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
9
9
|
|
|
10
10
|
// tslint:disable-next-line:max-func-body-length
|
|
11
11
|
async function main() {
|
|
@@ -22,6 +22,7 @@ async function main() {
|
|
|
22
22
|
|
|
23
23
|
const stockHolderRepo = new chevre.repository.StockHolder(client, mongoose.connection);
|
|
24
24
|
await stockHolderRepo.lock({
|
|
25
|
+
project,
|
|
25
26
|
eventId: 'sampleEventId',
|
|
26
27
|
startDate: startDate.toDate(),
|
|
27
28
|
offers: [
|
|
@@ -4,7 +4,7 @@ import * as redis from 'redis';
|
|
|
4
4
|
|
|
5
5
|
import { chevre } from '../../../lib/index';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
8
8
|
|
|
9
9
|
// tslint:disable-next-line:max-func-body-length
|
|
10
10
|
async function main() {
|
|
@@ -20,6 +20,7 @@ async function main() {
|
|
|
20
20
|
const itemAvailabilityRepo = new chevre.repository.StockHolder(client, mongoose.connection);
|
|
21
21
|
|
|
22
22
|
const result = await itemAvailabilityRepo.searchHolders({
|
|
23
|
+
project,
|
|
23
24
|
eventId: 'alckc9mlx',
|
|
24
25
|
startDate: new Date(),
|
|
25
26
|
offers: [
|
|
@@ -53,22 +53,22 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
53
53
|
};
|
|
54
54
|
}, {
|
|
55
55
|
typeOf: string;
|
|
56
|
+
project: any;
|
|
57
|
+
reservationFor: any;
|
|
56
58
|
reservations: any[];
|
|
57
59
|
reservationCount: number;
|
|
58
|
-
project?: any;
|
|
59
|
-
reservationFor?: any;
|
|
60
60
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
61
61
|
typeOf: string;
|
|
62
|
+
project: any;
|
|
63
|
+
reservationFor: any;
|
|
62
64
|
reservations: any[];
|
|
63
65
|
reservationCount: number;
|
|
64
|
-
project?: any;
|
|
65
|
-
reservationFor?: any;
|
|
66
66
|
}>> & Omit<import("mongoose").FlatRecord<{
|
|
67
67
|
typeOf: string;
|
|
68
|
+
project: any;
|
|
69
|
+
reservationFor: any;
|
|
68
70
|
reservations: any[];
|
|
69
71
|
reservationCount: number;
|
|
70
|
-
project?: any;
|
|
71
|
-
reservationFor?: any;
|
|
72
72
|
}> & {
|
|
73
73
|
_id: import("mongoose").Types.ObjectId;
|
|
74
74
|
}, never>>;
|
|
@@ -9,12 +9,18 @@ exports.modelName = modelName;
|
|
|
9
9
|
* 保留予約スキーマ
|
|
10
10
|
*/
|
|
11
11
|
const schema = new mongoose_1.Schema({
|
|
12
|
-
project:
|
|
12
|
+
project: {
|
|
13
|
+
type: mongoose_1.SchemaTypes.Mixed,
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
13
16
|
typeOf: {
|
|
14
17
|
type: String,
|
|
15
18
|
required: true
|
|
16
19
|
},
|
|
17
|
-
reservationFor:
|
|
20
|
+
reservationFor: {
|
|
21
|
+
type: mongoose_1.SchemaTypes.Mixed,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
18
24
|
reservationCount: {
|
|
19
25
|
type: Number,
|
|
20
26
|
default: 0,
|
|
@@ -14,6 +14,9 @@ export interface IOffer {
|
|
|
14
14
|
seatNumber: string;
|
|
15
15
|
}
|
|
16
16
|
export interface ILockKey {
|
|
17
|
+
project: {
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
17
20
|
eventId: string;
|
|
18
21
|
startDate: Date;
|
|
19
22
|
offers: IOffer[];
|
|
@@ -21,6 +24,9 @@ export interface ILockKey {
|
|
|
21
24
|
holder: string;
|
|
22
25
|
}
|
|
23
26
|
export interface IUnlockKey {
|
|
27
|
+
project: {
|
|
28
|
+
id: string;
|
|
29
|
+
};
|
|
24
30
|
eventId: string;
|
|
25
31
|
startDate: Date;
|
|
26
32
|
offer: IOffer;
|
|
@@ -40,6 +46,10 @@ export interface IReservationPackage {
|
|
|
40
46
|
subReservation: ISubReservation[];
|
|
41
47
|
}
|
|
42
48
|
export interface IAggregateReservation {
|
|
49
|
+
project: {
|
|
50
|
+
id: string;
|
|
51
|
+
typeOf: factory.organizationType.Project;
|
|
52
|
+
};
|
|
43
53
|
typeOf: 'AggregateReservation';
|
|
44
54
|
reservationCount: number;
|
|
45
55
|
reservationFor: {
|
|
@@ -101,10 +111,46 @@ export declare class StockHolderRepository {
|
|
|
101
111
|
* offers.lengthが0だと"ERR wrong number of arguments for 'hmget' command"となるので注意
|
|
102
112
|
*/
|
|
103
113
|
searchHolders(params: {
|
|
114
|
+
project: {
|
|
115
|
+
id: string;
|
|
116
|
+
};
|
|
104
117
|
eventId: string;
|
|
105
118
|
startDate: Date;
|
|
106
119
|
offers: IOffer[];
|
|
107
120
|
}): Promise<IGetHolderResult[]>;
|
|
121
|
+
/**
|
|
122
|
+
* 汎用的な検索(mongooseのみ対応)
|
|
123
|
+
*/
|
|
124
|
+
search(params: {
|
|
125
|
+
limit?: number;
|
|
126
|
+
page?: number;
|
|
127
|
+
project?: {
|
|
128
|
+
id?: {
|
|
129
|
+
$eq?: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
reservationFor?: {
|
|
133
|
+
id?: {
|
|
134
|
+
$eq?: string;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
reservationNumber?: {
|
|
138
|
+
$eq?: string;
|
|
139
|
+
};
|
|
140
|
+
id?: {
|
|
141
|
+
$eq?: string;
|
|
142
|
+
};
|
|
143
|
+
reservedTicket?: {
|
|
144
|
+
ticketedSeat?: {
|
|
145
|
+
seatNumber?: {
|
|
146
|
+
$eq?: string;
|
|
147
|
+
};
|
|
148
|
+
seatSection?: {
|
|
149
|
+
$eq?: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
}): Promise<ISearchSubReservationResult[]>;
|
|
108
154
|
private checkIfConflicted;
|
|
109
155
|
private initializeHoldReservation;
|
|
110
156
|
}
|
|
@@ -15,7 +15,7 @@ const moment = require("moment");
|
|
|
15
15
|
const factory = require("../factory");
|
|
16
16
|
const holdReservation_1 = require("./mongoose/schemas/holdReservation");
|
|
17
17
|
const settings_1 = require("../settings");
|
|
18
|
-
const debug = createDebug('chevre-domain:repo');
|
|
18
|
+
const debug = createDebug('chevre-domain:repo:stockHolder');
|
|
19
19
|
/**
|
|
20
20
|
* イベントストックホルダーリポジトリ
|
|
21
21
|
*/
|
|
@@ -87,7 +87,7 @@ class StockHolderRepository {
|
|
|
87
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
88
|
if (StockHolderRepository.useMongoose({ eventId: lockKey.eventId, startDate: lockKey.startDate })) {
|
|
89
89
|
// reservationCount<=nであれば$push+$incする
|
|
90
|
-
yield this.initializeHoldReservation({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
90
|
+
yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
91
91
|
const addedReservationCount = lockKey.offers.length;
|
|
92
92
|
const reservationCountLte = maximum - addedReservationCount;
|
|
93
93
|
const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
@@ -135,7 +135,7 @@ class StockHolderRepository {
|
|
|
135
135
|
lock(lockKey) {
|
|
136
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
137
|
if (StockHolderRepository.useMongoose({ eventId: lockKey.eventId, startDate: lockKey.startDate })) {
|
|
138
|
-
yield this.initializeHoldReservation({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
138
|
+
yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
139
139
|
const addedReservationCount = lockKey.offers.length;
|
|
140
140
|
const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
141
141
|
const reservationPackage = {
|
|
@@ -215,7 +215,7 @@ class StockHolderRepository {
|
|
|
215
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
216
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
217
217
|
// [id]あるいは[seatNumber+seatSection]でreservations.subReservationsから$pull+$incする
|
|
218
|
-
yield this.initializeHoldReservation({ eventId: params.eventId, startDate: params.startDate });
|
|
218
|
+
yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
219
219
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer);
|
|
220
220
|
const reservationNumber = params.holder;
|
|
221
221
|
const updateResult = yield this.holdReservationModel.findOneAndUpdate({
|
|
@@ -303,7 +303,7 @@ class StockHolderRepository {
|
|
|
303
303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
304
304
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
305
305
|
// [id]あるいは[seatNumber+seatSection]でreservationNumberを返す
|
|
306
|
-
yield this.initializeHoldReservation({ eventId: params.eventId, startDate: params.startDate });
|
|
306
|
+
yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
307
307
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer);
|
|
308
308
|
const matchStages = [
|
|
309
309
|
{
|
|
@@ -377,7 +377,7 @@ class StockHolderRepository {
|
|
|
377
377
|
return __awaiter(this, void 0, void 0, function* () {
|
|
378
378
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
379
379
|
// [id]あるいは[seatNumber+seatSection]のリストでreservationNumberのリストを返す
|
|
380
|
-
yield this.initializeHoldReservation({ eventId: params.eventId, startDate: params.startDate });
|
|
380
|
+
yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
381
381
|
const subReservations = params.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
382
382
|
const matchStages = [
|
|
383
383
|
{
|
|
@@ -447,6 +447,52 @@ class StockHolderRepository {
|
|
|
447
447
|
// }
|
|
448
448
|
// }
|
|
449
449
|
// }
|
|
450
|
+
/**
|
|
451
|
+
* 汎用的な検索(mongooseのみ対応)
|
|
452
|
+
*/
|
|
453
|
+
search(params) {
|
|
454
|
+
var _a, _b, _c, _d, _e;
|
|
455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
const matchStages = [
|
|
457
|
+
// {
|
|
458
|
+
// $match: { 'reservations.subReservation.identifier': { $in: subReservations.map((r) => r.identifier) } }
|
|
459
|
+
// }
|
|
460
|
+
];
|
|
461
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
462
|
+
if (typeof projectIdEq === 'string') {
|
|
463
|
+
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
464
|
+
}
|
|
465
|
+
const reservationForIdEq = (_d = (_c = params.reservationFor) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
|
|
466
|
+
if (typeof reservationForIdEq === 'string') {
|
|
467
|
+
matchStages.push({ $match: { 'reservationFor.id': { $eq: reservationForIdEq } } });
|
|
468
|
+
}
|
|
469
|
+
const reservationNumberEq = (_e = params.reservationNumber) === null || _e === void 0 ? void 0 : _e.$eq;
|
|
470
|
+
if (typeof reservationNumberEq === 'string') {
|
|
471
|
+
matchStages.push({ $match: { 'reservations.reservationNumber': { $eq: reservationNumberEq } } });
|
|
472
|
+
}
|
|
473
|
+
const aggregate = this.holdReservationModel.aggregate([
|
|
474
|
+
{ $unwind: '$reservations' },
|
|
475
|
+
{ $unwind: '$reservations.subReservation' },
|
|
476
|
+
...matchStages,
|
|
477
|
+
{
|
|
478
|
+
$project: {
|
|
479
|
+
_id: 0,
|
|
480
|
+
id: '$reservations.subReservation.id',
|
|
481
|
+
identifier: '$reservations.subReservation.identifier',
|
|
482
|
+
reservationFor: '$reservationFor',
|
|
483
|
+
reservationNumber: '$reservations.reservationNumber',
|
|
484
|
+
reservedTicket: '$reservations.subReservation.reservedTicket'
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
]);
|
|
488
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
489
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
490
|
+
aggregate.limit(params.limit * page)
|
|
491
|
+
.skip(params.limit * (page - 1));
|
|
492
|
+
}
|
|
493
|
+
return aggregate.exec();
|
|
494
|
+
});
|
|
495
|
+
}
|
|
450
496
|
checkIfConflicted(params) {
|
|
451
497
|
return __awaiter(this, void 0, void 0, function* () {
|
|
452
498
|
// 旧キーと新キーの両方存在検証(念のため)
|
|
@@ -476,6 +522,7 @@ class StockHolderRepository {
|
|
|
476
522
|
throw new factory.errors.Argument('startDate', 'must be Date');
|
|
477
523
|
}
|
|
478
524
|
const aggregateReservation = {
|
|
525
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
479
526
|
typeOf: 'AggregateReservation',
|
|
480
527
|
reservationCount: 0,
|
|
481
528
|
reservationFor: {
|
|
@@ -388,6 +388,7 @@ function filterByEligibleSeatingType(params) {
|
|
|
388
388
|
let remainingAttendeeCapacity;
|
|
389
389
|
if (maximumAttendeeCapacity > 0) {
|
|
390
390
|
const availabilities = yield repos.stockHolder.searchHolders({
|
|
391
|
+
project: { id: params.event.project.id },
|
|
391
392
|
eventId: params.event.id,
|
|
392
393
|
startDate: moment(params.event.startDate)
|
|
393
394
|
.toDate(),
|
|
@@ -239,6 +239,7 @@ function searchEventSeatOffers(params) {
|
|
|
239
239
|
});
|
|
240
240
|
if (seats.length > 0) {
|
|
241
241
|
const availabilities = yield repos.stockHolder.searchHolders({
|
|
242
|
+
project: { id: params.event.project.id },
|
|
242
243
|
eventId: params.event.id,
|
|
243
244
|
startDate: moment(params.event.startDate)
|
|
244
245
|
.toDate(),
|
|
@@ -677,6 +678,7 @@ function processLockSeats(params) {
|
|
|
677
678
|
const maximumAttendeeCapacity4event = (_b = params.event.location) === null || _b === void 0 ? void 0 : _b.maximumAttendeeCapacity;
|
|
678
679
|
if (typeof maximumAttendeeCapacity4event === 'number') {
|
|
679
680
|
yield repos.stockHolder.lockIfNotLimitExceeded({
|
|
681
|
+
project: { id: params.event.project.id },
|
|
680
682
|
eventId: params.event.id,
|
|
681
683
|
startDate: moment(params.event.startDate)
|
|
682
684
|
.toDate(),
|
|
@@ -687,6 +689,7 @@ function processLockSeats(params) {
|
|
|
687
689
|
}
|
|
688
690
|
else {
|
|
689
691
|
yield repos.stockHolder.lock({
|
|
692
|
+
project: { id: params.event.project.id },
|
|
690
693
|
eventId: params.event.id,
|
|
691
694
|
startDate: moment(params.event.startDate)
|
|
692
695
|
.toDate(),
|
|
@@ -91,6 +91,7 @@ function searchEventSeatOffersWithPaging(params) {
|
|
|
91
91
|
} }));
|
|
92
92
|
if (seats.length > 0) {
|
|
93
93
|
const availabilities = yield repos.stockHolder.searchHolders({
|
|
94
|
+
project: { id: event.project.id },
|
|
94
95
|
eventId: params.event.id,
|
|
95
96
|
startDate: moment(event.startDate)
|
|
96
97
|
.toDate(),
|
|
@@ -98,6 +98,7 @@ function cancelPengindIfNotYet(params, now) {
|
|
|
98
98
|
yield processUnlockSeat({
|
|
99
99
|
reservation: {
|
|
100
100
|
id: cancelingSubReservation.id,
|
|
101
|
+
project: { id: reserveTransaction.project.id },
|
|
101
102
|
reservedTicket: cancelingSubReservation.reservedTicket,
|
|
102
103
|
subReservation: cancelingSubReservation.subReservation,
|
|
103
104
|
reservationFor: {
|
|
@@ -204,6 +205,7 @@ function cancelReservation(actionAttributesList) {
|
|
|
204
205
|
yield processUnlockSeat({
|
|
205
206
|
reservation: {
|
|
206
207
|
id: cancelingSubReservation.id,
|
|
208
|
+
project: { id: reserveTransaction.project.id },
|
|
207
209
|
reservedTicket: cancelingSubReservation.reservedTicket,
|
|
208
210
|
subReservation: cancelingSubReservation.subReservation,
|
|
209
211
|
reservationFor: {
|
|
@@ -255,6 +257,7 @@ function cancelReservation(actionAttributesList) {
|
|
|
255
257
|
yield processUnlockSeat({
|
|
256
258
|
reservation: {
|
|
257
259
|
id: reservation.id,
|
|
260
|
+
project: { id: reservation.project.id },
|
|
258
261
|
reservedTicket: reservation.reservedTicket,
|
|
259
262
|
subReservation: reservation.subReservation,
|
|
260
263
|
reservationFor: {
|
|
@@ -344,6 +347,7 @@ function processUnlockSeat(params) {
|
|
|
344
347
|
.toDate();
|
|
345
348
|
// 予約IDでロックされていれば解除
|
|
346
349
|
let lockKey = {
|
|
350
|
+
project: reservation.project,
|
|
347
351
|
eventId: reservation.reservationFor.id,
|
|
348
352
|
startDate: eventStartDate,
|
|
349
353
|
offer: {
|
|
@@ -361,6 +365,7 @@ function processUnlockSeat(params) {
|
|
|
361
365
|
const ticketedSeat = reservation.reservedTicket.ticketedSeat;
|
|
362
366
|
if (ticketedSeat !== undefined) {
|
|
363
367
|
lockKey = {
|
|
368
|
+
project: reservation.project,
|
|
364
369
|
eventId: reservation.reservationFor.id,
|
|
365
370
|
startDate: eventStartDate,
|
|
366
371
|
offer: {
|
|
@@ -383,6 +388,7 @@ function processUnlockSeat(params) {
|
|
|
383
388
|
const seatNumber4sub = (_d = (_c = subReservation.reservedTicket) === null || _c === void 0 ? void 0 : _c.ticketedSeat) === null || _d === void 0 ? void 0 : _d.seatNumber;
|
|
384
389
|
if (typeof seatSection4sub === 'string' && typeof seatNumber4sub === 'string') {
|
|
385
390
|
const lockKey4sub = {
|
|
391
|
+
project: reservation.project,
|
|
386
392
|
eventId: reservation.reservationFor.id,
|
|
387
393
|
startDate: eventStartDate,
|
|
388
394
|
offer: {
|
package/package.json
CHANGED