@chevre/domain 22.11.0-alpha.9 → 22.11.0

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.
Files changed (149) hide show
  1. package/example/src/chevre/aggregation/aggregateOrderOfCustomer.ts +21 -10
  2. package/example/src/chevre/aggregation/aggregateTasks.ts +41 -0
  3. package/example/src/chevre/checkCustomerAttributesLength.ts +109 -0
  4. package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
  5. package/example/src/chevre/reIndex.ts +1 -1
  6. package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
  7. package/example/src/chevre/roles/{addAdminInventoryManagerRole.ts → addProjectCreatorRole.ts} +6 -8
  8. package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
  9. package/example/src/chevre/roles/findPermissions.ts +84 -0
  10. package/example/src/chevre/roles/findRoleNames.ts +117 -0
  11. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
  12. package/example/src/chevre/searchEventSeats.ts +1 -1
  13. package/example/src/chevre/searchProducts.ts +28 -0
  14. package/example/src/chevre/settings/addSettings.ts +31 -17
  15. package/example/src/chevre/task/countPotentiallyRunning.ts +41 -0
  16. package/example/src/chevre/task/countTasks.ts +51 -0
  17. package/example/src/chevre/{deleteRunsAtPassedCertainPeriod.ts → task/deleteRunsAtPassedCertainPeriod.ts} +4 -3
  18. package/example/src/chevre/task/deleteUnexpectedTasks.ts +23 -0
  19. package/example/src/chevre/task/emitRunning.ts +89 -0
  20. package/example/src/idaas/auth0/adminApplications.ts +183 -0
  21. package/example/src/idaas/auth0/getToken.ts +55 -0
  22. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
  23. package/example/src/regex.ts +31 -0
  24. package/lib/chevre/eventEmitter/task.d.ts +29 -6
  25. package/lib/chevre/index.d.ts +0 -2
  26. package/lib/chevre/index.js +0 -10
  27. package/lib/chevre/repo/member.d.ts +22 -4
  28. package/lib/chevre/repo/member.js +81 -27
  29. package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
  30. package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
  31. package/lib/chevre/repo/mongoose/schemas/product.js +9 -0
  32. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +15 -0
  33. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
  34. package/lib/chevre/repo/mongoose/schemas/task.js +9 -0
  35. package/lib/chevre/repo/order.d.ts +17 -2
  36. package/lib/chevre/repo/order.js +47 -8
  37. package/lib/chevre/repo/pendingReservation.js +1 -0
  38. package/lib/chevre/repo/product.js +12 -17
  39. package/lib/chevre/repo/role.d.ts +5 -4
  40. package/lib/chevre/repo/role.js +35 -32
  41. package/lib/chevre/repo/setting.d.ts +1 -10
  42. package/lib/chevre/repo/setting.js +2 -11
  43. package/lib/chevre/repo/stockHolder.d.ts +4 -27
  44. package/lib/chevre/repo/stockHolder.js +163 -175
  45. package/lib/chevre/repo/task.d.ts +58 -38
  46. package/lib/chevre/repo/task.js +126 -296
  47. package/lib/chevre/repo/transaction.js +10 -10
  48. package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
  49. package/lib/chevre/service/assetTransaction/registerService.js +4 -0
  50. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +19 -16
  51. package/lib/chevre/service/code.d.ts +5 -28
  52. package/lib/chevre/service/code.js +3 -79
  53. package/lib/chevre/service/iam.d.ts +17 -7
  54. package/lib/chevre/service/iam.js +26 -6
  55. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
  56. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
  57. package/lib/chevre/service/notification.d.ts +2 -1
  58. package/lib/chevre/service/notification.js +3 -1
  59. package/lib/chevre/service/offer/product.js +4 -0
  60. package/lib/chevre/service/order/confirmPayTransaction.d.ts +6 -1
  61. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +3 -3
  62. package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
  63. package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
  64. package/lib/chevre/service/task/aggregateOffers.js +1 -1
  65. package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
  66. package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
  67. package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
  68. package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
  69. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
  70. package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
  71. package/lib/chevre/service/task/cancelPendingReservation.js +1 -1
  72. package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
  73. package/lib/chevre/service/task/cancelReservation.js +1 -1
  74. package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
  75. package/lib/chevre/service/task/checkResource.d.ts +1 -1
  76. package/lib/chevre/service/task/checkResource.js +1 -1
  77. package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
  78. package/lib/chevre/service/task/confirmPayTransaction.d.ts +2 -2
  79. package/lib/chevre/service/task/confirmPayTransaction.js +3 -2
  80. package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
  81. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  82. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +6 -2
  83. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
  84. package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
  85. package/lib/chevre/service/task/createEvent.d.ts +1 -1
  86. package/lib/chevre/service/task/deletePerson.d.ts +1 -1
  87. package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
  88. package/lib/chevre/service/task/givePointAward.d.ts +1 -1
  89. package/lib/chevre/service/task/handleNotification.d.ts +4 -2
  90. package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
  91. package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
  92. package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
  93. package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
  94. package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
  95. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
  96. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
  97. package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
  98. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
  99. package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
  100. package/lib/chevre/service/task/pay.d.ts +1 -1
  101. package/lib/chevre/service/task/placeOrder.d.ts +1 -1
  102. package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
  103. package/lib/chevre/service/task/refund.d.ts +1 -1
  104. package/lib/chevre/service/task/registerService.d.ts +1 -1
  105. package/lib/chevre/service/task/reserve.d.ts +1 -1
  106. package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
  107. package/lib/chevre/service/task/returnOrder.d.ts +1 -1
  108. package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
  109. package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
  110. package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
  111. package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
  112. package/lib/chevre/service/task/sendOrder.d.ts +1 -1
  113. package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
  114. package/lib/chevre/service/task/useReservation.d.ts +1 -1
  115. package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
  116. package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
  117. package/lib/chevre/service/task/voidPayment.d.ts +1 -1
  118. package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
  119. package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
  120. package/lib/chevre/service/task/voidReserveTransaction.js +1 -1
  121. package/lib/chevre/service/task.d.ts +7 -29
  122. package/lib/chevre/service/task.js +9 -114
  123. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.d.ts +11 -0
  124. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +105 -0
  125. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +17 -0
  126. package/lib/chevre/service/taskHandler/onOperationFailed.js +70 -0
  127. package/lib/chevre/service/taskHandler.d.ts +26 -0
  128. package/lib/chevre/service/taskHandler.js +97 -0
  129. package/lib/chevre/service/validation/validateEvent.d.ts +2 -2
  130. package/lib/chevre/service/validation/validateEvent.js +16 -10
  131. package/lib/chevre/service.d.ts +0 -4
  132. package/lib/chevre/service.js +10 -14
  133. package/lib/chevre/settings/aggregation.d.ts +6 -1
  134. package/lib/chevre/settings/aggregation.js +2 -1
  135. package/package.json +6 -4
  136. package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
  137. package/example/src/chevre/executeOneTask.ts +0 -41
  138. package/example/src/chevre/executeTaskIfExists.ts +0 -80
  139. package/example/src/chevre/findExecutableTask.ts +0 -50
  140. package/example/src/chevre/findSetting.ts +0 -79
  141. package/example/src/chevre/searchPermissions.ts +0 -46
  142. package/example/src/chevre/searchProductOffers.ts +0 -29
  143. package/example/src/chevre/stockHolder/checkIfConflicted.ts +0 -76
  144. package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +0 -186
  145. package/example/src/chevre/stockHolder/migratePendingReservations.ts +0 -96
  146. package/example/src/chevre/stockHolder/playAroundStockHolder.ts +0 -256
  147. package/example/src/chevre/upsertProductsByProductId.ts +0 -100
  148. package/lib/chevre/adminAuth.d.ts +0 -2
  149. package/lib/chevre/adminAuth.js +0 -6
@@ -77,39 +77,42 @@ class RoleRepo {
77
77
  .exec();
78
78
  });
79
79
  }
80
- aggregatePermissions(params) {
80
+ // migrate to findDistinctPermissionsByRoleName(2025-07-21~)
81
+ // public async aggregatePermissions(params: {
82
+ // roleName: { $in: string[] };
83
+ // }): Promise<{ _id: string }[]> {
84
+ // const matchStages: IMatchStage[] = [
85
+ // { $match: { roleName: { $in: params.roleName.$in } } }
86
+ // ];
87
+ // const aggregate = this.roleModel.aggregate([
88
+ // ...matchStages,
89
+ // {
90
+ // $unwind: {
91
+ // path: '$permissions'
92
+ // }
93
+ // },
94
+ // {
95
+ // $project: {
96
+ // _id: 0,
97
+ // permission: '$permissions'
98
+ // }
99
+ // },
100
+ // {
101
+ // $group: {
102
+ // _id: '$permission'
103
+ // }
104
+ // }
105
+ // ]);
106
+ // return aggregate.option({ maxTimeMS: MONGO_MAX_TIME_MS })
107
+ // .exec();
108
+ // }
109
+ /**
110
+ * distinctコマンドを使用して、ロールから権限を検索する
111
+ */
112
+ findUniquePermissionsByRoleName(params) {
81
113
  return __awaiter(this, void 0, void 0, function* () {
82
- const matchStages = [
83
- { $match: { roleName: { $in: params.roleName.$in } } }
84
- ];
85
- const aggregate = this.roleModel.aggregate([
86
- // ...(typeof params.sort?.productID === 'number')
87
- // ? [{ $sort: { productID: params.sort.productID } }]
88
- // : [],
89
- ...matchStages,
90
- {
91
- $unwind: {
92
- path: '$permissions'
93
- }
94
- },
95
- {
96
- $project: {
97
- _id: 0,
98
- permission: '$permissions'
99
- }
100
- },
101
- {
102
- $group: {
103
- _id: '$permission'
104
- }
105
- }
106
- ]);
107
- // if (typeof params.limit === 'number' && params.limit > 0) {
108
- // const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
109
- // aggregate.limit(params.limit * page)
110
- // .skip(params.limit * (page - 1));
111
- // }
112
- return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
114
+ return this.roleModel.distinct('permissions', { roleName: { $in: params.roleName.$in } })
115
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
113
116
  .exec();
114
117
  });
115
118
  }
@@ -22,16 +22,7 @@ export declare class SettingRepo {
22
22
  $eq: string;
23
23
  };
24
24
  };
25
- }, update: Pick<ISetting, 'onEventChanged' | 'onReservationStatusChanged' | 'onResourceUpdated' | 'defaultSenderEmail' | 'useInformResourceTypes' | 'userPoolIdNew' | 'userPoolIdOld' | 'storage' | 'quota' | 'triggerWebhook' | 'waiter'>): Promise<import("mongoose").UpdateWriteOpResult>;
26
- updateByProject4migration(filter: {
27
- project: {
28
- id: {
29
- $eq: string;
30
- };
31
- };
32
- }, update: {
33
- $set: any;
34
- }): Promise<import("mongoose").UpdateWriteOpResult>;
25
+ }, update: Pick<ISetting, 'onEventChanged' | 'onReservationStatusChanged' | 'onTaskStatusChanged' | 'onResourceUpdated' | 'defaultSenderEmail' | 'useInformResourceTypes' | 'userPoolIdNew' | 'userPoolIdOld' | 'storage' | 'quota' | 'triggerWebhook' | 'waiter'>): Promise<import("mongoose").UpdateWriteOpResult>;
35
26
  unsetUnnecessaryFields(params: {
36
27
  filter: FilterQuery<ISetting>;
37
28
  $unset: any;
@@ -49,18 +49,9 @@ class SettingRepo {
49
49
  }
50
50
  updateByProject(filter, update) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- const { onEventChanged, onReservationStatusChanged, onResourceUpdated, defaultSenderEmail, useInformResourceTypes, userPoolIdNew, userPoolIdOld, storage, quota, triggerWebhook, waiter } = update;
52
+ const { onEventChanged, onReservationStatusChanged, onTaskStatusChanged, onResourceUpdated, defaultSenderEmail, useInformResourceTypes, userPoolIdNew, userPoolIdOld, storage, quota, triggerWebhook, waiter } = update;
53
53
  return this.settingModel.updateOne({ 'project.id': { $eq: filter.project.id.$eq } }, {
54
- $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (onEventChanged !== undefined) ? { onEventChanged } : undefined), (onReservationStatusChanged !== undefined) ? { onReservationStatusChanged } : undefined), (onResourceUpdated !== undefined) ? { onResourceUpdated } : undefined), (defaultSenderEmail !== undefined) ? { defaultSenderEmail } : undefined), (useInformResourceTypes !== undefined) ? { useInformResourceTypes } : undefined), (userPoolIdNew !== undefined) ? { userPoolIdNew } : undefined), (userPoolIdOld !== undefined) ? { userPoolIdOld } : undefined), (storage !== undefined) ? { storage } : undefined), (quota !== undefined) ? { quota } : undefined), (triggerWebhook !== undefined) ? { triggerWebhook } : undefined), (waiter !== undefined) ? { waiter } : undefined)
55
- })
56
- .exec();
57
- });
58
- }
59
- updateByProject4migration(filter, update) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const { $set } = update;
62
- return this.settingModel.updateOne({ 'project.id': { $eq: filter.project.id.$eq } }, {
63
- $set
54
+ $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (onEventChanged !== undefined) ? { onEventChanged } : undefined), (onReservationStatusChanged !== undefined) ? { onReservationStatusChanged } : undefined), (onTaskStatusChanged !== undefined) ? { onTaskStatusChanged } : undefined), (onResourceUpdated !== undefined) ? { onResourceUpdated } : undefined), (defaultSenderEmail !== undefined) ? { defaultSenderEmail } : undefined), (useInformResourceTypes !== undefined) ? { useInformResourceTypes } : undefined), (userPoolIdNew !== undefined) ? { userPoolIdNew } : undefined), (userPoolIdOld !== undefined) ? { userPoolIdOld } : undefined), (storage !== undefined) ? { storage } : undefined), (quota !== undefined) ? { quota } : undefined), (triggerWebhook !== undefined) ? { triggerWebhook } : undefined), (waiter !== undefined) ? { waiter } : undefined)
64
55
  })
65
56
  .exec();
66
57
  });
@@ -1,17 +1,14 @@
1
1
  import type { Connection } from 'mongoose';
2
- import type { RedisClientType } from 'redis';
3
2
  import { AbstractStockHolderRepo, IGetHolderResult, ILockKey, IOffer, IUnlockKey } from './stockHolderAbstract';
4
3
  export { ILockKey, IOffer, IUnlockKey };
5
4
  /**
6
- * イベントストックホルダーリポジトリ
5
+ * 保留予約リポジトリ
7
6
  */
8
7
  export declare class StockHolderRepo implements AbstractStockHolderRepo {
9
- static KEY_PREFIX_NEW: string;
10
- private readonly redisClient;
11
8
  private readonly pendingReservationRepo;
12
- constructor(redisClient: RedisClientType, connection: Connection);
13
- private static offer2field;
14
- private static createKey;
9
+ constructor(params: {
10
+ connection: Connection;
11
+ });
15
12
  /**
16
13
  * 座席をロックする(maxキャパシティチェック有)
17
14
  */
@@ -50,26 +47,6 @@ export declare class StockHolderRepo implements AbstractStockHolderRepo {
50
47
  hasTicketedSeat: boolean;
51
48
  offers: IOffer[];
52
49
  }): Promise<IGetHolderResult[]>;
53
- redisKeyExists(params: {
54
- eventId: string;
55
- startDate: Date;
56
- }): Promise<boolean>;
57
- checkIfConflicted(params: {
58
- eventId: string;
59
- startDate: Date;
60
- }): Promise<void>;
61
- /**
62
- * 万が一に備えて、保留予約をredis->mongo移行
63
- */
64
- migrate2mongoJustInCase(params: {
65
- eventId: string;
66
- startDate: Date;
67
- }): Promise<{
68
- expireTime: number;
69
- hash: {
70
- [x: string]: string;
71
- };
72
- }>;
73
50
  /**
74
51
  * 新リポジトリを使用するかどうか
75
52
  */
@@ -10,71 +10,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.StockHolderRepo = void 0;
13
- const createDebug = require("debug");
14
- const moment = require("moment");
13
+ // import type { RedisClientType } from 'redis';
15
14
  const factory = require("../factory");
16
- // import { createSchema, IModel, ISetting, modelName } from './mongoose/schemas/setting';
17
15
  const pendingReservation_1 = require("./pendingReservation");
18
- const debug = createDebug('chevre-domain:repo:stockHolder');
19
16
  const SEARCH_OFFERS_MAX_LENGTH = 100;
20
- const USE_STOCK_HOLDER_CHECK_CONFLICT = process.env.USE_STOCK_HOLDER_CHECK_CONFLICT === '1';
21
17
  /**
22
- * イベントストックホルダーリポジトリ
18
+ * 保留予約リポジトリ
23
19
  */
24
20
  class StockHolderRepo {
25
- constructor(redisClient, connection) {
26
- this.redisClient = redisClient;
27
- // this.settingModel = connection.model(modelName, createSchema());
21
+ constructor(params) {
22
+ const { connection } = params;
23
+ // this.redisClient = redisClient;
28
24
  this.pendingReservationRepo = new pendingReservation_1.PendingReservationRepo(connection);
29
25
  }
30
- static offer2field(params, hasTicketedSeat) {
31
- var _a, _b;
32
- if (hasTicketedSeat) {
33
- return `${params.seatSection}:${params.seatNumber}`;
34
- }
35
- else {
36
- // 予約IDをfieldにする場合
37
- const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
38
- if (typeof serviceOutputId === 'string') {
39
- return serviceOutputId;
40
- }
41
- else {
42
- throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
43
- }
44
- }
45
- }
46
- static createKey(params) {
47
- if (!(params.startDate instanceof Date)) {
48
- throw new factory.errors.Argument('startDate', 'must be Date');
49
- }
50
- return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
51
- }
26
+ // private static offer2field(params: IOffer, hasTicketedSeat: boolean) {
27
+ // if (hasTicketedSeat) {
28
+ // return `${params.seatSection}:${params.seatNumber}`;
29
+ // } else {
30
+ // // 予約IDをfieldにする場合
31
+ // const serviceOutputId = params.itemOffered?.serviceOutput?.id;
32
+ // if (typeof serviceOutputId === 'string') {
33
+ // return serviceOutputId;
34
+ // } else {
35
+ // throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
36
+ // }
37
+ // }
38
+ // }
39
+ // private static createKey(params: {
40
+ // eventId: string;
41
+ // startDate: Date;
42
+ // }): string {
43
+ // if (!(params.startDate instanceof Date)) {
44
+ // throw new factory.errors.Argument('startDate', 'must be Date');
45
+ // }
46
+ // return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
47
+ // }
52
48
  /**
53
49
  * 座席をロックする(maxキャパシティチェック有)
54
50
  */
55
51
  lockIfNotLimitExceeded(lockKey, maximum) {
56
52
  return __awaiter(this, void 0, void 0, function* () {
57
- const useMongoose = yield this.useMongoose({
53
+ const useMongoose = this.useMongoose({
58
54
  project: { id: lockKey.project.id },
59
55
  eventId: lockKey.eventId,
60
56
  startDate: lockKey.startDate,
61
57
  hasTicketedSeat: lockKey.hasTicketedSeat
62
58
  });
63
59
  if (useMongoose) {
64
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
65
60
  return this.pendingReservationRepo.lockIfNotLimitExceeded(lockKey, maximum);
66
61
  }
67
62
  else {
68
- const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
69
- yield this.redisClient.watch(key);
70
- const hashCount = yield this.redisClient.hLen(key);
71
- // Process result
72
- // Heavy and time consuming operation here
73
- debug('checking hash count...hashCount:', hashCount);
74
- if (hashCount + lockKey.offers.length > maximum) {
75
- throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
76
- }
77
- yield this.lock(lockKey);
63
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
64
+ // if (this.redisClient === undefined) {
65
+ // throw new factory.errors.Internal('redisClient required');
66
+ // }
67
+ // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
68
+ // await this.redisClient.watch(key);
69
+ // const hashCount = await this.redisClient.hLen(key);
70
+ // if (hashCount + lockKey.offers.length > maximum) {
71
+ // throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
72
+ // }
73
+ // await this.lock(lockKey);
78
74
  }
79
75
  });
80
76
  }
@@ -87,62 +83,65 @@ class StockHolderRepo {
87
83
  if (!(lockKey.expires instanceof Date)) {
88
84
  throw new factory.errors.Argument('expires', 'must be Date');
89
85
  }
90
- const useMongoose = yield this.useMongoose({
86
+ const useMongoose = this.useMongoose({
91
87
  project: { id: lockKey.project.id },
92
88
  eventId: lockKey.eventId,
93
89
  startDate: lockKey.startDate,
94
90
  hasTicketedSeat: lockKey.hasTicketedSeat
95
91
  });
96
- const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
92
+ // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
97
93
  // await this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
98
94
  if (useMongoose) {
99
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
100
95
  return this.pendingReservationRepo.lock(lockKey);
101
96
  }
102
97
  else {
103
- const value = lockKey.holder;
104
- const multi = this.redisClient.multi();
105
- const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
106
- // check uniqueness(2025-04-20~)
107
- const uniqueFields = [...new Set(fields)];
108
- if (uniqueFields.length !== fields.length) {
109
- throw new factory.errors.Argument('offers', 'offers must be unique');
110
- }
111
- fields.forEach((field) => {
112
- multi.hSetNX(key, field, value);
113
- });
114
- const results = yield multi.expireAt(key, moment(lockKey.expires)
115
- .unix())
116
- .exec();
117
- const lockedFields = [];
118
- if (Array.isArray(results)) {
119
- results.slice(0, fields.length)
120
- .forEach((r, index) => {
121
- if (r === 1 || r === true) {
122
- lockedFields.push(fields[index]);
123
- }
124
- });
125
- }
126
- const lockedAll = lockedFields.length === fields.length;
127
- debug('lockedAll?', lockedAll);
128
- // expireAtReplyの検証も追加する(2023-04-19~)
129
- const expiredAll = results.slice(fields.length)
130
- .every((r) => (r === 1 || r === true));
131
- debug('expiredAll?', expiredAll);
132
- if (!lockedAll || !expiredAll) {
133
- if (lockedFields.length > 0) {
134
- // 全て仮押さえできなければ仮押さえできたものは解除
135
- yield this.redisClient.multi()
136
- .hDel(key, lockedFields)
137
- .exec();
138
- }
139
- if (!lockedAll) {
140
- throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
141
- }
142
- else {
143
- throw new factory.errors.Internal('timeout cannot be set unexpectedly');
144
- }
145
- }
98
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
99
+ // if (this.redisClient === undefined) {
100
+ // throw new factory.errors.Internal('redisClient required');
101
+ // }
102
+ // const value = lockKey.holder;
103
+ // const multi = this.redisClient.multi();
104
+ // const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
105
+ // // check uniqueness(2025-04-20~)
106
+ // const uniqueFields = [...new Set(fields)];
107
+ // if (uniqueFields.length !== fields.length) {
108
+ // throw new factory.errors.Argument('offers', 'offers must be unique');
109
+ // }
110
+ // fields.forEach((field) => {
111
+ // multi.hSetNX(key, field, value);
112
+ // });
113
+ // const results = await multi.expireAt(
114
+ // key,
115
+ // moment(lockKey.expires)
116
+ // .unix()
117
+ // )
118
+ // .exec();
119
+ // const lockedFields: string[] = [];
120
+ // if (Array.isArray(results)) {
121
+ // results.slice(0, fields.length)
122
+ // .forEach((r, index) => {
123
+ // if (r === 1 || (<any>r) === true) {
124
+ // lockedFields.push(fields[index]);
125
+ // }
126
+ // });
127
+ // }
128
+ // const lockedAll = lockedFields.length === fields.length;
129
+ // // expireAtReplyの検証も追加する(2023-04-19~)
130
+ // const expiredAll = results.slice(fields.length)
131
+ // .every((r) => (r === 1 || (<any>r) === true));
132
+ // if (!lockedAll || !expiredAll) {
133
+ // if (lockedFields.length > 0) {
134
+ // // 全て仮押さえできなければ仮押さえできたものは解除
135
+ // await this.redisClient.multi()
136
+ // .hDel(key, lockedFields)
137
+ // .exec();
138
+ // }
139
+ // if (!lockedAll) {
140
+ // throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
141
+ // } else {
142
+ // throw new factory.errors.Internal('timeout cannot be set unexpectedly');
143
+ // }
144
+ // }
146
145
  }
147
146
  });
148
147
  }
@@ -151,23 +150,26 @@ class StockHolderRepo {
151
150
  */
152
151
  unlock(params) {
153
152
  return __awaiter(this, void 0, void 0, function* () {
154
- const useMongoose = yield this.useMongoose({
153
+ const useMongoose = this.useMongoose({
155
154
  project: { id: params.project.id },
156
155
  eventId: params.eventId,
157
156
  startDate: params.startDate,
158
157
  hasTicketedSeat: params.hasTicketedSeat
159
158
  });
160
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
159
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
161
160
  // await this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
162
161
  if (useMongoose) {
163
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
164
162
  return this.pendingReservationRepo.unlock(params);
165
163
  }
166
164
  else {
167
- const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
168
- yield this.redisClient.multi()
169
- .hDel(key, field)
170
- .exec();
165
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
166
+ // if (this.redisClient === undefined) {
167
+ // throw new factory.errors.Internal('redisClient required');
168
+ // }
169
+ // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
170
+ // await this.redisClient.multi()
171
+ // .hDel(key, field)
172
+ // .exec();
171
173
  }
172
174
  });
173
175
  }
@@ -176,23 +178,26 @@ class StockHolderRepo {
176
178
  */
177
179
  countUnavailableOffers(params) {
178
180
  return __awaiter(this, void 0, void 0, function* () {
179
- if (yield this.useMongoose({
181
+ if (this.useMongoose({
180
182
  project: { id: params.project.id },
181
183
  eventId: params.event.id,
182
184
  startDate: params.event.startDate,
183
185
  hasTicketedSeat: params.event.hasTicketedSeat
184
186
  })) {
185
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
186
187
  return this.pendingReservationRepo.countUnavailableOffers(params);
187
188
  }
188
189
  else {
189
- const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
190
- const reply = yield this.redisClient.hLen(key);
191
- let fieldCount = 0;
192
- if (typeof reply === 'number') {
193
- fieldCount = Number(reply);
194
- }
195
- return fieldCount;
190
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
191
+ // if (this.redisClient === undefined) {
192
+ // throw new factory.errors.Internal('redisClient required');
193
+ // }
194
+ // const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
195
+ // const reply = await this.redisClient.hLen(key);
196
+ // let fieldCount: number = 0;
197
+ // if (typeof reply === 'number') {
198
+ // fieldCount = Number(reply);
199
+ // }
200
+ // return fieldCount;
196
201
  }
197
202
  });
198
203
  }
@@ -201,19 +206,22 @@ class StockHolderRepo {
201
206
  */
202
207
  getHolder(params) {
203
208
  return __awaiter(this, void 0, void 0, function* () {
204
- if (yield this.useMongoose({
209
+ if (this.useMongoose({
205
210
  project: { id: params.project.id },
206
211
  eventId: params.eventId,
207
212
  startDate: params.startDate,
208
213
  hasTicketedSeat: params.hasTicketedSeat
209
214
  })) {
210
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
211
215
  return this.pendingReservationRepo.getHolder(params);
212
216
  }
213
217
  else {
214
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
215
- const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
216
- return this.redisClient.hGet(key, field);
218
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
219
+ // if (this.redisClient === undefined) {
220
+ // throw new factory.errors.Internal('redisClient required');
221
+ // }
222
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
223
+ // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
224
+ // return this.redisClient.hGet(key, field);
217
225
  }
218
226
  });
219
227
  }
@@ -223,86 +231,66 @@ class StockHolderRepo {
223
231
  if (params.offers.length > SEARCH_OFFERS_MAX_LENGTH) {
224
232
  throw new factory.errors.Argument('offers', `offers.length must be <= ${SEARCH_OFFERS_MAX_LENGTH}`);
225
233
  }
226
- if (yield this.useMongoose({
234
+ if (this.useMongoose({
227
235
  project: { id: params.project.id },
228
236
  eventId: params.eventId,
229
237
  startDate: params.startDate,
230
238
  hasTicketedSeat: params.hasTicketedSeat
231
239
  })) {
232
- // throw new factory.errors.NotImplemented('new stock holder repository not implemented');
233
240
  return this.pendingReservationRepo.searchHolders(params);
234
241
  }
235
242
  else {
236
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
237
- const fields = params.offers.map((o) => {
238
- return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
239
- });
240
- // Array reply: list of values associated with the given fields, in the same order as they are requested.
241
- const result = yield this.redisClient.hmGet(key, fields);
242
- if (!Array.isArray(result)) {
243
- throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
244
- }
245
- // そのまま返却(2023-04-17~)
246
- return result;
247
- }
248
- });
249
- }
250
- redisKeyExists(params) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- const key = StockHolderRepo.createKey(params);
253
- const existingRedisKeyCount = yield this.redisClient.exists(key);
254
- if (typeof existingRedisKeyCount !== 'number') {
255
- throw new factory.errors.Internal(`unexpected existingKeyCount: ${typeof existingRedisKeyCount}`);
243
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
244
+ // if (this.redisClient === undefined) {
245
+ // throw new factory.errors.Internal('redisClient required');
246
+ // }
247
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
248
+ // const fields = params.offers.map((o) => {
249
+ // return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
250
+ // });
251
+ // // Array reply: list of values associated with the given fields, in the same order as they are requested.
252
+ // const result = await this.redisClient.hmGet(key, fields);
253
+ // if (!Array.isArray(result)) {
254
+ // throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
255
+ // }
256
+ // // そのまま返却(2023-04-17~)
257
+ // return result;
256
258
  }
257
- return existingRedisKeyCount > 0;
258
- });
259
- }
260
- checkIfConflicted(params) {
261
- return __awaiter(this, void 0, void 0, function* () {
262
- const redisKeyExists = yield this.redisKeyExists(params);
263
- const mongoDocExists = yield this.pendingReservationRepo.docExists(params);
264
- if (redisKeyExists && mongoDocExists) {
265
- throw new factory.errors.Internal(`repository conflicted. eventId:${params.eventId}`);
266
- }
267
- });
268
- }
269
- /**
270
- * 万が一に備えて、保留予約をredis->mongo移行
271
- */
272
- migrate2mongoJustInCase(params) {
273
- return __awaiter(this, void 0, void 0, function* () {
274
- const redisKey = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
275
- return {
276
- expireTime: yield this.redisClient.expireTime(redisKey),
277
- hash: yield this.redisClient.hGetAll(redisKey)
278
- };
279
259
  });
280
260
  }
261
+ // public async checkIfConflicted(params: {
262
+ // eventId: string;
263
+ // startDate: Date;
264
+ // }): Promise<void> {
265
+ // const redisKeyExists = await this.redisKeyExists(params);
266
+ // const mongoDocExists = await this.pendingReservationRepo.docExists(params);
267
+ // if (redisKeyExists && mongoDocExists) {
268
+ // throw new factory.errors.Internal(`repository conflicted. eventId:${params.eventId}`);
269
+ // }
270
+ // }
281
271
  /**
282
272
  * 新リポジトリを使用するかどうか
283
273
  */
274
+ // tslint:disable-next-line:prefer-function-over-method
284
275
  useMongoose(params) {
285
- return __awaiter(this, void 0, void 0, function* () {
286
- if (!(params.startDate instanceof Date)) {
287
- throw new factory.errors.Argument('startDate', 'must be Date');
288
- }
289
- let useMongoose = false;
290
- // always use mongo(2025-05-21~)
291
- const redisKeyExists = yield this.redisKeyExists(params);
292
- if (redisKeyExists) {
293
- useMongoose = false;
294
- }
295
- else {
296
- // redis keyが存在しなければmongo利用
297
- useMongoose = true;
298
- }
299
- // check confliction for test
300
- if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
301
- yield this.checkIfConflicted(params);
302
- }
303
- return useMongoose;
304
- });
276
+ if (!(params.startDate instanceof Date)) {
277
+ throw new factory.errors.Argument('startDate', 'must be Date');
278
+ }
279
+ // always use mongo(2025-08-17~)
280
+ return true;
281
+ // let useMongoose = false;
282
+ // const redisKeyExists = await this.redisKeyExists(params);
283
+ // if (redisKeyExists) {
284
+ // useMongoose = false;
285
+ // } else {
286
+ // // redis keyが存在しなければmongo利用
287
+ // useMongoose = true;
288
+ // }
289
+ // // check confliction for test
290
+ // if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
291
+ // await this.checkIfConflicted(params);
292
+ // }
293
+ // return useMongoose;
305
294
  }
306
295
  }
307
296
  exports.StockHolderRepo = StockHolderRepo;
308
- StockHolderRepo.KEY_PREFIX_NEW = 'stockHolder';