@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.
- package/example/src/chevre/aggregation/aggregateOrderOfCustomer.ts +21 -10
- package/example/src/chevre/aggregation/aggregateTasks.ts +41 -0
- package/example/src/chevre/checkCustomerAttributesLength.ts +109 -0
- package/example/src/chevre/notifyAbortedTasksByEmail.ts +1 -1
- package/example/src/chevre/reIndex.ts +1 -1
- package/example/src/chevre/roles/addEventOfferPermissionIfNotExists.ts +27 -0
- package/example/src/chevre/roles/{addAdminInventoryManagerRole.ts → addProjectCreatorRole.ts} +6 -8
- package/example/src/chevre/roles/assignGlobalRoles.ts +72 -0
- package/example/src/chevre/roles/findPermissions.ts +84 -0
- package/example/src/chevre/roles/findRoleNames.ts +117 -0
- package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +38 -0
- package/example/src/chevre/searchEventSeats.ts +1 -1
- package/example/src/chevre/searchProducts.ts +28 -0
- package/example/src/chevre/settings/addSettings.ts +31 -17
- package/example/src/chevre/task/countPotentiallyRunning.ts +41 -0
- package/example/src/chevre/task/countTasks.ts +51 -0
- package/example/src/chevre/{deleteRunsAtPassedCertainPeriod.ts → task/deleteRunsAtPassedCertainPeriod.ts} +4 -3
- package/example/src/chevre/task/deleteUnexpectedTasks.ts +23 -0
- package/example/src/chevre/task/emitRunning.ts +89 -0
- package/example/src/idaas/auth0/adminApplications.ts +183 -0
- package/example/src/idaas/auth0/getToken.ts +55 -0
- package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +84 -0
- package/example/src/regex.ts +31 -0
- package/lib/chevre/eventEmitter/task.d.ts +29 -6
- package/lib/chevre/index.d.ts +0 -2
- package/lib/chevre/index.js +0 -10
- package/lib/chevre/repo/member.d.ts +22 -4
- package/lib/chevre/repo/member.js +81 -27
- package/lib/chevre/repo/mongoose/schemas/member/global.d.ts +14 -0
- package/lib/chevre/repo/mongoose/schemas/member/global.js +82 -0
- package/lib/chevre/repo/mongoose/schemas/product.js +9 -0
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +15 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +1 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +9 -0
- package/lib/chevre/repo/order.d.ts +17 -2
- package/lib/chevre/repo/order.js +47 -8
- package/lib/chevre/repo/pendingReservation.js +1 -0
- package/lib/chevre/repo/product.js +12 -17
- package/lib/chevre/repo/role.d.ts +5 -4
- package/lib/chevre/repo/role.js +35 -32
- package/lib/chevre/repo/setting.d.ts +1 -10
- package/lib/chevre/repo/setting.js +2 -11
- package/lib/chevre/repo/stockHolder.d.ts +4 -27
- package/lib/chevre/repo/stockHolder.js +163 -175
- package/lib/chevre/repo/task.d.ts +58 -38
- package/lib/chevre/repo/task.js +126 -296
- package/lib/chevre/repo/transaction.js +10 -10
- package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/registerService.js +4 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +19 -16
- package/lib/chevre/service/code.d.ts +5 -28
- package/lib/chevre/service/code.js +3 -79
- package/lib/chevre/service/iam.d.ts +17 -7
- package/lib/chevre/service/iam.js +26 -6
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
- package/lib/chevre/service/notification.d.ts +2 -1
- package/lib/chevre/service/notification.js +3 -1
- package/lib/chevre/service/offer/product.js +4 -0
- package/lib/chevre/service/order/confirmPayTransaction.d.ts +6 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +3 -3
- package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOffers.js +1 -1
- package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
- package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
- package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
- package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
- package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
- package/lib/chevre/service/task/cancelPendingReservation.js +1 -1
- package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
- package/lib/chevre/service/task/cancelReservation.js +1 -1
- package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
- package/lib/chevre/service/task/checkResource.d.ts +1 -1
- package/lib/chevre/service/task/checkResource.js +1 -1
- package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/confirmPayTransaction.d.ts +2 -2
- package/lib/chevre/service/task/confirmPayTransaction.js +3 -2
- package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +6 -2
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
- package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
- package/lib/chevre/service/task/createEvent.d.ts +1 -1
- package/lib/chevre/service/task/deletePerson.d.ts +1 -1
- package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.d.ts +1 -1
- package/lib/chevre/service/task/handleNotification.d.ts +4 -2
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
- package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
- package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
- package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
- package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
- package/lib/chevre/service/task/pay.d.ts +1 -1
- package/lib/chevre/service/task/placeOrder.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/refund.d.ts +1 -1
- package/lib/chevre/service/task/registerService.d.ts +1 -1
- package/lib/chevre/service/task/reserve.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/returnOrder.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
- package/lib/chevre/service/task/sendOrder.d.ts +1 -1
- package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
- package/lib/chevre/service/task/useReservation.d.ts +1 -1
- package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayment.d.ts +1 -1
- package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.js +1 -1
- package/lib/chevre/service/task.d.ts +7 -29
- package/lib/chevre/service/task.js +9 -114
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.d.ts +11 -0
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +105 -0
- package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +17 -0
- package/lib/chevre/service/taskHandler/onOperationFailed.js +70 -0
- package/lib/chevre/service/taskHandler.d.ts +26 -0
- package/lib/chevre/service/taskHandler.js +97 -0
- package/lib/chevre/service/validation/validateEvent.d.ts +2 -2
- package/lib/chevre/service/validation/validateEvent.js +16 -10
- package/lib/chevre/service.d.ts +0 -4
- package/lib/chevre/service.js +10 -14
- package/lib/chevre/settings/aggregation.d.ts +6 -1
- package/lib/chevre/settings/aggregation.js +2 -1
- package/package.json +6 -4
- package/example/src/chevre/adminAuth/adminIdentity.ts +0 -38
- package/example/src/chevre/executeOneTask.ts +0 -41
- package/example/src/chevre/executeTaskIfExists.ts +0 -80
- package/example/src/chevre/findExecutableTask.ts +0 -50
- package/example/src/chevre/findSetting.ts +0 -79
- package/example/src/chevre/searchPermissions.ts +0 -46
- package/example/src/chevre/searchProductOffers.ts +0 -29
- package/example/src/chevre/stockHolder/checkIfConflicted.ts +0 -76
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +0 -186
- package/example/src/chevre/stockHolder/migratePendingReservations.ts +0 -96
- package/example/src/chevre/stockHolder/playAroundStockHolder.ts +0 -256
- package/example/src/chevre/upsertProductsByProductId.ts +0 -100
- package/lib/chevre/adminAuth.d.ts +0 -2
- package/lib/chevre/adminAuth.js +0 -6
package/lib/chevre/repo/role.js
CHANGED
|
@@ -77,39 +77,42 @@ class RoleRepo {
|
|
|
77
77
|
.exec();
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
|
|
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
|
-
|
|
83
|
-
{
|
|
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(
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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(
|
|
26
|
-
|
|
27
|
-
// this.
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 =
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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 =
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
fields
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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 =
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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 (
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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 (
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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 (
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
//
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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';
|