@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
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import { chevre } from '../../../lib/index';
|
|
3
|
-
|
|
4
|
-
import * as mongoose from 'mongoose';
|
|
5
|
-
import * as redis from 'redis';
|
|
6
|
-
|
|
7
|
-
export async function executeTaskIfExists() {
|
|
8
|
-
const redisClient = 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
|
-
await redisClient.connect();
|
|
16
|
-
|
|
17
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
18
|
-
|
|
19
|
-
let count = 0;
|
|
20
|
-
|
|
21
|
-
const MAX_NUBMER_OF_PARALLEL_TASKS = 1;
|
|
22
|
-
const INTERVAL_MILLISECONDS = 1000;
|
|
23
|
-
|
|
24
|
-
setInterval(
|
|
25
|
-
async () => {
|
|
26
|
-
if (count > MAX_NUBMER_OF_PARALLEL_TASKS) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
count += 1;
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
console.log('executing...', count);
|
|
34
|
-
await (await chevre.service.task.createService()).executeOneIfExists({
|
|
35
|
-
// name: chevre.factory.taskName.AggregateScreeningEvent,
|
|
36
|
-
executor: { name: 'sample' },
|
|
37
|
-
runsAt: { $lt: new Date() },
|
|
38
|
-
name: {
|
|
39
|
-
$nin: [
|
|
40
|
-
chevre.factory.taskName.DeleteTransaction,
|
|
41
|
-
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
42
|
-
chevre.factory.taskName.ImportEventsFromCOA,
|
|
43
|
-
chevre.factory.taskName.AcceptCOAOffer,
|
|
44
|
-
chevre.factory.taskName.CheckMovieTicket,
|
|
45
|
-
chevre.factory.taskName.AuthorizePayment,
|
|
46
|
-
chevre.factory.taskName.PublishPaymentUrl
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
})({
|
|
50
|
-
connection: mongoose.connection,
|
|
51
|
-
redisClient,
|
|
52
|
-
credentials: {
|
|
53
|
-
sendGrid: await chevre.credentials.SendGrid.createInstance({ apiKey: 'xxx' })
|
|
54
|
-
},
|
|
55
|
-
settings: new chevre.settings.Settings({
|
|
56
|
-
deliverOrderLimit: 1,
|
|
57
|
-
abortedTasksWithoutReport: [],
|
|
58
|
-
coa: { timeout: 1000 },
|
|
59
|
-
gmo: { timeout: 1000, timeoutBackground: 1000, useFetch: true },
|
|
60
|
-
movieticketReserve: { timeout: 1000, timeoutCheck: 1000, minIntervalBetweenPayAndRefund: 0 },
|
|
61
|
-
numTryConfirmReserveTransaction: 10,
|
|
62
|
-
useExperimentalFeature: false
|
|
63
|
-
})
|
|
64
|
-
});
|
|
65
|
-
console.log('executed', count);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.error(error);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
count -= 1;
|
|
71
|
-
},
|
|
72
|
-
INTERVAL_MILLISECONDS
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
executeTaskIfExists()
|
|
77
|
-
.then(() => {
|
|
78
|
-
console.log('success!');
|
|
79
|
-
})
|
|
80
|
-
.catch(console.error);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
11
|
-
|
|
12
|
-
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
setInterval(
|
|
15
|
-
async () => {
|
|
16
|
-
const startTime = process.hrtime();
|
|
17
|
-
const task = await taskRepo.findExecutableOne({
|
|
18
|
-
name: {
|
|
19
|
-
$eq: chevre.factory.taskName.VoidReserveTransaction
|
|
20
|
-
// $nin: [
|
|
21
|
-
// chevre.factory.taskName.DeleteTransaction,
|
|
22
|
-
// chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
23
|
-
// chevre.factory.taskName.ImportEventsFromCOA,
|
|
24
|
-
// chevre.factory.taskName.AcceptCOAOffer,
|
|
25
|
-
// chevre.factory.taskName.CheckMovieTicket,
|
|
26
|
-
// chevre.factory.taskName.AuthorizePayment,
|
|
27
|
-
// chevre.factory.taskName.PublishPaymentUrl
|
|
28
|
-
// ]
|
|
29
|
-
},
|
|
30
|
-
runsAt: {
|
|
31
|
-
$lt: moment()
|
|
32
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
33
|
-
.add(-60, 'seconds')
|
|
34
|
-
.toDate()
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
const diff = process.hrtime(startTime);
|
|
38
|
-
console.log(`took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
|
|
39
|
-
|
|
40
|
-
// tslint:disable-next-line:no-null-keyword
|
|
41
|
-
console.dir(task?.id, { depth: null });
|
|
42
|
-
},
|
|
43
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
44
|
-
1000
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
main()
|
|
49
|
-
.then()
|
|
50
|
-
.catch(console.error);
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
const informOrderUrls = (typeof process.env.INFORM_ORDER_URL === 'string')
|
|
7
|
-
? process.env.INFORM_ORDER_URL.split(' ')
|
|
8
|
-
: [];
|
|
9
|
-
// const informReservationUrls = (typeof process.env.INFORM_RESERVATION_URL === 'string')
|
|
10
|
-
// ? process.env.INFORM_RESERVATION_URL.split(' ')
|
|
11
|
-
// : [];
|
|
12
|
-
// const informResourceUrls = (typeof process.env.INFORM_RESOURCE_URL === 'string')
|
|
13
|
-
// ? process.env.INFORM_RESOURCE_URL.split(',')
|
|
14
|
-
// : [];
|
|
15
|
-
// const informEvent2aggUrls = (typeof process.env.INFORM_EVENT_AGG_URL === 'string')
|
|
16
|
-
// ? process.env.INFORM_EVENT_AGG_URL.split(' ')
|
|
17
|
-
// : [];
|
|
18
|
-
// const userPoolIdOld = process.env.USERPOOL_ID_OLD;
|
|
19
|
-
// const userPoolIdNew = process.env.USERPOOL_ID_NEW;
|
|
20
|
-
// const defaultSenderEmail = process.env.DEFAULT_SENDER_EMAIL;
|
|
21
|
-
|
|
22
|
-
// tslint:disable-next-line:max-func-body-length
|
|
23
|
-
async function main() {
|
|
24
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
25
|
-
|
|
26
|
-
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
27
|
-
|
|
28
|
-
const result = await settingRepo.findOne({}, ['triggerWebhook', 'waiter']);
|
|
29
|
-
// tslint:disable-next-line:no-null-keyword
|
|
30
|
-
console.dir(result, { depth: null });
|
|
31
|
-
|
|
32
|
-
if (result === null) {
|
|
33
|
-
if (informOrderUrls.length > 0) {
|
|
34
|
-
await settingRepo.saveOne({
|
|
35
|
-
project: { id: '*', typeOf: chevre.factory.organizationType.Project },
|
|
36
|
-
onOrderStatusChanged: {
|
|
37
|
-
informOrder: informOrderUrls
|
|
38
|
-
.filter((url) => url.length > 0)
|
|
39
|
-
.map((url) => {
|
|
40
|
-
return {
|
|
41
|
-
recipient: {
|
|
42
|
-
typeOf: chevre.factory.creativeWorkType.WebApplication,
|
|
43
|
-
name: 'Aggregation Service',
|
|
44
|
-
url
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
console.log('saved');
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
const updateResult = await settingRepo.updateByProject(
|
|
54
|
-
{ project: { id: { $eq: '*' } } },
|
|
55
|
-
{
|
|
56
|
-
triggerWebhook: {
|
|
57
|
-
timeout: 15000,
|
|
58
|
-
useFetchAPI: true,
|
|
59
|
-
secretKey: String(process.env.TRIGGER_WEBHOOK_SECRET_KEY),
|
|
60
|
-
headerIdentifier: String(process.env.TRIGGER_WEBHOOK_HEADER_IDENTIFIER),
|
|
61
|
-
retryCountMax: 2,
|
|
62
|
-
retryIntervalInMS: 1000
|
|
63
|
-
},
|
|
64
|
-
waiter: {
|
|
65
|
-
disabled: process.env.WAITER_DISABLED === '1',
|
|
66
|
-
passportUnavailable: process.env.WAITER_PASSPORT_UNAVAILABLE === '1',
|
|
67
|
-
passportIssuers: String(process.env.WAITER_PASSPORT_ISSUER)
|
|
68
|
-
.split(' '),
|
|
69
|
-
secret: String(process.env.WAITER_SECRET)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
console.log('updated', updateResult);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
main()
|
|
78
|
-
.then(console.log)
|
|
79
|
-
.catch(console.error);
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
8
|
-
const memberId = 'xxx';
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
12
|
-
|
|
13
|
-
const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
14
|
-
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
let now: Date;
|
|
17
|
-
|
|
18
|
-
now = new Date();
|
|
19
|
-
const searchPermissionsResult = await (await chevre.service.iam.createService()).searchPermissions({
|
|
20
|
-
project: { id: PROJECT_ID },
|
|
21
|
-
member: {
|
|
22
|
-
id: memberId,
|
|
23
|
-
memberOf: {
|
|
24
|
-
id: PROJECT_ID,
|
|
25
|
-
typeOf: chevre.factory.organizationType.Project
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
})({
|
|
29
|
-
member: memberRepo,
|
|
30
|
-
role: roleRepo
|
|
31
|
-
});
|
|
32
|
-
console.log('time cost:', moment()
|
|
33
|
-
.diff(now));
|
|
34
|
-
|
|
35
|
-
console.log(searchPermissionsResult);
|
|
36
|
-
console.log(searchPermissionsResult.permissions.length);
|
|
37
|
-
|
|
38
|
-
// console.log(aggregateRoleNamesResult);
|
|
39
|
-
// console.log(aggregateRoleNamesResult.length);
|
|
40
|
-
// console.log(aggregatePermissionsResult);
|
|
41
|
-
// console.log(aggregatePermissionsResult.length);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
main()
|
|
45
|
-
.then(console.log)
|
|
46
|
-
.catch(console.error);
|
|
@@ -1,29 +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
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
-
|
|
11
|
-
const productOfferRepo = await chevre.repository.ProductOffer.createInstance(mongoose.connection);
|
|
12
|
-
|
|
13
|
-
const offers = await productOfferRepo.search({
|
|
14
|
-
project: { id: { $eq: PROJECT_ID } }
|
|
15
|
-
// seller: { id: { $eq: 'xxx' } }
|
|
16
|
-
});
|
|
17
|
-
console.log(offers);
|
|
18
|
-
console.log(offers.length);
|
|
19
|
-
|
|
20
|
-
// await productOfferRepo.deleteOne({
|
|
21
|
-
// project: { id: PROJECT_ID },
|
|
22
|
-
// seller: { id: 'xxx' },
|
|
23
|
-
// itemOffered: { id: 'xxx' }
|
|
24
|
-
// });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
main()
|
|
28
|
-
.then(console.log)
|
|
29
|
-
.catch(console.error);
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
import * as redis from 'redis';
|
|
5
|
-
|
|
6
|
-
import { chevre } from '../../../../lib/index';
|
|
7
|
-
|
|
8
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
9
|
-
const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
10
|
-
|
|
11
|
-
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
12
|
-
socket: {
|
|
13
|
-
port: Number(<string>process.env.REDIS_PORT),
|
|
14
|
-
host: <string>process.env.REDIS_HOST
|
|
15
|
-
},
|
|
16
|
-
password: <string>process.env.REDIS_KEY
|
|
17
|
-
})
|
|
18
|
-
.on('error', (err) => {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.error('createDefaultRedisClient: client onError:', err);
|
|
21
|
-
// reject(err);
|
|
22
|
-
});
|
|
23
|
-
client.connect();
|
|
24
|
-
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
25
|
-
|
|
26
|
-
// tslint:disable-next-line:max-func-body-length
|
|
27
|
-
async function main() {
|
|
28
|
-
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
29
|
-
const stockHolderRepo = await chevre.repository.StockHolder.createInstance(
|
|
30
|
-
client,
|
|
31
|
-
mongoose.connection
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const cursor = eventRepo.getCursor(
|
|
35
|
-
{
|
|
36
|
-
'project.id': { $ne: excludedProject.id },
|
|
37
|
-
startDate: {
|
|
38
|
-
$gte: moment()
|
|
39
|
-
.add(-1, 'days')
|
|
40
|
-
.toDate()
|
|
41
|
-
},
|
|
42
|
-
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
|
|
43
|
-
// _id: { $eq: 'blyk9q24f' }
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
_id: 1,
|
|
47
|
-
// offers: 1,
|
|
48
|
-
startDate: 1,
|
|
49
|
-
project: 1,
|
|
50
|
-
typeOf: 1
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
console.log('events found');
|
|
54
|
-
|
|
55
|
-
let i = 0;
|
|
56
|
-
await cursor.eachAsync(async (doc) => {
|
|
57
|
-
i += 1;
|
|
58
|
-
const event: Pick<
|
|
59
|
-
chevre.factory.event.screeningEvent.IEvent,
|
|
60
|
-
'id' | 'startDate' | 'project' | 'typeOf'
|
|
61
|
-
> = doc.toObject();
|
|
62
|
-
|
|
63
|
-
console.log(
|
|
64
|
-
'conflicted?', event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
65
|
-
await stockHolderRepo.checkIfConflicted({
|
|
66
|
-
eventId: event.id,
|
|
67
|
-
startDate: event.startDate
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
console.log(i, 'events checked');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
main()
|
|
75
|
-
.then()
|
|
76
|
-
.catch(console.error);
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console no-magic-numbers
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
import * as redis from 'redis';
|
|
5
|
-
import * as util from 'util';
|
|
6
|
-
|
|
7
|
-
import { chevre } from '../../../../lib/index';
|
|
8
|
-
|
|
9
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
10
|
-
const { BACKLOG_ISSUE_KEY, BACKLOG_API_KEY, BACKLOG_SPACE_KEY } = process.env;
|
|
11
|
-
const BACKLOG_NOTIFY_URL = `https://${BACKLOG_SPACE_KEY}.backlog.jp/api/v2/issues/${BACKLOG_ISSUE_KEY}/comments?apiKey=${BACKLOG_API_KEY}`;
|
|
12
|
-
|
|
13
|
-
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
14
|
-
socket: {
|
|
15
|
-
port: Number(<string>process.env.REDIS_PORT),
|
|
16
|
-
host: <string>process.env.REDIS_HOST
|
|
17
|
-
},
|
|
18
|
-
password: <string>process.env.REDIS_KEY,
|
|
19
|
-
name: 'checkRedisKeyCount'
|
|
20
|
-
})
|
|
21
|
-
.on('error', (err) => {
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.error('createDefaultRedisClient: client onError:', err);
|
|
24
|
-
// reject(err);
|
|
25
|
-
});
|
|
26
|
-
client.connect();
|
|
27
|
-
mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
28
|
-
|
|
29
|
-
function countRedisKeyByProject(params: {
|
|
30
|
-
project: { id: string };
|
|
31
|
-
now: Date;
|
|
32
|
-
}) {
|
|
33
|
-
return async (repos: {
|
|
34
|
-
event: chevre.repository.Event;
|
|
35
|
-
stockHolder: chevre.repository.StockHolder;
|
|
36
|
-
}) => {
|
|
37
|
-
const cursor = repos.event.getCursor(
|
|
38
|
-
{
|
|
39
|
-
'project.id': {
|
|
40
|
-
$eq: params.project.id
|
|
41
|
-
},
|
|
42
|
-
// startDate: {
|
|
43
|
-
// $gte: params.now
|
|
44
|
-
// },
|
|
45
|
-
endDate: {
|
|
46
|
-
$gte: params.now
|
|
47
|
-
},
|
|
48
|
-
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
|
|
49
|
-
// _id: { $eq: 'blyk9q24f' }
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
_id: 1,
|
|
53
|
-
// offers: 1,
|
|
54
|
-
startDate: 1,
|
|
55
|
-
project: 1,
|
|
56
|
-
typeOf: 1
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
console.log('events found');
|
|
60
|
-
|
|
61
|
-
let i = 0;
|
|
62
|
-
let redisKeyCount = 0;
|
|
63
|
-
const eventsWithRedis: string[] = [];
|
|
64
|
-
await cursor.eachAsync(async (doc) => {
|
|
65
|
-
i += 1;
|
|
66
|
-
const event: Pick<
|
|
67
|
-
chevre.factory.event.screeningEvent.IEvent,
|
|
68
|
-
'id' | 'startDate' | 'project' | 'typeOf'
|
|
69
|
-
> = doc.toObject();
|
|
70
|
-
|
|
71
|
-
console.log('redisKeyExists?', event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
72
|
-
const redisKeyExists = await repos.stockHolder.redisKeyExists({
|
|
73
|
-
eventId: event.id,
|
|
74
|
-
startDate: event.startDate
|
|
75
|
-
});
|
|
76
|
-
console.log('redisKeyExists:', redisKeyExists, event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
77
|
-
|
|
78
|
-
if (redisKeyExists) {
|
|
79
|
-
redisKeyCount += 1;
|
|
80
|
-
eventsWithRedis.push(event.id);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
console.log(i, 'events checked');
|
|
85
|
-
console.log(redisKeyCount, 'redisKeys found');
|
|
86
|
-
|
|
87
|
-
return { checkedCount: i, redisKeyCount, eventsWithRedis };
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// tslint:disable-next-line:max-func-body-length
|
|
92
|
-
async function main() {
|
|
93
|
-
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
94
|
-
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
95
|
-
// const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
96
|
-
const stockHolderRepo = await chevre.repository.StockHolder.createInstance(
|
|
97
|
-
client,
|
|
98
|
-
mongoose.connection
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
let checkingProjects: string[] = [];
|
|
102
|
-
// 全プロジェクト
|
|
103
|
-
checkingProjects = (await projectRepo.projectFields(
|
|
104
|
-
{
|
|
105
|
-
// id: { $eq: 'xxx' }
|
|
106
|
-
},
|
|
107
|
-
['id']
|
|
108
|
-
)).map(({ id }) => id);
|
|
109
|
-
|
|
110
|
-
checkingProjects = checkingProjects.filter((id) => id.slice(0, 6) !== 'sskts-');
|
|
111
|
-
|
|
112
|
-
const results: {
|
|
113
|
-
project: { id: string };
|
|
114
|
-
checkedCount: number;
|
|
115
|
-
redisKeyCount: number;
|
|
116
|
-
}[] = [];
|
|
117
|
-
|
|
118
|
-
const now = moment()
|
|
119
|
-
.add(0, 'days')
|
|
120
|
-
.toDate();
|
|
121
|
-
for (const projectId of checkingProjects) {
|
|
122
|
-
const { checkedCount, redisKeyCount } = await countRedisKeyByProject({
|
|
123
|
-
project: { id: projectId },
|
|
124
|
-
now
|
|
125
|
-
})({
|
|
126
|
-
event: eventRepo,
|
|
127
|
-
stockHolder: stockHolderRepo
|
|
128
|
-
});
|
|
129
|
-
results.push({
|
|
130
|
-
project: { id: projectId },
|
|
131
|
-
checkedCount,
|
|
132
|
-
redisKeyCount
|
|
133
|
-
});
|
|
134
|
-
// console.log(eventsWithRedis);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const header = util.format(
|
|
138
|
-
'| %s | %s | %s | %s |\n| %s | %s | %s | %s |',
|
|
139
|
-
`project `.slice(0, 40),
|
|
140
|
-
`now `.slice(0, 24),
|
|
141
|
-
`checkedCount `.slice(0, 24),
|
|
142
|
-
`redisKeyCount `.slice(0, 24),
|
|
143
|
-
`---------------------------------------- `.slice(0, 40),
|
|
144
|
-
`------------------------ `.slice(0, 24),
|
|
145
|
-
`------------------------ `.slice(0, 24),
|
|
146
|
-
`------------------------ `.slice(0, 24)
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const text = util.format(
|
|
150
|
-
'%s\n%s',
|
|
151
|
-
header,
|
|
152
|
-
results.map((result) => {
|
|
153
|
-
return util.format(
|
|
154
|
-
'| %s | %s | %s | %s |',
|
|
155
|
-
`${result.project.id} `.slice(0, 40),
|
|
156
|
-
`${now.toISOString()} `.slice(0, 24),
|
|
157
|
-
`${result.checkedCount} `.slice(0, 24),
|
|
158
|
-
`${result.redisKeyCount} `.slice(0, 24)
|
|
159
|
-
);
|
|
160
|
-
})
|
|
161
|
-
.join('\n')
|
|
162
|
-
);
|
|
163
|
-
console.log(text);
|
|
164
|
-
|
|
165
|
-
// backlogへ通知
|
|
166
|
-
if (typeof BACKLOG_API_KEY === 'string') {
|
|
167
|
-
console.log('notifying on backlog...');
|
|
168
|
-
await fetch(
|
|
169
|
-
BACKLOG_NOTIFY_URL,
|
|
170
|
-
{
|
|
171
|
-
method: 'POST',
|
|
172
|
-
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
173
|
-
body: JSON.stringify({
|
|
174
|
-
content: text,
|
|
175
|
-
notifiedUserId: []
|
|
176
|
-
// notifiedUserId: users.map((user) => user.id)
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
console.log('posted to backlog.');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
main()
|
|
185
|
-
.then()
|
|
186
|
-
.catch(console.error);
|
|
@@ -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);
|