@chevre/domain 22.9.0-alpha.8 → 22.9.0-alpha.80
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 +124 -0
- package/example/src/chevre/aggregation/aggregateOrderOfSeat.ts +159 -0
- package/example/src/chevre/checkPaymentServiceUniqueness.ts +79 -0
- package/example/src/chevre/countPotentiallyExpired.ts +42 -0
- package/example/src/chevre/executeOneTask.ts +41 -0
- package/example/src/chevre/{aggregateAllEvents2.ts → executeTaskIfExists.ts} +19 -10
- package/example/src/chevre/findExecutableTask.ts +50 -0
- package/example/src/chevre/makeExpiredManyTasks.ts +27 -0
- package/example/src/chevre/makeTransactionExpired.ts +28 -0
- package/example/src/chevre/migratePaymentServiceChannelIds.ts +107 -0
- package/example/src/chevre/notifyAbortedTasksByEmail.ts +56 -0
- package/example/src/chevre/notifyByEmail.ts +43 -0
- package/example/src/chevre/reExportAction.ts +40 -0
- package/example/src/chevre/reIndex.ts +1 -2
- package/example/src/chevre/recreateRefundTasks.ts +187 -0
- package/example/src/chevre/saveWebSite.ts +59 -0
- package/example/src/chevre/searchAuthorizations.ts +4 -3
- package/example/src/chevre/searchPaymentServices.ts +32 -0
- package/example/src/chevre/sendEmailMessage.ts +60 -0
- package/example/src/chevre/sendGrid/filterEmailActivity.ts +2 -4
- package/example/src/chevre/transaction/startExportTasks.ts +4 -3
- package/example/src/chevre/unsetUnnecessaryFields.ts +4 -3
- package/lib/chevre/credentials/sendGrid.d.ts +13 -0
- package/lib/chevre/credentials/sendGrid.js +4 -1
- package/lib/chevre/eventEmitter/task.d.ts +1 -1
- package/lib/chevre/repo/action.d.ts +13 -98
- package/lib/chevre/repo/action.js +54 -41
- package/lib/chevre/repo/aggregateOrder.d.ts +27 -0
- package/lib/chevre/repo/aggregateOrder.js +148 -0
- package/lib/chevre/repo/assetTransaction.d.ts +41 -9
- package/lib/chevre/repo/assetTransaction.js +173 -52
- package/lib/chevre/repo/authorization.d.ts +2 -1
- package/lib/chevre/repo/authorization.js +25 -19
- package/lib/chevre/repo/identity.d.ts +5 -5
- package/lib/chevre/repo/identityProvider.d.ts +32 -7
- package/lib/chevre/repo/identityProvider.js +11 -4
- package/lib/chevre/repo/mongoose/schemas/action.d.ts +3 -1
- package/lib/chevre/repo/mongoose/schemas/action.js +41 -1
- package/lib/chevre/repo/mongoose/schemas/aggregateOrder.d.ts +23 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +78 -0
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +22 -2
- package/lib/chevre/repo/mongoose/schemas/authorization.js +9 -0
- package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/identityProvider.d.ts +1 -29
- package/lib/chevre/repo/mongoose/schemas/identityProvider.js +0 -4
- package/lib/chevre/repo/mongoose/schemas/paymentService.js +29 -3
- package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.js +1 -2
- package/lib/chevre/repo/mongoose/schemas/potentialAction.d.ts +10 -0
- package/lib/chevre/repo/mongoose/schemas/potentialAction.js +56 -0
- package/lib/chevre/repo/mongoose/schemas/{interface.d.ts → reserveInterface.d.ts} +1 -1
- package/lib/chevre/repo/mongoose/schemas/{interface.js → reserveInterface.js} +2 -2
- package/lib/chevre/repo/mongoose/schemas/task.js +28 -9
- package/lib/chevre/repo/mongoose/schemas/transaction.js +19 -0
- package/lib/chevre/repo/mongoose/schemas/webSite.d.ts +10 -0
- package/lib/chevre/repo/mongoose/schemas/webSite.js +69 -0
- package/lib/chevre/repo/order.d.ts +56 -0
- package/lib/chevre/repo/order.js +122 -0
- package/lib/chevre/repo/paymentService.d.ts +5 -4
- package/lib/chevre/repo/paymentService.js +104 -37
- package/lib/chevre/repo/paymentServiceChannel.d.ts +5 -1
- package/lib/chevre/repo/paymentServiceChannel.js +6 -5
- package/lib/chevre/repo/potentialAction.d.ts +56 -0
- package/lib/chevre/repo/potentialAction.js +137 -0
- package/lib/chevre/repo/product.js +2 -1
- package/lib/chevre/repo/reservation.d.ts +1 -1
- package/lib/chevre/repo/{interface.d.ts → reserveInterface.d.ts} +3 -4
- package/lib/chevre/repo/{interface.js → reserveInterface.js} +11 -13
- package/lib/chevre/repo/seller.d.ts +12 -12
- package/lib/chevre/repo/task.d.ts +68 -8
- package/lib/chevre/repo/task.js +175 -53
- package/lib/chevre/repo/transaction.d.ts +61 -15
- package/lib/chevre/repo/transaction.js +228 -51
- package/lib/chevre/repo/webSite.d.ts +45 -0
- package/lib/chevre/repo/webSite.js +165 -0
- package/lib/chevre/repository.d.ts +20 -5
- package/lib/chevre/repository.js +54 -15
- package/lib/chevre/service/assetTransaction/cancelReservation/factory.d.ts +3 -1
- package/lib/chevre/service/assetTransaction/cancelReservation/factory.js +51 -59
- package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +28 -0
- package/lib/chevre/service/assetTransaction/cancelReservation/start.js +106 -0
- package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.d.ts +6 -0
- package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.js +52 -0
- package/lib/chevre/service/assetTransaction/cancelReservation.d.ts +6 -23
- package/lib/chevre/service/assetTransaction/cancelReservation.js +5 -130
- package/lib/chevre/service/assetTransaction/fixInformAction.d.ts +16 -0
- package/lib/chevre/service/assetTransaction/fixInformAction.js +51 -0
- package/lib/chevre/service/assetTransaction/pay/factory.d.ts +7 -0
- package/lib/chevre/service/assetTransaction/pay/factory.js +27 -16
- package/lib/chevre/service/assetTransaction/pay.d.ts +12 -20
- package/lib/chevre/service/assetTransaction/pay.js +21 -42
- package/lib/chevre/service/assetTransaction/refund/factory.d.ts +6 -0
- package/lib/chevre/service/assetTransaction/refund/factory.js +29 -22
- package/lib/chevre/service/assetTransaction/refund/potentialActions.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/refund/potentialActions.js +37 -33
- package/lib/chevre/service/assetTransaction/refund.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/refund.js +11 -4
- package/lib/chevre/service/assetTransaction/reserve/confirm.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +1 -1
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.d.ts +1 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +3 -2
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +4 -0
- package/lib/chevre/service/assetTransaction/reserve/start.js +6 -4
- package/lib/chevre/service/assetTransaction/reserveCOA/cancel.d.ts +26 -0
- package/lib/chevre/service/assetTransaction/reserveCOA/cancel.js +112 -0
- package/lib/chevre/service/assetTransaction.d.ts +10 -8
- package/lib/chevre/service/assetTransaction.js +6 -8
- package/lib/chevre/service/notification/factory.d.ts +8 -0
- package/lib/chevre/service/notification/factory.js +25 -3
- package/lib/chevre/service/notification.d.ts +12 -1
- package/lib/chevre/service/notification.js +222 -25
- package/lib/chevre/service/offer/any.d.ts +1 -9
- package/lib/chevre/service/offer/any.js +1 -8
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +1 -0
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +4 -1
- package/lib/chevre/service/offer/event/authorize.js +10 -3
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.d.ts +14 -0
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.js +5 -89
- package/lib/chevre/service/offer/event/voidTransaction.d.ts +3 -0
- package/lib/chevre/service/offer/event/voidTransaction.js +8 -6
- package/lib/chevre/service/offer/event/voidTransactionByActionId.d.ts +3 -0
- package/lib/chevre/service/offer/event/voidTransactionByActionId.js +5 -3
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +4 -0
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +12 -0
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +0 -4
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +13 -1
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +1 -1
- package/lib/chevre/service/offer/moneyTransfer/authorize.js +9 -2
- package/lib/chevre/service/offer/onEventChanged.js +16 -7
- package/lib/chevre/service/offer/product.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +31 -23
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +31 -23
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +3 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +50 -32
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +31 -23
- package/lib/chevre/service/order/onOrderUpdated/factory.js +30 -23
- package/lib/chevre/service/payment/any/factory.d.ts +20 -14
- package/lib/chevre/service/payment/any/factory.js +47 -16
- package/lib/chevre/service/payment/any/fixOrderAsNeeded.d.ts +20 -0
- package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +41 -0
- package/lib/chevre/service/payment/any/{onPaid.d.ts → onPayActionCompleted.d.ts} +2 -5
- package/lib/chevre/service/payment/any/{onPaid.js → onPayActionCompleted.js} +35 -10
- package/lib/chevre/service/payment/any/onPaymentStatusChanged.d.ts +2 -2
- package/lib/chevre/service/payment/any/{onRefund.d.ts → onRefundActionCompletedOrFailed.d.ts} +4 -2
- package/lib/chevre/service/payment/any/{onRefund.js → onRefundActionCompletedOrFailed.js} +48 -29
- package/lib/chevre/service/payment/any.d.ts +21 -7
- package/lib/chevre/service/payment/any.js +180 -89
- package/lib/chevre/service/payment/creditCard/authorize.js +4 -2
- package/lib/chevre/service/payment/creditCard/factory.d.ts +1 -0
- package/lib/chevre/service/payment/creditCard/factory.js +2 -2
- package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.d.ts +1 -0
- package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.js +8 -6
- package/lib/chevre/service/payment/creditCard/gmoError.d.ts +8 -1
- package/lib/chevre/service/payment/creditCard/gmoError.js +7 -0
- package/lib/chevre/service/payment/creditCard/payCreditCard.js +8 -4
- package/lib/chevre/service/payment/creditCard/refundCreditCard.d.ts +3 -4
- package/lib/chevre/service/payment/creditCard/refundCreditCard.js +118 -64
- package/lib/chevre/service/payment/creditCard/voidTransaction.js +4 -2
- package/lib/chevre/service/payment/faceToFace.js +5 -5
- package/lib/chevre/service/payment/factory.d.ts +1 -1
- package/lib/chevre/service/payment/factory.js +32 -37
- package/lib/chevre/service/payment/movieTicket/authorize.js +35 -17
- package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
- package/lib/chevre/service/payment/movieTicket/factory.js +9 -13
- package/lib/chevre/service/payment/movieTicket/payMovieTicket.d.ts +5 -1
- package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +14 -12
- package/lib/chevre/service/payment/movieTicket/refundMovieTicket.d.ts +4 -1
- package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +16 -15
- package/lib/chevre/service/payment/movieTicket/voidTransaction.js +7 -2
- package/lib/chevre/service/payment/paymentCard.js +5 -6
- package/lib/chevre/service/reserve/cancelReservation.d.ts +1 -1
- package/lib/chevre/service/reserve/cancelReservation.js +17 -23
- package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
- package/lib/chevre/service/reserve/checkInReservation.js +41 -26
- package/lib/chevre/service/reserve/confirmReservation.d.ts +2 -5
- package/lib/chevre/service/reserve/confirmReservation.js +4 -11
- package/lib/chevre/service/reserve/factory.d.ts +1 -3
- package/lib/chevre/service/reserve/factory.js +11 -7
- package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.d.ts +2 -0
- package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.js +23 -11
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +23 -10
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +3 -0
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +17 -9
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +3 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +60 -11
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +22 -10
- package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.d.ts +2 -3
- package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.js +22 -10
- package/lib/chevre/service/reserve/useReservation.d.ts +3 -1
- package/lib/chevre/service/reserve/useReservation.js +25 -25
- package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +3 -1
- package/lib/chevre/service/reserve/verifyToken4reservation.js +3 -1
- package/lib/chevre/service/reserveCOA/cancelReservation.d.ts +12 -0
- package/lib/chevre/service/reserveCOA/cancelReservation.js +78 -0
- package/lib/chevre/service/reserveCOA/factory.d.ts +13 -0
- package/lib/chevre/service/reserveCOA/factory.js +23 -0
- package/lib/chevre/service/task/acceptCOAOffer.js +9 -3
- package/lib/chevre/service/task/authorizePayment.js +7 -6
- package/lib/chevre/service/task/cancelPendingReservation.d.ts +2 -2
- package/lib/chevre/service/task/cancelPendingReservation.js +52 -16
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +2 -0
- package/lib/chevre/service/task/confirmReserveTransaction.js +5 -3
- package/lib/chevre/service/task/deletePerson.js +46 -42
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +3 -3
- package/lib/chevre/service/task/importEventsFromCOA.js +3 -3
- package/lib/chevre/service/task/importOffersFromCOA.js +3 -4
- package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +3 -0
- package/lib/chevre/service/task/invalidatePaymentUrl.js +33 -0
- package/lib/chevre/service/task/onAuthorizationCreated.d.ts +2 -2
- package/lib/chevre/service/task/onAuthorizationCreated.js +11 -16
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +8 -5
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +8 -5
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +8 -5
- package/lib/chevre/service/task/onResourceUpdated.js +48 -27
- package/lib/chevre/service/task/pay.js +3 -3
- package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.d.ts +28 -0
- package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +33 -0
- package/lib/chevre/service/task/payment/payByTask.d.ts +48 -0
- package/lib/chevre/service/{payment.js → task/payment/payByTask.js} +16 -65
- package/lib/chevre/service/task/payment/refundByTask.d.ts +31 -0
- package/lib/chevre/service/task/payment/refundByTask.js +41 -0
- package/lib/chevre/service/task/payment/voidPaymentByTask.d.ts +23 -0
- package/lib/chevre/service/task/payment/voidPaymentByTask.js +38 -0
- package/lib/chevre/service/task/publishPaymentUrl.js +4 -0
- package/lib/chevre/service/task/refund.js +2 -2
- package/lib/chevre/service/task/reserve.js +2 -0
- package/lib/chevre/service/task/returnPayTransaction.js +10 -2
- package/lib/chevre/service/task/returnReserveTransaction.js +15 -6
- package/lib/chevre/service/task/triggerWebhook.js +2 -2
- package/lib/chevre/service/task/useReservation.js +14 -1
- package/lib/chevre/service/task/voidPayTransaction.js +5 -3
- package/lib/chevre/service/task/voidPayment.js +2 -2
- package/lib/chevre/service/task/voidReserveTransaction.js +4 -4
- package/lib/chevre/service/task.d.ts +21 -11
- package/lib/chevre/service/task.js +75 -32
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +2 -1
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +13 -7
- package/lib/chevre/service/transaction/placeOrder/confirm.js +29 -2
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +5 -3
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +80 -54
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +4 -0
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +2 -1
- package/lib/chevre/service/transaction/placeOrder.js +0 -2
- package/lib/chevre/service/transaction.d.ts +15 -8
- package/lib/chevre/service/transaction.js +8 -11
- package/package.json +4 -3
- package/example/src/chevre/migratePaymentServiceChannelsCreditCard.ts +0 -132
- package/example/src/chevre/migratePaymentServiceChannelsMovieTicket.ts +0 -113
- package/example/src/chevre/reexportTasksByExportAction.ts +0 -37
- package/example/src/chevre/retryTasks.ts +0 -41
- package/example/src/chevre/saveTasks.ts +0 -53
- package/example/src/chevre/searchPriceSpecifications.ts +0 -56
- package/lib/chevre/service/payment/any/fixConfirmationNumberAsNeeded.d.ts +0 -11
- package/lib/chevre/service/payment/any/fixConfirmationNumberAsNeeded.js +0 -31
- package/lib/chevre/service/payment.d.ts +0 -95
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
// import * as fs from 'fs';
|
|
3
|
+
import * as moment from 'moment-timezone';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
import { chevre } from '../../../../lib/index';
|
|
7
|
+
|
|
8
|
+
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
9
|
+
const AGGREGATE_PERIOD_IN_DAYS = 365;
|
|
10
|
+
|
|
11
|
+
function createAggregation(params: {
|
|
12
|
+
order: Pick<chevre.factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'project'>;
|
|
13
|
+
orderDateGte: Date;
|
|
14
|
+
orderDateLte: Date;
|
|
15
|
+
}) {
|
|
16
|
+
return async (repos: {
|
|
17
|
+
order: chevre.repository.Order;
|
|
18
|
+
}) => {
|
|
19
|
+
const { order, orderDateGte, orderDateLte } = params;
|
|
20
|
+
|
|
21
|
+
return repos.order.aggregateOrderOfCustomer({
|
|
22
|
+
project: { id: { $eq: PROJECT_ID } },
|
|
23
|
+
orderDate: { $gte: orderDateGte, $lte: orderDateLte },
|
|
24
|
+
customer: { email: { $eq: String(order.customer.email) } }
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// tslint:disable-next-line:max-func-body-length
|
|
30
|
+
async function main() {
|
|
31
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
32
|
+
|
|
33
|
+
const aggregateOrderRepo = await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
|
|
34
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
35
|
+
|
|
36
|
+
const orderDateLte: Date = moment()
|
|
37
|
+
.toDate();
|
|
38
|
+
const orderDateGte: Date = moment(orderDateLte)
|
|
39
|
+
.add(-AGGREGATE_PERIOD_IN_DAYS, 'days')
|
|
40
|
+
.toDate();
|
|
41
|
+
|
|
42
|
+
const cursor = orderRepo.getCursor(
|
|
43
|
+
{
|
|
44
|
+
'project.id': { $eq: PROJECT_ID },
|
|
45
|
+
orderDate: {
|
|
46
|
+
$gte: orderDateGte,
|
|
47
|
+
$lte: orderDateLte
|
|
48
|
+
},
|
|
49
|
+
typeOf: { $eq: chevre.factory.order.OrderType.Order }
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
customer: 1,
|
|
53
|
+
orderDate: 1,
|
|
54
|
+
orderNumber: 1,
|
|
55
|
+
project: 1
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
console.log('docs found');
|
|
59
|
+
|
|
60
|
+
let maxSumGraceTime: number = 0;
|
|
61
|
+
const peopleWithAggregateOrder: {
|
|
62
|
+
identifier: string;
|
|
63
|
+
aggregateOrder: {
|
|
64
|
+
// emailCount: number;
|
|
65
|
+
orderCount: number;
|
|
66
|
+
sumGraceTime: number;
|
|
67
|
+
};
|
|
68
|
+
score?: number;
|
|
69
|
+
}[] = [];
|
|
70
|
+
|
|
71
|
+
let i = 0;
|
|
72
|
+
let updateCount = 0;
|
|
73
|
+
// tslint:disable-next-line:max-func-body-length
|
|
74
|
+
await cursor.eachAsync(async (doc) => {
|
|
75
|
+
i += 1;
|
|
76
|
+
const order: Pick<chevre.factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'project'> = doc.toObject();
|
|
77
|
+
|
|
78
|
+
const { email } = order.customer;
|
|
79
|
+
if (typeof email === 'string') {
|
|
80
|
+
console.log(
|
|
81
|
+
'aggregating...',
|
|
82
|
+
order.project.id, order.orderNumber, order.orderDate, i);
|
|
83
|
+
const aggregateResult = await createAggregation({ order, orderDateGte, orderDateLte })({ order: orderRepo });
|
|
84
|
+
await aggregateOrderRepo.save(
|
|
85
|
+
{
|
|
86
|
+
project: order.project,
|
|
87
|
+
identifier: email,
|
|
88
|
+
typeOf: chevre.factory.personType.Person
|
|
89
|
+
},
|
|
90
|
+
{ $set: { aggregateOrder: aggregateResult.aggregation } }
|
|
91
|
+
);
|
|
92
|
+
updateCount += 1;
|
|
93
|
+
console.log(
|
|
94
|
+
'aggregated.',
|
|
95
|
+
order.project.id, order.orderNumber, order.orderDate, i);
|
|
96
|
+
|
|
97
|
+
const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
|
|
98
|
+
? aggregateResult.aggregation.sumGraceTime
|
|
99
|
+
: 0;
|
|
100
|
+
maxSumGraceTime = Math.max(sumGraceTime, maxSumGraceTime);
|
|
101
|
+
|
|
102
|
+
peopleWithAggregateOrder.push({
|
|
103
|
+
identifier: email,
|
|
104
|
+
aggregateOrder: {
|
|
105
|
+
...aggregateResult.aggregation,
|
|
106
|
+
sumGraceTime
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
console.log('maxSumGraceTime:', maxSumGraceTime);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
console.log(i, 'docs checked');
|
|
114
|
+
console.log(updateCount, 'docs aggregated');
|
|
115
|
+
|
|
116
|
+
// tslint:disable-next-line:non-literal-fs-path no-null-keyword
|
|
117
|
+
// fs.writeFileSync(`${__dirname}/peopleWithAggregateOrder.json`, JSON.stringify(peopleWithAggregateOrder, null, ' '));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
main()
|
|
121
|
+
.then(() => {
|
|
122
|
+
console.log('success!');
|
|
123
|
+
})
|
|
124
|
+
.catch(console.error);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as moment from 'moment-timezone';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
import { chevre } from '../../../../lib/index';
|
|
7
|
+
|
|
8
|
+
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
9
|
+
// const SCREEN_CODE = '10';
|
|
10
|
+
// const MOVIE_THEATER_CODE = '118';
|
|
11
|
+
// const SCREEN_CODE = '130';
|
|
12
|
+
const SCREEN_CODE = '211';
|
|
13
|
+
const MOVIE_THEATER_CODE = '020';
|
|
14
|
+
const AGGREGATE_PERIOD_IN_MONTHS = 12;
|
|
15
|
+
// tslint:disable-next-line:max-func-body-length
|
|
16
|
+
async function main() {
|
|
17
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
18
|
+
|
|
19
|
+
const seatRepo = await chevre.repository.place.Seat.createInstance(mongoose.connection);
|
|
20
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
21
|
+
|
|
22
|
+
const seats = <Pick<chevre.factory.place.seat.IPlace, 'branchCode'>[]>await seatRepo.searchSeats({
|
|
23
|
+
// limit: 50,
|
|
24
|
+
$projection: {
|
|
25
|
+
additionalProperty: 0,
|
|
26
|
+
'containedInPlace.typeOf': 0,
|
|
27
|
+
'containedInPlace.name': 0,
|
|
28
|
+
'containedInPlace.containedInPlace': 0,
|
|
29
|
+
name: 0, typeOf: 0
|
|
30
|
+
},
|
|
31
|
+
project: { id: { $eq: PROJECT_ID } },
|
|
32
|
+
containedInPlace: {
|
|
33
|
+
containedInPlace: {
|
|
34
|
+
branchCode: { $eq: SCREEN_CODE },
|
|
35
|
+
containedInPlace: { branchCode: { $eq: MOVIE_THEATER_CODE } }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
// tslint:disable-next-line:no-null-keyword
|
|
40
|
+
// console.dir(seats, { depth: null });
|
|
41
|
+
console.log(seats.length, 'seats found');
|
|
42
|
+
|
|
43
|
+
const orderDateGte: Date = moment()
|
|
44
|
+
.add(-AGGREGATE_PERIOD_IN_MONTHS, 'months')
|
|
45
|
+
.toDate();
|
|
46
|
+
const orderDateLte: Date = moment()
|
|
47
|
+
.toDate();
|
|
48
|
+
|
|
49
|
+
let maxSumGraceTime: number = 0;
|
|
50
|
+
let maxRepeatRate: number = 0;
|
|
51
|
+
const seatsWithAggregateOrder: {
|
|
52
|
+
branchCode: string;
|
|
53
|
+
aggregateOrder: {
|
|
54
|
+
emailCount: number;
|
|
55
|
+
orderCount: number;
|
|
56
|
+
repeatRate: number;
|
|
57
|
+
avgGraceTime?: number;
|
|
58
|
+
sumGraceTime: number;
|
|
59
|
+
avgGraceTimeInHours?: number;
|
|
60
|
+
sumGraceTimeInHours: number;
|
|
61
|
+
};
|
|
62
|
+
score?: number;
|
|
63
|
+
}[] = [];
|
|
64
|
+
let i = 1;
|
|
65
|
+
for (const { branchCode } of seats) {
|
|
66
|
+
i += 1;
|
|
67
|
+
const startTime = process.hrtime();
|
|
68
|
+
const aggregateResult = await orderRepo.aggregateOrderOfSeat({
|
|
69
|
+
project: { id: { $eq: PROJECT_ID } },
|
|
70
|
+
orderDate: { $gte: orderDateGte, $lte: orderDateLte },
|
|
71
|
+
acceptedOffers: {
|
|
72
|
+
itemOffered: {
|
|
73
|
+
reservationFor: {
|
|
74
|
+
location: { branchCode: SCREEN_CODE },
|
|
75
|
+
superEvent: { location: { branchCode: MOVIE_THEATER_CODE } }
|
|
76
|
+
},
|
|
77
|
+
reservedTicket: { ticketedSeat: { seatNumber: branchCode } }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
console.log('aggregateOrder:result', aggregateResult, orderDateGte, orderDateLte, i);
|
|
82
|
+
const diff = process.hrtime(startTime);
|
|
83
|
+
console.log(`importing chevre took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
|
|
84
|
+
|
|
85
|
+
const emailCount = (typeof aggregateResult.aggregation.emailCount === 'number')
|
|
86
|
+
? aggregateResult.aggregation.emailCount
|
|
87
|
+
: 0;
|
|
88
|
+
const repeatRate = (aggregateResult.aggregation.orderCount > 0)
|
|
89
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
90
|
+
? (aggregateResult.aggregation.orderCount - emailCount) * 100 / aggregateResult.aggregation.orderCount
|
|
91
|
+
: 0;
|
|
92
|
+
const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
|
|
93
|
+
? aggregateResult.aggregation.sumGraceTime
|
|
94
|
+
: 0;
|
|
95
|
+
const avgGraceTimeInHours = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
|
|
96
|
+
? Math.floor(
|
|
97
|
+
moment.duration(Math.floor(aggregateResult.aggregation.sumGraceTime / aggregateResult.aggregation.orderCount), 'milliseconds')
|
|
98
|
+
.asHours()
|
|
99
|
+
)
|
|
100
|
+
: 0;
|
|
101
|
+
const sumGraceTimeInHours = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
|
|
102
|
+
? Math.floor(moment.duration(aggregateResult.aggregation.sumGraceTime, 'milliseconds')
|
|
103
|
+
.asHours())
|
|
104
|
+
: 0;
|
|
105
|
+
maxSumGraceTime = Math.max(sumGraceTime, maxSumGraceTime);
|
|
106
|
+
maxRepeatRate = Math.max(repeatRate, maxRepeatRate);
|
|
107
|
+
|
|
108
|
+
seatsWithAggregateOrder.push({
|
|
109
|
+
branchCode,
|
|
110
|
+
aggregateOrder: {
|
|
111
|
+
...aggregateResult.aggregation,
|
|
112
|
+
emailCount,
|
|
113
|
+
repeatRate,
|
|
114
|
+
avgGraceTimeInHours,
|
|
115
|
+
sumGraceTimeInHours,
|
|
116
|
+
sumGraceTime
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const seatsJson = seatsWithAggregateOrder.map((seat, key) => {
|
|
122
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
123
|
+
const score = Math.floor(seat.aggregateOrder.sumGraceTime * 100 / maxSumGraceTime);
|
|
124
|
+
console.log('aggregateOrder:result', seat.branchCode, key);
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
branchCode: seat.branchCode,
|
|
128
|
+
score
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const scoresByEmailJson = seatsWithAggregateOrder.map((seat, key) => {
|
|
133
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
134
|
+
const score = Math.floor(seat.aggregateOrder.repeatRate * 100 / maxRepeatRate);
|
|
135
|
+
console.log('aggregateOrder:result', seat.branchCode, seat.aggregateOrder.emailCount, key);
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
branchCode: seat.branchCode,
|
|
139
|
+
score
|
|
140
|
+
// repeatRate: seat.aggregateOrder.repeatRate,
|
|
141
|
+
// emailCount: seat.aggregateOrder.emailCount,
|
|
142
|
+
// orderCount: seat.aggregateOrder.orderCount
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
console.log('maxSumGraceTime:', maxSumGraceTime);
|
|
147
|
+
console.log('maxRepeatRate:', maxRepeatRate);
|
|
148
|
+
|
|
149
|
+
// tslint:disable-next-line:non-literal-fs-path no-null-keyword
|
|
150
|
+
fs.writeFileSync(`${__dirname}/seatScoresByGraceTime.json`, JSON.stringify(seatsJson, null, ' '));
|
|
151
|
+
// tslint:disable-next-line:non-literal-fs-path no-null-keyword
|
|
152
|
+
fs.writeFileSync(`${__dirname}/seatScoresByEmail.json`, JSON.stringify(scoresByEmailJson, null, ' '));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
main()
|
|
156
|
+
.then(() => {
|
|
157
|
+
console.log('success!');
|
|
158
|
+
})
|
|
159
|
+
.catch(console.error);
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
const cursor = paymentServiceRepo.getCursor(
|
|
16
|
+
{
|
|
17
|
+
typeOf: {
|
|
18
|
+
$in: [
|
|
19
|
+
chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
20
|
+
chevre.factory.service.paymentService.PaymentServiceType.MovieTicket
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
// _id: { $eq: '5f9a4fed4f3709000abe6415' }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
_id: 1,
|
|
27
|
+
availableChannel: 1,
|
|
28
|
+
productID: 1,
|
|
29
|
+
project: 1,
|
|
30
|
+
typeOf: 1,
|
|
31
|
+
serviceType: 1
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
console.log('docs found');
|
|
35
|
+
|
|
36
|
+
let i = 0;
|
|
37
|
+
// let updateCount = 0;
|
|
38
|
+
const unexpectedIds: string[] = [];
|
|
39
|
+
await cursor.eachAsync(async (doc) => {
|
|
40
|
+
i += 1;
|
|
41
|
+
const paymentService: Pick<
|
|
42
|
+
chevre.factory.service.paymentService.IService,
|
|
43
|
+
'availableChannel' | 'id' | 'productID' | 'project' | 'typeOf' | 'serviceType'
|
|
44
|
+
> = doc.toObject();
|
|
45
|
+
|
|
46
|
+
console.log(
|
|
47
|
+
'alreadyMigrated?', paymentService.project.id, paymentService.productID, i);
|
|
48
|
+
if (typeof paymentService.id !== 'string') {
|
|
49
|
+
throw new Error('id must be string');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let isUnique = false;
|
|
53
|
+
const existingServices = await paymentServiceRepo.projectFields(
|
|
54
|
+
{
|
|
55
|
+
project: { id: { $eq: paymentService.project.id } },
|
|
56
|
+
serviceType: { codeValue: { $eq: paymentService.serviceType.codeValue } }
|
|
57
|
+
},
|
|
58
|
+
['id']
|
|
59
|
+
);
|
|
60
|
+
if (existingServices.length === 1 && existingServices.at(0)?.id === paymentService.id) {
|
|
61
|
+
isUnique = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (isUnique) {
|
|
65
|
+
console.log(
|
|
66
|
+
'unique.', paymentService.project.id, paymentService.productID, i);
|
|
67
|
+
} else {
|
|
68
|
+
unexpectedIds.push(paymentService.productID);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(unexpectedIds);
|
|
73
|
+
console.log(i, 'docs checked');
|
|
74
|
+
console.log(unexpectedIds.length, 'docs unexpected');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
main()
|
|
78
|
+
.then()
|
|
79
|
+
.catch(console.error);
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
14
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
let result = await transactionRepo.countPotentiallyExpired({
|
|
17
|
+
expires: {
|
|
18
|
+
$lt: moment()
|
|
19
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
20
|
+
.add(-60, 'seconds')
|
|
21
|
+
.toDate()
|
|
22
|
+
},
|
|
23
|
+
limit: 10
|
|
24
|
+
});
|
|
25
|
+
console.log('result', result);
|
|
26
|
+
|
|
27
|
+
result = await taskRepo.countPotentiallyRunning({
|
|
28
|
+
runsAt: {
|
|
29
|
+
$lt: moment()
|
|
30
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
31
|
+
.add(-60, 'seconds')
|
|
32
|
+
.toDate()
|
|
33
|
+
},
|
|
34
|
+
name: { $eq: chevre.factory.taskName.DeleteTransaction },
|
|
35
|
+
limit: 10
|
|
36
|
+
});
|
|
37
|
+
console.log('result', result);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
main()
|
|
41
|
+
.then()
|
|
42
|
+
.catch(console.error);
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
const task = await taskRepo.executeOneIfExists({
|
|
14
|
+
name: {
|
|
15
|
+
$nin: [
|
|
16
|
+
chevre.factory.taskName.DeleteTransaction,
|
|
17
|
+
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
18
|
+
chevre.factory.taskName.ImportEventsFromCOA,
|
|
19
|
+
chevre.factory.taskName.AcceptCOAOffer,
|
|
20
|
+
chevre.factory.taskName.CheckMovieTicket,
|
|
21
|
+
chevre.factory.taskName.AuthorizePayment,
|
|
22
|
+
chevre.factory.taskName.PublishPaymentUrl
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
executor: { name: 'sample' },
|
|
26
|
+
runsAt: {
|
|
27
|
+
$lt: moment()
|
|
28
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
29
|
+
.add(-2, 'years')
|
|
30
|
+
// .add(-60, 'seconds')
|
|
31
|
+
.toDate()
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// tslint:disable-next-line:no-null-keyword
|
|
36
|
+
console.dir(task, { depth: null });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main()
|
|
40
|
+
.then()
|
|
41
|
+
.catch(console.error);
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
/**
|
|
3
|
-
* イベント集計タスク実行
|
|
4
|
-
*/
|
|
5
2
|
import { chevre } from '../../../lib/index';
|
|
6
3
|
|
|
7
4
|
import * as mongoose from 'mongoose';
|
|
8
5
|
import * as redis from 'redis';
|
|
9
6
|
|
|
10
|
-
export async function
|
|
7
|
+
export async function executeTaskIfExists() {
|
|
11
8
|
const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
12
9
|
socket: {
|
|
13
10
|
port: Number(<string>process.env.REDIS_PORT),
|
|
@@ -21,8 +18,8 @@ export async function aggregateScreeningEvent() {
|
|
|
21
18
|
|
|
22
19
|
let count = 0;
|
|
23
20
|
|
|
24
|
-
const MAX_NUBMER_OF_PARALLEL_TASKS =
|
|
25
|
-
const INTERVAL_MILLISECONDS =
|
|
21
|
+
const MAX_NUBMER_OF_PARALLEL_TASKS = 1;
|
|
22
|
+
const INTERVAL_MILLISECONDS = 1000;
|
|
26
23
|
|
|
27
24
|
setInterval(
|
|
28
25
|
async () => {
|
|
@@ -34,9 +31,21 @@ export async function aggregateScreeningEvent() {
|
|
|
34
31
|
|
|
35
32
|
try {
|
|
36
33
|
console.log('executing...', count);
|
|
37
|
-
await (await chevre.service.task.createService()).
|
|
38
|
-
name: chevre.factory.taskName.AggregateScreeningEvent,
|
|
39
|
-
executor: { name: 'sample' }
|
|
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
|
+
}
|
|
40
49
|
})({
|
|
41
50
|
connection: mongoose.connection,
|
|
42
51
|
redisClient,
|
|
@@ -64,7 +73,7 @@ export async function aggregateScreeningEvent() {
|
|
|
64
73
|
);
|
|
65
74
|
}
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
executeTaskIfExists()
|
|
68
77
|
.then(() => {
|
|
69
78
|
console.log('success!');
|
|
70
79
|
})
|
|
@@ -0,0 +1,50 @@
|
|
|
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);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-implicit-dependencies no-console
|
|
2
|
+
import { chevre } from '../../../lib/index';
|
|
3
|
+
|
|
4
|
+
import * as moment from 'moment';
|
|
5
|
+
import * as mongoose from 'mongoose';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const expiresLt = moment()
|
|
15
|
+
.add(-1, 'hour')
|
|
16
|
+
.toDate();
|
|
17
|
+
const result = await taskRepo.makeExpiredMany({
|
|
18
|
+
expiresLt
|
|
19
|
+
});
|
|
20
|
+
console.log('result:', result);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
main()
|
|
24
|
+
.then(() => {
|
|
25
|
+
console.log('success!');
|
|
26
|
+
})
|
|
27
|
+
.catch(console.error);
|
|
@@ -0,0 +1,28 @@
|
|
|
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, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const result = await transactionRepo.makeOneExpiredIfExists({
|
|
15
|
+
expires: {
|
|
16
|
+
$lt: moment()
|
|
17
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
18
|
+
.add(-60, 'seconds')
|
|
19
|
+
.toDate()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
console.log('result:', result);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
main()
|
|
27
|
+
.then()
|
|
28
|
+
.catch(console.error);
|