@chevre/domain 22.9.0-alpha.97 → 22.9.0-alpha.99
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/investigateEvents.ts +86 -0
- package/example/src/chevre/investigateTransaction.ts +31 -19
- package/example/src/chevre/playAroundStockHolder.ts +269 -0
- package/example/src/chevre/publishConfimationNumber.ts +27 -0
- package/example/src/moment.ts +19 -18
- package/example/src/mongoConnectionList.ts +81 -0
- package/example/src/redisClientList.ts +12 -1
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +8 -2
- package/lib/chevre/repo/mongoose/schemas/stockHolder.d.ts +28 -0
- package/lib/chevre/repo/mongoose/schemas/stockHolder.js +100 -0
- package/lib/chevre/repo/mongoose/schemas/stockHolderAsReservationPackage.d.ts +31 -0
- package/lib/chevre/repo/mongoose/schemas/stockHolderAsReservationPackage.js +102 -0
- package/lib/chevre/repo/stockHolder.d.ts +10 -84
- package/lib/chevre/repo/stockHolder.js +64 -22
- package/lib/chevre/repo/stockHolderAbstract.d.ts +74 -0
- package/lib/chevre/repo/stockHolderAbstract.js +9 -0
- package/lib/chevre/repo/stockHolderAsAggregateReservation.d.ts +40 -0
- package/lib/chevre/repo/stockHolderAsAggregateReservation.js +290 -0
- package/lib/chevre/repo/stockHolderAsReservationPackage.d.ts +35 -0
- package/lib/chevre/repo/stockHolderAsReservationPackage.js +200 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +14 -3
- package/lib/chevre/service/assetTransaction/reserve/start.js +8 -1
- package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +0 -2
- package/package.json +1 -1
- package/example/src/chevre/investigateSellers.ts +0 -53
- package/example/src/chevre/playAroundAdvanceBookingRequirement.ts +0 -65
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const cursor = eventRepo.getCursor(
|
|
14
|
+
{
|
|
15
|
+
'project.id': {
|
|
16
|
+
$nin: [
|
|
17
|
+
'sskts-test',
|
|
18
|
+
'sskts-production'
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
startDate: { $gte: new Date('2025-04-10T00:00:00Z') }
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
offers: 1,
|
|
25
|
+
project: 1,
|
|
26
|
+
typeOf: 1,
|
|
27
|
+
startDate: 1,
|
|
28
|
+
location: 1,
|
|
29
|
+
aggregateReservation: 1
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
console.log('docs found');
|
|
33
|
+
|
|
34
|
+
let i = 0;
|
|
35
|
+
let hasNoSeatsCount = 0;
|
|
36
|
+
let tooManyReservationCount = 0;
|
|
37
|
+
let maxReservationCount = 0;
|
|
38
|
+
const targetIds: string[] = [];
|
|
39
|
+
const projectIds: string[] = [];
|
|
40
|
+
await cursor.eachAsync(async (doc) => {
|
|
41
|
+
i += 1;
|
|
42
|
+
const event: Pick<
|
|
43
|
+
chevre.factory.event.screeningEvent.IEvent, 'id' | 'offers' | 'startDate' | 'typeOf' | 'location' | 'project' | 'aggregateReservation'
|
|
44
|
+
> = doc.toObject();
|
|
45
|
+
|
|
46
|
+
// const hasMax = typeof event.location.maximumAttendeeCapacity === 'number';
|
|
47
|
+
const hasSeats = event.offers.itemOffered.serviceOutput?.reservedTicket?.ticketedSeat?.typeOf === chevre.factory.placeType.Seat;
|
|
48
|
+
if (!hasSeats) {
|
|
49
|
+
hasNoSeatsCount += 1;
|
|
50
|
+
targetIds.push(event.id);
|
|
51
|
+
projectIds.push(event.project.id);
|
|
52
|
+
console.log(
|
|
53
|
+
'hasNoSeatsCount:', hasNoSeatsCount,
|
|
54
|
+
event.id, event.project.id, event.startDate, i);
|
|
55
|
+
} else {
|
|
56
|
+
console.log(
|
|
57
|
+
'no', hasNoSeatsCount,
|
|
58
|
+
event.id, event.project.id, event.startDate, i);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const reservationCount = event.aggregateReservation?.reservationCount;
|
|
62
|
+
if (typeof reservationCount === 'number') {
|
|
63
|
+
maxReservationCount = Math.max(reservationCount, maxReservationCount);
|
|
64
|
+
}
|
|
65
|
+
const tooManyReservation = typeof event.aggregateReservation?.reservationCount === 'number'
|
|
66
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
67
|
+
&& event.aggregateReservation?.reservationCount > 2000;
|
|
68
|
+
if (tooManyReservation) {
|
|
69
|
+
tooManyReservationCount += 1;
|
|
70
|
+
console.log(
|
|
71
|
+
'tooManyReservationCount:', tooManyReservationCount,
|
|
72
|
+
event.id, event.project.id, event.startDate, i);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(targetIds);
|
|
78
|
+
console.log(i, 'docs checked');
|
|
79
|
+
console.log(hasNoSeatsCount, 'docs hasNoSeatsCount');
|
|
80
|
+
console.log('projectIds:', [...new Set(projectIds)]);
|
|
81
|
+
console.log('maxReservationCount:', maxReservationCount);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
main()
|
|
85
|
+
.then()
|
|
86
|
+
.catch(console.error);
|
|
@@ -4,7 +4,7 @@ import * as mongoose from 'mongoose';
|
|
|
4
4
|
|
|
5
5
|
import { chevre } from '../../../lib/index';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
8
8
|
|
|
9
9
|
async function main() {
|
|
10
10
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
@@ -13,40 +13,52 @@ async function main() {
|
|
|
13
13
|
|
|
14
14
|
const cursor = transactionRepo.getCursor(
|
|
15
15
|
{
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
'project.id': { $eq: project.id },
|
|
17
|
+
typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
|
|
18
|
+
status: {
|
|
19
|
+
$in: [
|
|
20
|
+
chevre.factory.transactionStatusType.Canceled,
|
|
21
|
+
chevre.factory.transactionStatusType.Expired
|
|
22
|
+
]
|
|
23
|
+
},
|
|
18
24
|
startDate: {
|
|
19
|
-
$gte: moment()
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
$gte: moment('2025-04-10T15:00:00Z')
|
|
26
|
+
.toDate(),
|
|
27
|
+
$lte: moment('2025-04-11T01:00:00Z')
|
|
22
28
|
.toDate()
|
|
23
29
|
}
|
|
24
30
|
},
|
|
25
31
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
project: 1,
|
|
33
|
+
typeOf: 1,
|
|
34
|
+
startDate: 1,
|
|
35
|
+
object: 1,
|
|
36
|
+
result: 1,
|
|
37
|
+
agent: 1
|
|
31
38
|
}
|
|
32
39
|
);
|
|
33
40
|
console.log('transactions found');
|
|
34
41
|
|
|
35
42
|
let i = 0;
|
|
43
|
+
let transactionByMemberCount = 0;
|
|
36
44
|
await cursor.eachAsync(async (doc) => {
|
|
37
45
|
i += 1;
|
|
38
|
-
const transaction:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const transaction: Pick<
|
|
47
|
+
chevre.factory.transaction.ITransaction<chevre.factory.transactionType.PlaceOrder>,
|
|
48
|
+
'project' | 'object' | 'startDate' | 'result' | 'typeOf' | 'agent'
|
|
49
|
+
> = doc.toObject();
|
|
50
|
+
|
|
51
|
+
if (transaction.agent.id === '28v3ml7b8f74h2dqdvni7ntf25') {
|
|
52
|
+
const publishedPaymentMethodId = transaction.object.paymentMethods?.paymentMethodId;
|
|
53
|
+
if (typeof publishedPaymentMethodId === 'string') {
|
|
54
|
+
console.log(transaction.project.id, transaction.agent.id, publishedPaymentMethodId, transaction.startDate, i);
|
|
55
|
+
transactionByMemberCount += 1;
|
|
56
|
+
}
|
|
46
57
|
}
|
|
47
58
|
});
|
|
48
59
|
|
|
49
60
|
console.log(i, 'transactions checked');
|
|
61
|
+
console.log(transactionByMemberCount, 'transactionByMember found');
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
main()
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
import * as redis from 'redis';
|
|
4
|
+
// import { StockHolderAsAggregateReservationRepo } from '../../../lib/chevre/repo/stockHolderAsAggregateReservation';
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
const eventId = 'sampleEventId';
|
|
9
|
+
const eventStartDate = new Date('2025-05-01T00:00:00Z');
|
|
10
|
+
const seatSection = 'SampleSectionNameXXXXXXXXXXXXXXXXXXX';
|
|
11
|
+
// tslint:disable-next-line:no-magic-numbers prefer-array-literal
|
|
12
|
+
const allSeatNumbers = [...Array(10000)].map((__, seatKey) => `SampleSeatNumber-${seatKey}`);
|
|
13
|
+
const OPERATION_INTERVAL = 2000;
|
|
14
|
+
|
|
15
|
+
mongoose.Model.on('index', (...args) => {
|
|
16
|
+
console.error('******** index event emitted. ********\n', args);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
async function sleep(waitTime: number): Promise<void> {
|
|
20
|
+
return new Promise<void>((resolve) => {
|
|
21
|
+
setTimeout(
|
|
22
|
+
() => {
|
|
23
|
+
resolve();
|
|
24
|
+
},
|
|
25
|
+
waitTime
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
31
|
+
socket: {
|
|
32
|
+
port: Number(<string>process.env.REDIS_PORT),
|
|
33
|
+
host: <string>process.env.REDIS_HOST
|
|
34
|
+
},
|
|
35
|
+
password: <string>process.env.REDIS_KEY
|
|
36
|
+
})
|
|
37
|
+
.on('error', (err) => {
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.error('createDefaultRedisClient: client onError:', err);
|
|
40
|
+
// reject(err);
|
|
41
|
+
});
|
|
42
|
+
client.connect();
|
|
43
|
+
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
44
|
+
|
|
45
|
+
// tslint:disable-next-line:max-func-body-length
|
|
46
|
+
async function lockSeatsForcibly() {
|
|
47
|
+
const stockHolderRepo = await chevre.repository.StockHolder.createInstance(client, mongoose.connection);
|
|
48
|
+
// const stockHolderAsAggregateReservationRepo = new StockHolderAsAggregateReservationRepo(mongoose.connection);
|
|
49
|
+
|
|
50
|
+
// const size = await stockHolderAsAggregateReservationRepo.getSize({
|
|
51
|
+
// project: {
|
|
52
|
+
// id: project.id
|
|
53
|
+
// },
|
|
54
|
+
// eventId,
|
|
55
|
+
// startDate: eventStartDate,
|
|
56
|
+
// hasTicketedSeat: true
|
|
57
|
+
// });
|
|
58
|
+
// console.log('size:', size);
|
|
59
|
+
|
|
60
|
+
// const newHolder = Date.now()
|
|
61
|
+
// .toString();
|
|
62
|
+
// const lockResult = await stockHolderAsAggregateReservationRepo.lock({
|
|
63
|
+
// project: {
|
|
64
|
+
// id: project.id
|
|
65
|
+
// },
|
|
66
|
+
// eventId,
|
|
67
|
+
// startDate: eventStartDate,
|
|
68
|
+
// hasTicketedSeat: true,
|
|
69
|
+
// // tslint:disable-next-line:prefer-array-literal
|
|
70
|
+
// offers: [...Array(10000)].map((__, seatKey) => ({ seatSection, seatNumber: `A-${seatKey}` })),
|
|
71
|
+
// expires: new Date(),
|
|
72
|
+
// holder: newHolder
|
|
73
|
+
// });
|
|
74
|
+
// console.log('lockResult:', lockResult);
|
|
75
|
+
|
|
76
|
+
// return;
|
|
77
|
+
|
|
78
|
+
// const cursor = mongoStockHolderRepo.getCursor(
|
|
79
|
+
// {
|
|
80
|
+
// 'reservationFor.id': { $eq: eventId }
|
|
81
|
+
// },
|
|
82
|
+
// {
|
|
83
|
+
// _id: 1,
|
|
84
|
+
// numSeats: 1,
|
|
85
|
+
// subReservation: 1
|
|
86
|
+
// }
|
|
87
|
+
// );
|
|
88
|
+
// console.log('docs found');
|
|
89
|
+
|
|
90
|
+
// await cursor.eachAsync(async (doc) => {
|
|
91
|
+
// const stockHolder = doc.toObject();
|
|
92
|
+
// if (stockHolder.numSeats !== stockHolder.subReservation.length) {
|
|
93
|
+
// throw new Error(`${stockHolder._id} invalid`);
|
|
94
|
+
// }
|
|
95
|
+
|
|
96
|
+
// });
|
|
97
|
+
// return;
|
|
98
|
+
|
|
99
|
+
console.log('counting unavailableOffers...');
|
|
100
|
+
const countUnavailableOffersMustBeZero = await stockHolderRepo.countUnavailableOffers({
|
|
101
|
+
event: {
|
|
102
|
+
id: 'xxxxxxxxx',
|
|
103
|
+
startDate: eventStartDate,
|
|
104
|
+
hasTicketedSeat: true
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
console.log('countUnavailableOffersMustBeZero:', countUnavailableOffersMustBeZero);
|
|
108
|
+
|
|
109
|
+
console.log('counting unavailableOffers...');
|
|
110
|
+
let countUnavailableOffersResult = await stockHolderRepo.countUnavailableOffers({
|
|
111
|
+
event: {
|
|
112
|
+
id: eventId,
|
|
113
|
+
startDate: eventStartDate,
|
|
114
|
+
hasTicketedSeat: true
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
console.log('countUnavailableOffersResult:', countUnavailableOffersResult);
|
|
118
|
+
|
|
119
|
+
await sleep(OPERATION_INTERVAL);
|
|
120
|
+
console.log('counting searching holders...');
|
|
121
|
+
const searchHoldersResult = await stockHolderRepo.searchHolders({
|
|
122
|
+
project: {
|
|
123
|
+
id: project.id
|
|
124
|
+
},
|
|
125
|
+
eventId,
|
|
126
|
+
startDate: eventStartDate,
|
|
127
|
+
hasTicketedSeat: true,
|
|
128
|
+
offers: [
|
|
129
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
130
|
+
...allSeatNumbers.slice(0, 100)
|
|
131
|
+
.map((seatNumber) => ({ seatSection, seatNumber }))
|
|
132
|
+
// { seatNumber: 'invalid', seatSection: 'invalid' }
|
|
133
|
+
]
|
|
134
|
+
});
|
|
135
|
+
// console.log('searchHoldersResult:', searchHoldersResult);
|
|
136
|
+
console.log('searchHoldersResult.length:', searchHoldersResult.length);
|
|
137
|
+
|
|
138
|
+
// select 2 seats
|
|
139
|
+
// tslint:disable-next-line:insecure-random
|
|
140
|
+
const seatNumber1 = allSeatNumbers[Math.floor(allSeatNumbers.length * Math.random())];
|
|
141
|
+
const seatNumber2 = allSeatNumbers.filter((seatNumber) => seatNumber !== seatNumber1)[
|
|
142
|
+
// tslint:disable-next-line:insecure-random
|
|
143
|
+
Math.floor((allSeatNumbers.length - 1) * Math.random())
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
const seatNumbers = [seatNumber1, seatNumber2];
|
|
147
|
+
console.log('seats selected.', seatNumbers);
|
|
148
|
+
|
|
149
|
+
let locked = false;
|
|
150
|
+
while (!locked) {
|
|
151
|
+
await sleep(OPERATION_INTERVAL);
|
|
152
|
+
const currentHolders: string[] = [];
|
|
153
|
+
for (const seatNumber of seatNumbers) {
|
|
154
|
+
const currentHolder = await stockHolderRepo.getHolder({
|
|
155
|
+
project: {
|
|
156
|
+
id: project.id
|
|
157
|
+
},
|
|
158
|
+
eventId,
|
|
159
|
+
startDate: eventStartDate,
|
|
160
|
+
hasTicketedSeat: true,
|
|
161
|
+
offer: { seatSection, seatNumber }
|
|
162
|
+
});
|
|
163
|
+
if (typeof currentHolder === 'string') {
|
|
164
|
+
currentHolders.push(currentHolder);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
console.log('currentHolders:', currentHolders);
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
await sleep(OPERATION_INTERVAL);
|
|
171
|
+
const newHolder = Date.now()
|
|
172
|
+
.toString();
|
|
173
|
+
console.log('locking...', newHolder, seatSection, seatNumbers);
|
|
174
|
+
const lockResult = await stockHolderRepo.lock({
|
|
175
|
+
project: {
|
|
176
|
+
id: project.id
|
|
177
|
+
},
|
|
178
|
+
eventId,
|
|
179
|
+
startDate: eventStartDate,
|
|
180
|
+
hasTicketedSeat: true,
|
|
181
|
+
offers: seatNumbers.map((seatNumber) => ({ seatSection, seatNumber })),
|
|
182
|
+
expires: new Date(),
|
|
183
|
+
holder: newHolder
|
|
184
|
+
});
|
|
185
|
+
// const lockResult = await stockHolderRepo.lockIfNotLimitExceeded(
|
|
186
|
+
// {
|
|
187
|
+
// project: {
|
|
188
|
+
// id: project.id
|
|
189
|
+
// },
|
|
190
|
+
// eventId,
|
|
191
|
+
// startDate: eventStartDate,
|
|
192
|
+
// hasTicketedSeat: true,
|
|
193
|
+
// offers: seatNumbers.map((seatNumber) => ({ seatSection, seatNumber })),
|
|
194
|
+
// expires: new Date(),
|
|
195
|
+
// holder: newHolder
|
|
196
|
+
// },
|
|
197
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
198
|
+
// 8
|
|
199
|
+
// );
|
|
200
|
+
console.log('lockResult:', lockResult, newHolder);
|
|
201
|
+
locked = true;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error instanceof chevre.factory.errors.AlreadyInUse) {
|
|
204
|
+
console.log('lockResult:', error.name, error.message);
|
|
205
|
+
} else {
|
|
206
|
+
console.error(error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const holder = currentHolders[0];
|
|
211
|
+
if (typeof holder === 'string') {
|
|
212
|
+
for (const seatNumber of seatNumbers) {
|
|
213
|
+
await sleep(OPERATION_INTERVAL);
|
|
214
|
+
console.log('unlocking...', holder, seatSection, seatNumber);
|
|
215
|
+
const unlockResult = await stockHolderRepo.unlock({
|
|
216
|
+
project: {
|
|
217
|
+
id: project.id
|
|
218
|
+
},
|
|
219
|
+
eventId,
|
|
220
|
+
startDate: eventStartDate,
|
|
221
|
+
hasTicketedSeat: true,
|
|
222
|
+
offer: { seatSection, seatNumber },
|
|
223
|
+
holder
|
|
224
|
+
});
|
|
225
|
+
console.log('unlockResult:', unlockResult);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
await sleep(OPERATION_INTERVAL);
|
|
231
|
+
countUnavailableOffersResult = await stockHolderRepo.countUnavailableOffers({
|
|
232
|
+
event: {
|
|
233
|
+
id: eventId,
|
|
234
|
+
startDate: eventStartDate,
|
|
235
|
+
hasTicketedSeat: true
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
console.log('countUnavailableOffersResult:', countUnavailableOffersResult);
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const NUM_LOCK = 1;
|
|
243
|
+
// const NUM_LOCK = 1000;
|
|
244
|
+
const LOCK_INTERVAL = 1000;
|
|
245
|
+
let i = 0;
|
|
246
|
+
let lockedCount = 0;
|
|
247
|
+
let timeout: NodeJS.Timeout;
|
|
248
|
+
const processStartDate = new Date();
|
|
249
|
+
function onSeatsLocked() {
|
|
250
|
+
lockedCount += 1;
|
|
251
|
+
console.log(lockedCount, 'lockSeatsForcibly executed!');
|
|
252
|
+
console.log('processed.', processStartDate, '~', new Date());
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
timeout = setInterval(
|
|
256
|
+
() => {
|
|
257
|
+
if (i >= NUM_LOCK) {
|
|
258
|
+
clearInterval(timeout);
|
|
259
|
+
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
i += 1;
|
|
264
|
+
lockSeatsForcibly()
|
|
265
|
+
.then(onSeatsLocked)
|
|
266
|
+
.catch(console.error);
|
|
267
|
+
},
|
|
268
|
+
LOCK_INTERVAL
|
|
269
|
+
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as redis from 'redis';
|
|
3
|
+
import { chevre } from '../../../lib/index';
|
|
4
|
+
|
|
5
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
6
|
+
|
|
7
|
+
// tslint:disable-next-line:max-func-body-length
|
|
8
|
+
async function main() {
|
|
9
|
+
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
10
|
+
socket: {
|
|
11
|
+
port: Number(<string>process.env.REDIS_PORT),
|
|
12
|
+
host: <string>process.env.REDIS_HOST
|
|
13
|
+
},
|
|
14
|
+
password: <string>process.env.REDIS_KEY
|
|
15
|
+
});
|
|
16
|
+
await client.connect();
|
|
17
|
+
|
|
18
|
+
const confirmationNumberRepo = await chevre.repository.ConfirmationNumber.createInstance(client);
|
|
19
|
+
const result = await confirmationNumberRepo.publish({ orderDate: new Date() });
|
|
20
|
+
console.log(result);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
main()
|
|
24
|
+
.then(() => {
|
|
25
|
+
console.log('success!');
|
|
26
|
+
})
|
|
27
|
+
.catch(console.error);
|
package/example/src/moment.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment
|
|
2
|
+
import * as moment from 'moment';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
.startOf('day');
|
|
9
|
-
const targetImportThrough = moment(importThrough)
|
|
10
|
-
.tz('Asia/Tokyo')
|
|
11
|
-
.endOf('day');
|
|
12
|
-
console.log(targetImportFrom.toDate(), targetImportThrough.toDate());
|
|
4
|
+
const eventStartDate = '2025-04-10T01:00:00Z';
|
|
5
|
+
// const timeFormat = 'HH:mm:ssZ';
|
|
6
|
+
const time = '00:00:00+09:00';
|
|
7
|
+
// const time = '00:00:00Z';
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
10
|
+
const offset = time.slice(8);
|
|
11
|
+
console.log('offset:', offset);
|
|
12
|
+
|
|
13
|
+
// const opensMoment = moment(time, timeFormat, true);
|
|
14
|
+
// const utcOffset = opensMoment.utcOffset();
|
|
15
|
+
|
|
16
|
+
// const eventStartDateMoment = moment.utc(eventStartDate);
|
|
17
|
+
const eventStartDateMoment = moment(eventStartDate, true);
|
|
18
|
+
console.log(eventStartDateMoment);
|
|
19
|
+
console.log(eventStartDateMoment.utcOffset(offset));
|
|
20
|
+
|
|
21
|
+
const usageDate = moment(`${eventStartDateMoment.format('YYYY-MM-DD')}T${time}`, true);
|
|
22
|
+
console.log(usageDate);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
// tslint:disable:no-console no-magic-numbers no-null-keyword
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
const MONGOLAB_URI = String(process.env.MONGOLAB_URI);
|
|
6
|
+
|
|
7
|
+
interface IConnectionByAppName {
|
|
8
|
+
connection: mongoose.Connection;
|
|
9
|
+
isReady: boolean;
|
|
10
|
+
}
|
|
11
|
+
const uniqueConnections: Record<string, IConnectionByAppName> = {};
|
|
12
|
+
export async function getUniqueConnectionByAppName(params: { appName: string }): Promise<mongoose.Connection> {
|
|
13
|
+
const { appName } = params;
|
|
14
|
+
if (uniqueConnections[appName] === undefined) {
|
|
15
|
+
uniqueConnections[appName] = {
|
|
16
|
+
connection: mongoose.createConnection(MONGOLAB_URI, { appName }),
|
|
17
|
+
isReady: false
|
|
18
|
+
};
|
|
19
|
+
uniqueConnections[appName].connection.on('connected', () => console.log('connected'));
|
|
20
|
+
uniqueConnections[appName].connection.on('open', () => console.log('open'));
|
|
21
|
+
uniqueConnections[appName].connection.on('disconnected', () => console.log('disconnected'));
|
|
22
|
+
uniqueConnections[appName].connection.on('reconnected', () => console.log('reconnected'));
|
|
23
|
+
uniqueConnections[appName].connection.on('disconnecting', () => console.log('disconnecting'));
|
|
24
|
+
uniqueConnections[appName].connection.on('close', () => console.log('close'));
|
|
25
|
+
}
|
|
26
|
+
const conectionByAppName = uniqueConnections[appName];
|
|
27
|
+
|
|
28
|
+
if (!conectionByAppName.isReady) {
|
|
29
|
+
console.log('connecting(asPromise)...');
|
|
30
|
+
await conectionByAppName.connection.asPromise();
|
|
31
|
+
conectionByAppName.isReady = true;
|
|
32
|
+
} else {
|
|
33
|
+
console.log('is ready.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return conectionByAppName.connection;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function main() {
|
|
40
|
+
console.log(mongoose.connections.length, 'mongoose.connections found');
|
|
41
|
+
|
|
42
|
+
mongoose.connection.on('connected', () => console.log('connected'));
|
|
43
|
+
mongoose.connection.on('open', () => console.log('open'));
|
|
44
|
+
mongoose.connection.on('disconnected', () => console.log('disconnected'));
|
|
45
|
+
mongoose.connection.on('reconnected', () => console.log('reconnected'));
|
|
46
|
+
mongoose.connection.on('disconnecting', () => console.log('disconnecting'));
|
|
47
|
+
mongoose.connection.on('close', () => console.log('close'));
|
|
48
|
+
// await mongoose.connect(MONGOLAB_URI);
|
|
49
|
+
|
|
50
|
+
// const firstConnection = mongoose.createConnection(<string>process.env.MONGOLAB_URI);
|
|
51
|
+
// firstConnection.on('connected', () => console.log('connected'));
|
|
52
|
+
// firstConnection.on('open', () => console.log('open'));
|
|
53
|
+
// firstConnection.on('disconnected', () => console.log('disconnected'));
|
|
54
|
+
// firstConnection.on('reconnected', () => console.log('reconnected'));
|
|
55
|
+
// firstConnection.on('disconnecting', () => console.log('disconnecting'));
|
|
56
|
+
// firstConnection.on('close', () => console.log('close'));
|
|
57
|
+
|
|
58
|
+
// tslint:disable-next-line:prefer-array-literal
|
|
59
|
+
[...Array(10)].map(async (__, i) => {
|
|
60
|
+
getUniqueConnectionByAppName({ appName: 'xxx' })
|
|
61
|
+
.then(async (connectResult) => {
|
|
62
|
+
console.log('connected:', connectResult.id, i);
|
|
63
|
+
await getUniqueConnectionByAppName({ appName: 'xxx' });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log(mongoose.connections.length, 'mongoose.connections found');
|
|
68
|
+
|
|
69
|
+
// db.currentOp(true)
|
|
70
|
+
// .inprog.forEach((op) => {
|
|
71
|
+
// if (op.active = true && op.client != undefined) {
|
|
72
|
+
// const miniOp = {
|
|
73
|
+
// client: op.client, description: op.desc
|
|
74
|
+
// };
|
|
75
|
+
// console.log(miniOp);
|
|
76
|
+
// }
|
|
77
|
+
// });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main()
|
|
81
|
+
.catch(console.error);
|
|
@@ -55,14 +55,25 @@ async function main() {
|
|
|
55
55
|
console.log('redisClient created.', redisClient.options?.name);
|
|
56
56
|
|
|
57
57
|
const reply = await redisClient.CLIENT_LIST();
|
|
58
|
-
console.dir(reply, { depth: null });
|
|
58
|
+
// console.dir(reply, { depth: null });
|
|
59
59
|
console.dir(
|
|
60
60
|
reply.map(
|
|
61
61
|
({ id, name, age, idle, user, addr, flags }) => `${id}, ${name}, ${age}, ${idle}, ${user}, ${addr}, ${flags}`
|
|
62
62
|
),
|
|
63
63
|
{ depth: null }
|
|
64
64
|
);
|
|
65
|
+
const connectRedisCount = reply.filter(({ name }) => name.slice(-13) === ':connectRedis')
|
|
66
|
+
.length;
|
|
67
|
+
const clientsByName: Record<string, any> = {};
|
|
68
|
+
reply.forEach(({ name }) => {
|
|
69
|
+
if (clientsByName[name] === undefined) {
|
|
70
|
+
clientsByName[name] = { count: 0 };
|
|
71
|
+
}
|
|
72
|
+
clientsByName[name].count += 1;
|
|
73
|
+
});
|
|
65
74
|
console.log(reply.length, 'clients found');
|
|
75
|
+
console.log('connectRedisCount:', connectRedisCount);
|
|
76
|
+
console.log(clientsByName);
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
main()
|
|
@@ -22,7 +22,8 @@ const schemaDefinition = {
|
|
|
22
22
|
useInformResourceTypes: [String],
|
|
23
23
|
userPoolIdOld: String,
|
|
24
24
|
userPoolIdNew: String,
|
|
25
|
-
waiter: mongoose_1.SchemaTypes.Mixed
|
|
25
|
+
waiter: mongoose_1.SchemaTypes.Mixed,
|
|
26
|
+
useMongoAsStockHolder: Boolean
|
|
26
27
|
};
|
|
27
28
|
const schemaOptions = {
|
|
28
29
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -48,7 +49,12 @@ const schemaOptions = {
|
|
|
48
49
|
versionKey: false
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
|
-
const indexes = [
|
|
52
|
+
const indexes = [
|
|
53
|
+
[
|
|
54
|
+
{ 'project.id': 1 },
|
|
55
|
+
{ name: 'projectId' }
|
|
56
|
+
]
|
|
57
|
+
];
|
|
52
58
|
exports.indexes = indexes;
|
|
53
59
|
/**
|
|
54
60
|
* 設定スキーマ
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
+
import * as factory from '../../../factory';
|
|
3
|
+
interface ISubReservation {
|
|
4
|
+
identifier: string;
|
|
5
|
+
reservationNumber: string;
|
|
6
|
+
}
|
|
7
|
+
interface IAggregateReservation {
|
|
8
|
+
project: {
|
|
9
|
+
id: string;
|
|
10
|
+
typeOf: factory.organizationType.Project;
|
|
11
|
+
};
|
|
12
|
+
typeOf: 'AggregateReservation';
|
|
13
|
+
reservationCount: number;
|
|
14
|
+
reservationFor: {
|
|
15
|
+
id: string;
|
|
16
|
+
startDate: Date;
|
|
17
|
+
};
|
|
18
|
+
reservations: ISubReservation[];
|
|
19
|
+
expires: Date;
|
|
20
|
+
}
|
|
21
|
+
type IDocType = IAggregateReservation;
|
|
22
|
+
type IModel = Model<IDocType>;
|
|
23
|
+
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
24
|
+
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
25
|
+
declare const modelName = "StockHolder";
|
|
26
|
+
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
27
|
+
declare function createSchema(): ISchema;
|
|
28
|
+
export { createSchema, IModel, ISubReservation, IAggregateReservation, indexes, modelName };
|