@chevre/domain 22.11.0-alpha.9 → 22.12.0-alpha.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 +25 -11
- package/example/src/chevre/aggregation/aggregateOrderOfCustomerGlobally.ts +34 -0
- 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/factory/event.d.ts +1 -1
- package/lib/chevre/index.d.ts +0 -2
- package/lib/chevre/index.js +0 -10
- package/lib/chevre/repo/event.js +1 -1
- package/lib/chevre/repo/member.d.ts +22 -4
- package/lib/chevre/repo/member.js +81 -27
- package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +9 -0
- package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
- 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 +23 -2
- package/lib/chevre/repo/order.js +70 -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/aggregation/event/aggregateScreeningEvent.js +7 -4
- 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/assetTransaction/reserve/start.js +5 -1
- 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
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment-timezone';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
import * as redis from 'redis';
|
|
5
|
-
import { ILockKey } from '../../../../lib/chevre/repo/stockHolderAbstract';
|
|
6
|
-
import { chevre } from '../../../../lib/index';
|
|
7
|
-
|
|
8
|
-
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
9
|
-
socket: {
|
|
10
|
-
port: Number(<string>process.env.REDIS_PORT),
|
|
11
|
-
host: <string>process.env.REDIS_HOST
|
|
12
|
-
},
|
|
13
|
-
password: <string>process.env.REDIS_KEY
|
|
14
|
-
})
|
|
15
|
-
.on('error', (err) => {
|
|
16
|
-
// eslint-disable-next-line no-console
|
|
17
|
-
console.error('createDefaultRedisClient: client onError:', err);
|
|
18
|
-
// reject(err);
|
|
19
|
-
});
|
|
20
|
-
client.connect();
|
|
21
|
-
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
22
|
-
|
|
23
|
-
const EVENT_ID = 'cm8dwc74c';
|
|
24
|
-
|
|
25
|
-
async function main() {
|
|
26
|
-
// 万が一に備えて、保留予約をredis->mongo移行するスクリプト
|
|
27
|
-
const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
|
|
28
|
-
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
29
|
-
// const pendingReservationRepo = await chevre.repository.PendingReservation.createInstance(mongoose.connection);
|
|
30
|
-
const stockHolderRepo = await chevre.repository.StockHolder.createInstance(client, mongoose.connection);
|
|
31
|
-
|
|
32
|
-
const event = await eventRepo.projectEventFieldsById(
|
|
33
|
-
{ id: EVENT_ID },
|
|
34
|
-
['startDate', 'organizer', 'project', 'offers']
|
|
35
|
-
);
|
|
36
|
-
const hasTicketedSeat = event.offers.itemOffered.serviceOutput?.reservedTicket?.ticketedSeat?.typeOf === chevre.factory.placeType.Seat;
|
|
37
|
-
const { expireTime, hash } = await stockHolderRepo.migrate2mongoJustInCase({
|
|
38
|
-
eventId: EVENT_ID,
|
|
39
|
-
startDate: event.startDate
|
|
40
|
-
// project: { id: event.project.id },
|
|
41
|
-
// provider: { id: event.organizer.id }
|
|
42
|
-
});
|
|
43
|
-
console.log(expireTime, hash);
|
|
44
|
-
|
|
45
|
-
const lockKeys: ILockKey[] = [];
|
|
46
|
-
const reservationNumbers: string[] = [...new Set(Object.values(hash))];
|
|
47
|
-
const expires: Date = moment.unix(expireTime)
|
|
48
|
-
.toDate();
|
|
49
|
-
console.log('reservationNumbers:', reservationNumbers);
|
|
50
|
-
console.log('expires:', expires);
|
|
51
|
-
|
|
52
|
-
// 予約番号ごとにlockKeyを作成する
|
|
53
|
-
for (const reservationNumber of reservationNumbers) {
|
|
54
|
-
const reserveTransaction = (await assetTransactionRepo.search<chevre.factory.assetTransactionType.Reserve>(
|
|
55
|
-
{
|
|
56
|
-
limit: 1,
|
|
57
|
-
page: 1,
|
|
58
|
-
transactionNumber: { $eq: reservationNumber },
|
|
59
|
-
typeOf: chevre.factory.assetTransactionType.Reserve,
|
|
60
|
-
status: { $in: [chevre.factory.transactionStatusType.Confirmed] }
|
|
61
|
-
},
|
|
62
|
-
['object', 'startDate']
|
|
63
|
-
)).shift();
|
|
64
|
-
if (reserveTransaction === undefined) {
|
|
65
|
-
throw new Error(`reserveTransaction not found ${reservationNumber}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const fields: string[] = Object.keys(hash)
|
|
69
|
-
.filter((field) => hash[field] === reservationNumber);
|
|
70
|
-
const lockKey: ILockKey = {
|
|
71
|
-
project: { id: event.project.id },
|
|
72
|
-
provider: { id: event.organizer.id },
|
|
73
|
-
eventId: EVENT_ID,
|
|
74
|
-
startDate: event.startDate,
|
|
75
|
-
hasTicketedSeat,
|
|
76
|
-
offers: fields.map((field) => {
|
|
77
|
-
const splitedField = field.split(':');
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
seatSection: splitedField[0],
|
|
81
|
-
seatNumber: splitedField[1]
|
|
82
|
-
};
|
|
83
|
-
}),
|
|
84
|
-
expires,
|
|
85
|
-
holder: reservationNumber,
|
|
86
|
-
bookingTime: reserveTransaction.startDate
|
|
87
|
-
};
|
|
88
|
-
console.log('lockKey:', lockKey);
|
|
89
|
-
lockKeys.push(lockKey);
|
|
90
|
-
// await pendingReservationRepo.lock(lockKey);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
main()
|
|
95
|
-
.then(console.log)
|
|
96
|
-
.catch(console.error);
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment-timezone';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
import * as redis from 'redis';
|
|
5
|
-
import { chevre } from '../../../../lib/index';
|
|
6
|
-
|
|
7
|
-
const today = moment()
|
|
8
|
-
.tz('Asia/Tokyo')
|
|
9
|
-
.format('YYYYMMDD');
|
|
10
|
-
const project = { id: String(process.env.PROJECT_ID) };
|
|
11
|
-
const providerId = 'sampleProviderId';
|
|
12
|
-
const eventId = `sampleEventId${today}:03`;
|
|
13
|
-
const eventStartDate = new Date('2025-05-01T00:00:00Z');
|
|
14
|
-
const expires = moment(eventStartDate)
|
|
15
|
-
.add(1, 'week')
|
|
16
|
-
.toDate();
|
|
17
|
-
const seatSection = 'SampleSectionNameXXXXXXXXXXXXXXXXXXX';
|
|
18
|
-
// tslint:disable-next-line:no-magic-numbers prefer-array-literal
|
|
19
|
-
const allSeatNumbers = [...Array(10000)].map((__, seatKey) => `SampleSeatNumber-${seatKey}`);
|
|
20
|
-
const OPERATION_INTERVAL = 2000;
|
|
21
|
-
// const MAXIMUM_CAPACITY = 10002;
|
|
22
|
-
|
|
23
|
-
mongoose.Model.on('index', (...args) => {
|
|
24
|
-
console.error('******** index event emitted. ********\n', args);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
async function sleep(waitTime: number): Promise<void> {
|
|
28
|
-
return new Promise<void>((resolve) => {
|
|
29
|
-
setTimeout(
|
|
30
|
-
() => {
|
|
31
|
-
resolve();
|
|
32
|
-
},
|
|
33
|
-
waitTime
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
39
|
-
socket: {
|
|
40
|
-
port: Number(<string>process.env.REDIS_PORT),
|
|
41
|
-
host: <string>process.env.REDIS_HOST
|
|
42
|
-
},
|
|
43
|
-
password: <string>process.env.REDIS_KEY
|
|
44
|
-
})
|
|
45
|
-
.on('error', (err) => {
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
|
-
console.error('createDefaultRedisClient: client onError:', err);
|
|
48
|
-
// reject(err);
|
|
49
|
-
});
|
|
50
|
-
client.connect();
|
|
51
|
-
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
52
|
-
|
|
53
|
-
const formatter = new Intl.NumberFormat('ja-JP');
|
|
54
|
-
// => "1,000"
|
|
55
|
-
|
|
56
|
-
// tslint:disable-next-line:max-func-body-length
|
|
57
|
-
async function lockSeatsForcibly(params: {
|
|
58
|
-
maximumCapacity?: number;
|
|
59
|
-
}) {
|
|
60
|
-
const { maximumCapacity } = params;
|
|
61
|
-
let startTime: [number, number] = process.hrtime();
|
|
62
|
-
let diff: [number, number] = process.hrtime(startTime);
|
|
63
|
-
|
|
64
|
-
const stockHolderRepo = await chevre.repository.StockHolder.createInstance(
|
|
65
|
-
client,
|
|
66
|
-
mongoose.connection
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
startTime = process.hrtime();
|
|
70
|
-
console.log('counting unavailableOffers...');
|
|
71
|
-
let countUnavailableOffersResult = await stockHolderRepo.countUnavailableOffers({
|
|
72
|
-
project: { id: project.id },
|
|
73
|
-
event: {
|
|
74
|
-
id: eventId,
|
|
75
|
-
startDate: eventStartDate,
|
|
76
|
-
hasTicketedSeat: true
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
console.log('countUnavailableOffersResult:', countUnavailableOffersResult);
|
|
80
|
-
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
81
|
-
|
|
82
|
-
await sleep(OPERATION_INTERVAL);
|
|
83
|
-
startTime = process.hrtime();
|
|
84
|
-
console.log('counting searching holders...');
|
|
85
|
-
const searchHoldersResult = await stockHolderRepo.searchHolders({
|
|
86
|
-
project: { id: project.id },
|
|
87
|
-
eventId,
|
|
88
|
-
startDate: eventStartDate,
|
|
89
|
-
hasTicketedSeat: true,
|
|
90
|
-
offers: [
|
|
91
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
92
|
-
...allSeatNumbers.slice(0, 100)
|
|
93
|
-
.map((seatNumber) => ({ seatSection, seatNumber }))
|
|
94
|
-
]
|
|
95
|
-
});
|
|
96
|
-
diff = process.hrtime(startTime);
|
|
97
|
-
console.log('searchHoldersResult.length:', searchHoldersResult.length);
|
|
98
|
-
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
99
|
-
|
|
100
|
-
// select 2 seats
|
|
101
|
-
// tslint:disable-next-line:insecure-random
|
|
102
|
-
const seatNumber1 = allSeatNumbers[Math.floor(allSeatNumbers.length * Math.random())];
|
|
103
|
-
const seatNumber2 = allSeatNumbers.filter((seatNumber) => seatNumber !== seatNumber1)[
|
|
104
|
-
// tslint:disable-next-line:insecure-random
|
|
105
|
-
Math.floor((allSeatNumbers.length - 1) * Math.random())
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
const seatNumbers = [seatNumber1, seatNumber2];
|
|
109
|
-
console.log('seats selected.', seatNumbers);
|
|
110
|
-
|
|
111
|
-
let locked = false;
|
|
112
|
-
while (!locked) {
|
|
113
|
-
await sleep(OPERATION_INTERVAL);
|
|
114
|
-
startTime = process.hrtime();
|
|
115
|
-
const currentHolders: string[] = [];
|
|
116
|
-
for (const seatNumber of seatNumbers) {
|
|
117
|
-
const currentHolder = await stockHolderRepo.getHolder({
|
|
118
|
-
project: { id: project.id },
|
|
119
|
-
eventId,
|
|
120
|
-
startDate: eventStartDate,
|
|
121
|
-
hasTicketedSeat: true,
|
|
122
|
-
offer: { seatSection, seatNumber }
|
|
123
|
-
});
|
|
124
|
-
if (typeof currentHolder === 'string') {
|
|
125
|
-
currentHolders.push(currentHolder);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
diff = process.hrtime(startTime);
|
|
129
|
-
console.log('currentHolders:', currentHolders);
|
|
130
|
-
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
await sleep(OPERATION_INTERVAL);
|
|
134
|
-
const newHolder = Date.now()
|
|
135
|
-
.toString();
|
|
136
|
-
const bookingTime = new Date();
|
|
137
|
-
startTime = process.hrtime();
|
|
138
|
-
console.log('locking...', newHolder, seatSection, seatNumbers);
|
|
139
|
-
if (typeof maximumCapacity === 'number') {
|
|
140
|
-
try {
|
|
141
|
-
await stockHolderRepo.lockIfNotLimitExceeded(
|
|
142
|
-
{
|
|
143
|
-
project: { id: project.id },
|
|
144
|
-
provider: { id: providerId },
|
|
145
|
-
eventId,
|
|
146
|
-
startDate: eventStartDate,
|
|
147
|
-
hasTicketedSeat: true,
|
|
148
|
-
offers: seatNumbers.map((seatNumber) => ({ seatSection, seatNumber })),
|
|
149
|
-
expires,
|
|
150
|
-
holder: newHolder,
|
|
151
|
-
bookingTime
|
|
152
|
-
},
|
|
153
|
-
maximumCapacity
|
|
154
|
-
);
|
|
155
|
-
} catch (error) {
|
|
156
|
-
if (error.message === 'maximumAttendeeCapacity exceeded') {
|
|
157
|
-
// ok
|
|
158
|
-
} else {
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
await stockHolderRepo.lock({
|
|
164
|
-
project: { id: project.id },
|
|
165
|
-
provider: { id: providerId },
|
|
166
|
-
eventId,
|
|
167
|
-
startDate: eventStartDate,
|
|
168
|
-
hasTicketedSeat: true,
|
|
169
|
-
offers: seatNumbers.map((seatNumber) => ({ seatSection, seatNumber })),
|
|
170
|
-
expires,
|
|
171
|
-
holder: newHolder,
|
|
172
|
-
bookingTime
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
diff = process.hrtime(startTime);
|
|
176
|
-
console.log('locked.', newHolder);
|
|
177
|
-
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
178
|
-
locked = true;
|
|
179
|
-
} catch (error) {
|
|
180
|
-
if (error instanceof chevre.factory.errors.AlreadyInUse) {
|
|
181
|
-
console.log('lockResult:', error.name, error.message);
|
|
182
|
-
} else {
|
|
183
|
-
console.error(error);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
await sleep(OPERATION_INTERVAL);
|
|
188
|
-
for (const currentHolder of currentHolders) {
|
|
189
|
-
for (const seatNumber of seatNumbers) {
|
|
190
|
-
startTime = process.hrtime();
|
|
191
|
-
console.log('unlocking...', currentHolder, seatSection, seatNumber);
|
|
192
|
-
const unlockResult = await stockHolderRepo.unlock({
|
|
193
|
-
project: { id: project.id },
|
|
194
|
-
eventId,
|
|
195
|
-
startDate: eventStartDate,
|
|
196
|
-
hasTicketedSeat: true,
|
|
197
|
-
offer: { seatSection, seatNumber },
|
|
198
|
-
holder: currentHolder
|
|
199
|
-
});
|
|
200
|
-
diff = process.hrtime(startTime);
|
|
201
|
-
console.log('unlockResult:', unlockResult);
|
|
202
|
-
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
await sleep(OPERATION_INTERVAL);
|
|
208
|
-
countUnavailableOffersResult = await stockHolderRepo.countUnavailableOffers({
|
|
209
|
-
project: { id: project.id },
|
|
210
|
-
event: {
|
|
211
|
-
id: eventId,
|
|
212
|
-
startDate: eventStartDate,
|
|
213
|
-
hasTicketedSeat: true
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
console.log('countUnavailableOffersResult:', countUnavailableOffersResult);
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
async function main() {
|
|
221
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
222
|
-
const numLock = (typeof process.argv[2] === 'string') ? Number(process.argv[2]) : 1;
|
|
223
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
224
|
-
const maximumCapacity = (typeof process.argv[3] === 'string') ? Number(process.argv[3]) : undefined;
|
|
225
|
-
|
|
226
|
-
const LOCK_INTERVAL = 300;
|
|
227
|
-
let i = 0;
|
|
228
|
-
let lockedCount = 0;
|
|
229
|
-
let timeout: NodeJS.Timeout;
|
|
230
|
-
const processStartDate = new Date();
|
|
231
|
-
function onSeatsLocked() {
|
|
232
|
-
lockedCount += 1;
|
|
233
|
-
console.log(lockedCount, 'lockSeatsForcibly executed!');
|
|
234
|
-
console.log('processed.', processStartDate, '~', new Date());
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
timeout = setInterval(
|
|
238
|
-
() => {
|
|
239
|
-
if (i >= numLock) {
|
|
240
|
-
clearInterval(timeout);
|
|
241
|
-
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
i += 1;
|
|
246
|
-
lockSeatsForcibly({ maximumCapacity })
|
|
247
|
-
.then(onSeatsLocked)
|
|
248
|
-
.catch(console.error);
|
|
249
|
-
},
|
|
250
|
-
LOCK_INTERVAL
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
main()
|
|
255
|
-
.then()
|
|
256
|
-
.catch(console.error);
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
7
|
-
|
|
8
|
-
// tslint:disable-next-line:max-func-body-length
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
-
|
|
12
|
-
const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
const result = await productRepo.upsertManyByProductId(
|
|
15
|
-
[
|
|
16
|
-
{
|
|
17
|
-
$set: {
|
|
18
|
-
project: {
|
|
19
|
-
typeOf: chevre.factory.organizationType.Project,
|
|
20
|
-
id: PROJECT_ID
|
|
21
|
-
},
|
|
22
|
-
typeOf: chevre.factory.product.ProductType.EventService,
|
|
23
|
-
productID: '2023122601EventService',
|
|
24
|
-
name: {
|
|
25
|
-
en: 'xxx',
|
|
26
|
-
ja: 'xxx'
|
|
27
|
-
},
|
|
28
|
-
// hasOfferCatalog: {
|
|
29
|
-
// id: 'blpc770py',
|
|
30
|
-
// typeOf: 'OfferCatalog'
|
|
31
|
-
// },
|
|
32
|
-
// serviceType: {
|
|
33
|
-
// codeValue: '0001',
|
|
34
|
-
// typeOf: 'CategoryCode',
|
|
35
|
-
// inCodeSet: {
|
|
36
|
-
// identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType,
|
|
37
|
-
// typeOf: 'CategoryCodeSet'
|
|
38
|
-
// }
|
|
39
|
-
// },
|
|
40
|
-
availableChannel: {
|
|
41
|
-
typeOf: 'ServiceChannel',
|
|
42
|
-
credentials: {}
|
|
43
|
-
},
|
|
44
|
-
description: {
|
|
45
|
-
en: 'xxx',
|
|
46
|
-
ja: 'xxx'
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
$unset: {
|
|
50
|
-
hasOfferCatalog: 1,
|
|
51
|
-
serviceType: 1
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
$set: {
|
|
56
|
-
project: {
|
|
57
|
-
typeOf: chevre.factory.organizationType.Project,
|
|
58
|
-
id: PROJECT_ID
|
|
59
|
-
},
|
|
60
|
-
typeOf: chevre.factory.product.ProductType.EventService,
|
|
61
|
-
productID: '2023122602EventService',
|
|
62
|
-
name: {
|
|
63
|
-
en: 'xxx',
|
|
64
|
-
ja: 'xxx'
|
|
65
|
-
},
|
|
66
|
-
hasOfferCatalog: {
|
|
67
|
-
// id: 'blpc770py',
|
|
68
|
-
typeOf: 'OfferCatalog',
|
|
69
|
-
itemListElement: [{ id: 'blpc770py' }]
|
|
70
|
-
},
|
|
71
|
-
// serviceType: {
|
|
72
|
-
// codeValue: '0001',
|
|
73
|
-
// typeOf: 'CategoryCode',
|
|
74
|
-
// inCodeSet: {
|
|
75
|
-
// identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType,
|
|
76
|
-
// typeOf: 'CategoryCodeSet'
|
|
77
|
-
// }
|
|
78
|
-
// },
|
|
79
|
-
availableChannel: {
|
|
80
|
-
typeOf: 'ServiceChannel',
|
|
81
|
-
credentials: {}
|
|
82
|
-
},
|
|
83
|
-
description: {
|
|
84
|
-
en: 'xxx',
|
|
85
|
-
ja: 'xxx'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
$unset: {
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
// { replace: true }
|
|
93
|
-
);
|
|
94
|
-
// tslint:disable-next-line:no-null-keyword
|
|
95
|
-
console.log(result);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
main()
|
|
99
|
-
.then(console.log)
|
|
100
|
-
.catch(console.error);
|
package/lib/chevre/adminAuth.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadChevreAuth = exports.auth = void 0;
|
|
4
|
-
const sdk_1 = require("@cinerino/sdk");
|
|
5
|
-
Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return sdk_1.auth; } });
|
|
6
|
-
Object.defineProperty(exports, "loadChevreAuth", { enumerable: true, get: function () { return sdk_1.loadChevreAuth; } });
|