@chevre/domain 21.2.0-alpha.120 → 21.2.0-alpha.122

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.
@@ -5,7 +5,7 @@ import * as redis from 'redis';
5
5
 
6
6
  import { chevre } from '../../../lib/index';
7
7
 
8
- // const project = { id: String(process.env.PROJECT_ID) };
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
- // const project = { id: String(process.env.PROJECT_ID) };
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: mongoose_1.SchemaTypes.Mixed,
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: mongoose_1.SchemaTypes.Mixed,
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,9 +24,13 @@ 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;
33
+ holder: string;
27
34
  }
28
35
  export type IGetHolderResult = string | null;
29
36
  export interface ISubReservation {
@@ -39,6 +46,10 @@ export interface IReservationPackage {
39
46
  subReservation: ISubReservation[];
40
47
  }
41
48
  export interface IAggregateReservation {
49
+ project: {
50
+ id: string;
51
+ typeOf: factory.organizationType.Project;
52
+ };
42
53
  typeOf: 'AggregateReservation';
43
54
  reservationCount: number;
44
55
  reservationFor: {
@@ -94,16 +105,50 @@ export declare class StockHolderRepository {
94
105
  /**
95
106
  * 保持者を取得する
96
107
  */
97
- getHolder(params: IUnlockKey): Promise<string | null | undefined>;
108
+ getHolder(params: Omit<IUnlockKey, 'holder'>): Promise<string | null | undefined>;
98
109
  /**
99
110
  * 在庫状況を検索する
100
111
  * offers.lengthが0だと"ERR wrong number of arguments for 'hmget' command"となるので注意
101
112
  */
102
113
  searchHolders(params: {
114
+ project: {
115
+ id: string;
116
+ };
103
117
  eventId: string;
104
118
  startDate: Date;
105
119
  offers: IOffer[];
106
120
  }): Promise<IGetHolderResult[]>;
121
+ /**
122
+ * 汎用的な検索(mongooseのみ対応)
123
+ */
124
+ search(params: {
125
+ project?: {
126
+ id?: {
127
+ $eq?: string;
128
+ };
129
+ };
130
+ reservationFor?: {
131
+ id?: {
132
+ $eq?: string;
133
+ };
134
+ };
135
+ reservationNumber?: {
136
+ $eq?: string;
137
+ };
138
+ id?: {
139
+ $eq?: string;
140
+ };
141
+ reservedTicket?: {
142
+ ticketedSeat?: {
143
+ seatNumber?: {
144
+ $eq?: string;
145
+ };
146
+ seatSection?: {
147
+ $eq?: string;
148
+ };
149
+ };
150
+ };
151
+ }): Promise<ISearchSubReservationResult[]>;
107
152
  private checkIfConflicted;
108
153
  private initializeHoldReservation;
109
154
  }
@@ -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,19 +215,25 @@ 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
- yield this.holdReservationModel.findOneAndUpdate({
220
+ const reservationNumber = params.holder;
221
+ const updateResult = yield this.holdReservationModel.findOneAndUpdate({
221
222
  'reservationFor.id': { $eq: params.eventId },
222
- 'reservations.subReservation.identifier': {
223
- $eq: subReservation.identifier
224
- }
223
+ 'reservations.reservationNumber': { $eq: reservationNumber },
224
+ 'reservations.subReservation.identifier': { $eq: subReservation.identifier }
225
225
  }, {
226
226
  $inc: { reservationCount: -1 },
227
- $pull: { 'reservations.subReservation': { identifier: { $eq: subReservation.identifier } } }
228
- }, { new: true })
227
+ $pull: { 'reservations.$[reservationPackage].subReservation': { identifier: { $eq: subReservation.identifier } } }
228
+ }, {
229
+ new: true,
230
+ arrayFilters: [
231
+ { 'reservationPackage.reservationNumber': reservationNumber }
232
+ ]
233
+ })
229
234
  .select({ _id: 1 })
230
235
  .exec();
236
+ debug('unlock processed. updateResult:', updateResult, 'reservationNumber:', reservationNumber, 'identifier:', subReservation.identifier);
231
237
  // docが存在しなくてもよい
232
238
  }
233
239
  else {
@@ -297,7 +303,7 @@ class StockHolderRepository {
297
303
  return __awaiter(this, void 0, void 0, function* () {
298
304
  if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
299
305
  // [id]あるいは[seatNumber+seatSection]でreservationNumberを返す
300
- yield this.initializeHoldReservation({ eventId: params.eventId, startDate: params.startDate });
306
+ yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
301
307
  const subReservation = StockHolderRepository.offer2subReservation(params.offer);
302
308
  const matchStages = [
303
309
  {
@@ -371,7 +377,7 @@ class StockHolderRepository {
371
377
  return __awaiter(this, void 0, void 0, function* () {
372
378
  if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
373
379
  // [id]あるいは[seatNumber+seatSection]のリストでreservationNumberのリストを返す
374
- yield this.initializeHoldReservation({ eventId: params.eventId, startDate: params.startDate });
380
+ yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
375
381
  const subReservations = params.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
376
382
  const matchStages = [
377
383
  {
@@ -441,6 +447,47 @@ class StockHolderRepository {
441
447
  // }
442
448
  // }
443
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
+ return aggregate.exec();
489
+ });
490
+ }
444
491
  checkIfConflicted(params) {
445
492
  return __awaiter(this, void 0, void 0, function* () {
446
493
  // 旧キーと新キーの両方存在検証(念のため)
@@ -470,6 +517,7 @@ class StockHolderRepository {
470
517
  throw new factory.errors.Argument('startDate', 'must be Date');
471
518
  }
472
519
  const aggregateReservation = {
520
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
473
521
  typeOf: 'AggregateReservation',
474
522
  reservationCount: 0,
475
523
  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,13 +347,15 @@ 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: {
350
354
  itemOffered: { serviceOutput: { id: reservation.id } },
351
355
  seatNumber: '',
352
356
  seatSection: ''
353
- }
357
+ },
358
+ holder: params.expectedHolder
354
359
  };
355
360
  let holder = yield repos.stockHolder.getHolder(lockKey);
356
361
  if (holder === params.expectedHolder) {
@@ -360,12 +365,14 @@ function processUnlockSeat(params) {
360
365
  const ticketedSeat = reservation.reservedTicket.ticketedSeat;
361
366
  if (ticketedSeat !== undefined) {
362
367
  lockKey = {
368
+ project: reservation.project,
363
369
  eventId: reservation.reservationFor.id,
364
370
  startDate: eventStartDate,
365
371
  offer: {
366
372
  seatNumber: ticketedSeat.seatNumber,
367
373
  seatSection: ticketedSeat.seatSection
368
- }
374
+ },
375
+ holder: params.expectedHolder
369
376
  };
370
377
  holder = yield repos.stockHolder.getHolder(lockKey);
371
378
  if (holder === params.expectedHolder) {
@@ -381,12 +388,14 @@ function processUnlockSeat(params) {
381
388
  const seatNumber4sub = (_d = (_c = subReservation.reservedTicket) === null || _c === void 0 ? void 0 : _c.ticketedSeat) === null || _d === void 0 ? void 0 : _d.seatNumber;
382
389
  if (typeof seatSection4sub === 'string' && typeof seatNumber4sub === 'string') {
383
390
  const lockKey4sub = {
391
+ project: reservation.project,
384
392
  eventId: reservation.reservationFor.id,
385
393
  startDate: eventStartDate,
386
394
  offer: {
387
395
  seatNumber: seatNumber4sub,
388
396
  seatSection: seatSection4sub
389
- }
397
+ },
398
+ holder: params.expectedHolder
390
399
  };
391
400
  const holder4sub = yield repos.stockHolder.getHolder(lockKey4sub);
392
401
  if (holder4sub === params.expectedHolder) {
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.120"
120
+ "version": "21.2.0-alpha.122"
121
121
  }