@chevre/domain 21.35.0-alpha.8 → 21.35.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/checkReserveTransactionSizes.ts +46 -0
- package/example/src/chevre/findCustomerByOrderNumber.ts +19 -0
- package/example/src/chevre/investigateMovieTicketIdentifier.ts +78 -0
- package/example/src/chevre/migrateAuthorizeEventServiceOfferCOA.ts +84 -0
- package/example/src/chevre/migrateAuthorizeEventServiceOfferChevre.ts +84 -0
- package/example/src/chevre/migrateAuthorizeEventServiceOfferInstrument.ts +128 -0
- package/example/src/chevre/migrateAuthorizeEventServiceOfferResult.ts +163 -0
- package/example/src/chevre/unsetUnnecessaryFieldsInAction.ts +55 -0
- package/example/src/chevre/{unsetUnnecessaryFields.ts → unsetUnnecessaryFieldsInTransaction.ts} +15 -6
- package/lib/chevre/factory/taskIdentifier.d.ts +29 -0
- package/lib/chevre/factory/taskIdentifier.js +10 -0
- package/lib/chevre/repo/action.d.ts +5 -5
- package/lib/chevre/repo/action.js +30 -29
- package/lib/chevre/repo/assetTransaction.js +10 -8
- package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +0 -25
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +2 -2
- package/lib/chevre/repo/mongoose/schemas/order.js +2 -4
- package/lib/chevre/repo/mongoose/schemas/transaction.js +2 -2
- package/lib/chevre/repo/orderInTransaction.d.ts +12 -1
- package/lib/chevre/repo/orderInTransaction.js +38 -0
- package/lib/chevre/repo/project.d.ts +1 -1
- package/lib/chevre/repo/project.js +11 -8
- package/lib/chevre/repo/seller.d.ts +9 -4
- package/lib/chevre/repo/seller.js +21 -15
- package/lib/chevre/repo/task.d.ts +12 -0
- package/lib/chevre/repo/task.js +17 -0
- package/lib/chevre/repo/transaction.d.ts +1 -1
- package/lib/chevre/repo/transaction.js +13 -17
- package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -1
- package/lib/chevre/service/assetTransaction/pay.d.ts +6 -0
- package/lib/chevre/service/assetTransaction/pay.js +4 -4
- package/lib/chevre/service/notification.d.ts +5 -1
- package/lib/chevre/service/notification.js +6 -2
- package/lib/chevre/service/offer/event/authorize.js +2 -2
- package/lib/chevre/service/offer/event/factory.d.ts +6 -2
- package/lib/chevre/service/offer/event/factory.js +45 -47
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +2 -2
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +2 -2
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +2 -1
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +34 -16
- package/lib/chevre/service/offer/eventServiceByCOA/factory.js +16 -15
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +1 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +1 -63
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +11 -11
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +3 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -9
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +6 -8
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +18 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +5 -5
- package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.d.ts +21 -0
- package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +97 -0
- package/lib/chevre/service/order/placeOrder/factory.d.ts +3 -1
- package/lib/chevre/service/order/placeOrder/factory.js +34 -5
- package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.d.ts +10 -0
- package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.js +34 -0
- package/lib/chevre/service/order/placeOrder.d.ts +1 -17
- package/lib/chevre/service/order/placeOrder.js +10 -178
- package/lib/chevre/service/order/placeOrderWithoutTransaction.d.ts +22 -0
- package/lib/chevre/service/order/placeOrderWithoutTransaction.js +60 -0
- package/lib/chevre/service/order/sendOrder.js +1 -1
- package/lib/chevre/service/order.d.ts +2 -1
- package/lib/chevre/service/order.js +2 -1
- package/lib/chevre/service/payment/any/factory.d.ts +2 -2
- package/lib/chevre/service/payment/any.js +13 -4
- package/lib/chevre/service/payment/movieTicket/authorize.d.ts +6 -0
- package/lib/chevre/service/payment/movieTicket/authorize.js +1 -1
- package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +3 -3
- package/lib/chevre/service/payment/movieTicket/validation.d.ts +9 -2
- package/lib/chevre/service/payment/movieTicket/validation.js +32 -11
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
- package/lib/chevre/service/task/returnPayTransaction.d.ts +2 -2
- package/lib/chevre/service/task/returnPayTransaction.js +77 -23
- package/lib/chevre/service/task/sendEmailMessage.d.ts +2 -2
- package/lib/chevre/service/task/sendEmailMessage.js +3 -2
- package/lib/chevre/service/task.js +2 -0
- package/lib/chevre/service/transaction/deleteTransaction.js +3 -3
- package/lib/chevre/service/transaction/placeOrderInProgress/confirm.d.ts +8 -5
- package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +43 -41
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.d.ts +1 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/result.js +50 -30
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +5 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +57 -31
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +62 -58
- package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.d.ts +3 -1
- package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +14 -27
- package/lib/chevre/service/transaction/returnOrder/preStart.js +17 -19
- package/lib/chevre/service/transaction.d.ts +13 -2
- package/lib/chevre/service/transaction.js +42 -13
- package/lib/chevre/service.d.ts +2 -0
- package/lib/chevre/service.js +2 -0
- package/lib/chevre/settings.d.ts +0 -1
- package/lib/chevre/settings.js +1 -2
- package/package.json +3 -3
- package/example/src/chevre/investigateCheckMovieTicketActions.ts +0 -60
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
// tslint:disable-next-line:max-func-body-length
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const assetTransactionRepo = await chevre.repository.AssetTransaction.createInstance(mongoose.connection);
|
|
12
|
+
const cursor = assetTransactionRepo.getCursor(
|
|
13
|
+
{
|
|
14
|
+
// typeOf: { $eq: chevre.factory.assetTransactionType.Pay },
|
|
15
|
+
status: { $eq: chevre.factory.transactionStatusType.Confirmed },
|
|
16
|
+
startDate: {
|
|
17
|
+
// $lte: moment()
|
|
18
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
19
|
+
// .add(-28, 'days'),
|
|
20
|
+
$gte: moment()
|
|
21
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
22
|
+
.add(-180, 'days')
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
console.log('transactions found');
|
|
29
|
+
|
|
30
|
+
let i = 0;
|
|
31
|
+
// tslint:disable-next-line:max-func-body-length
|
|
32
|
+
await cursor.eachAsync(async (doc) => {
|
|
33
|
+
i += 1;
|
|
34
|
+
const reserveTransaction = <chevre.factory.assetTransaction.reserve.ITransaction>doc.toObject();
|
|
35
|
+
console.log(
|
|
36
|
+
'size:', JSON.stringify(reserveTransaction).length,
|
|
37
|
+
reserveTransaction.typeOf, reserveTransaction.project.id, reserveTransaction.transactionNumber,
|
|
38
|
+
reserveTransaction.startDate, i);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
console.log(i, 'transactions checked');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
main()
|
|
45
|
+
.then()
|
|
46
|
+
.catch(console.error);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const orderInTransactionRepo = await chevre.repository.OrderInTransaction.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const customer = await orderInTransactionRepo.findCustomerByOrderNumber({
|
|
12
|
+
orderNumber: { $eq: 'SSK3-0708814-6653130' }
|
|
13
|
+
});
|
|
14
|
+
console.log(customer);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main()
|
|
18
|
+
.then(console.log)
|
|
19
|
+
.catch(console.error);
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
const MOVIE_TICKET_IDENTIFIER_REGEX = '^[0-9a-zA-Z*]+$';
|
|
10
|
+
// const MOVIE_TICKET_IDENTIFIER_REGEX = '^.+$';
|
|
11
|
+
|
|
12
|
+
// tslint:disable-next-line:max-func-body-length
|
|
13
|
+
async function main() {
|
|
14
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
15
|
+
|
|
16
|
+
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
17
|
+
|
|
18
|
+
const cursor = actionRepo.getCursor(
|
|
19
|
+
{
|
|
20
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
21
|
+
'object.typeOf': { $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
|
|
22
|
+
startDate: {
|
|
23
|
+
$gte: moment()
|
|
24
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
25
|
+
.add(-30, 'days')
|
|
26
|
+
.toDate()
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
project: 1,
|
|
31
|
+
typeOf: 1,
|
|
32
|
+
startDate: 1,
|
|
33
|
+
object: 1,
|
|
34
|
+
result: 1
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
console.log('actions found');
|
|
38
|
+
|
|
39
|
+
let i = 0;
|
|
40
|
+
await cursor.eachAsync(async (doc) => {
|
|
41
|
+
i += 1;
|
|
42
|
+
const action: Pick<
|
|
43
|
+
chevre.factory.action.authorize.paymentMethod.any.IAction,
|
|
44
|
+
'project' | 'typeOf' | 'startDate' | 'object' | 'result'
|
|
45
|
+
> = doc.toObject();
|
|
46
|
+
|
|
47
|
+
const accountId = (Array.isArray(action.result)) ? action.result[0].accountId : action.result?.accountId;
|
|
48
|
+
const issuedThroughTypeOf = (Array.isArray(action.result))
|
|
49
|
+
? action.result[0].issuedThrough.typeOf
|
|
50
|
+
: action.result?.issuedThrough.typeOf;
|
|
51
|
+
if (issuedThroughTypeOf === chevre.factory.service.paymentService.PaymentServiceType.MovieTicket) {
|
|
52
|
+
const regExp = new RegExp(MOVIE_TICKET_IDENTIFIER_REGEX);
|
|
53
|
+
console.log(
|
|
54
|
+
'checking...',
|
|
55
|
+
accountId,
|
|
56
|
+
action.project.id, action.startDate, i
|
|
57
|
+
);
|
|
58
|
+
if (typeof accountId !== 'string') {
|
|
59
|
+
throw new Error(`${accountId} must be string`);
|
|
60
|
+
}
|
|
61
|
+
if (!accountId.match(regExp)) {
|
|
62
|
+
throw new Error(`${accountId} invalid`);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// console.log(
|
|
66
|
+
// 'no check',
|
|
67
|
+
// issuedThroughTypeOf,
|
|
68
|
+
// action.project.id, action.startDate, i
|
|
69
|
+
// );
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
console.log(i, 'actions checked');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main()
|
|
77
|
+
.then()
|
|
78
|
+
.catch(console.error);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
11
|
+
const cursor = actionRepo.getCursor(
|
|
12
|
+
{
|
|
13
|
+
// _id: { $eq: '66697991037c9d7243208261' },
|
|
14
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
15
|
+
// actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
|
|
16
|
+
// startDate: {
|
|
17
|
+
// $lte: moment()
|
|
18
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
19
|
+
// .add(-180, 'days'),
|
|
20
|
+
// $gte: moment()
|
|
21
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
22
|
+
// .add(-180, 'days')
|
|
23
|
+
// },
|
|
24
|
+
'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.offer.eventService.ObjectType.SeatReservation },
|
|
25
|
+
'instrument.typeOf': { $exists: true, $eq: chevre.factory.assetTransactionType.COAReserveTransaction }
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
__id: 1, startDate: 1, project: 1, typeOf: 1, actionStatus: 1, instrument: 1, object: 1
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
console.log('actions found');
|
|
32
|
+
|
|
33
|
+
let i = 0;
|
|
34
|
+
let updateCount = 0;
|
|
35
|
+
const saveResultCount = 0;
|
|
36
|
+
// tslint:disable-next-line:max-func-body-length
|
|
37
|
+
await cursor.eachAsync(async (doc) => {
|
|
38
|
+
i += 1;
|
|
39
|
+
const authorizeAction = <Pick<
|
|
40
|
+
chevre.factory.action.authorize.offer.eventService.IAction<chevre.factory.service.webAPI.Identifier>,
|
|
41
|
+
'id' | 'startDate' | 'project' | 'typeOf' | 'actionStatus' | 'instrument' | 'object'
|
|
42
|
+
>>doc.toObject();
|
|
43
|
+
|
|
44
|
+
let migrated = false;
|
|
45
|
+
if (authorizeAction.instrument.typeOf === chevre.factory.assetTransactionType.Reserve) {
|
|
46
|
+
migrated = true;
|
|
47
|
+
} else {
|
|
48
|
+
const acceptedOffers = (<any>authorizeAction.object).acceptedOffer;
|
|
49
|
+
if (acceptedOffers === undefined) {
|
|
50
|
+
migrated = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (migrated) {
|
|
55
|
+
console.log(
|
|
56
|
+
'already migrated.',
|
|
57
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.actionStatus, authorizeAction.startDate,
|
|
58
|
+
i, updateCount, saveResultCount);
|
|
59
|
+
|
|
60
|
+
} else {
|
|
61
|
+
// optimize action
|
|
62
|
+
let unsetResult: any;
|
|
63
|
+
unsetResult = await actionRepo.unsetUnnecessaryFields({
|
|
64
|
+
filter: { _id: { $eq: authorizeAction.id } },
|
|
65
|
+
$unset: {
|
|
66
|
+
'object.acceptedOffer': 1
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
updateCount += 1;
|
|
70
|
+
console.log(
|
|
71
|
+
'result unset. unsetResult:', unsetResult,
|
|
72
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.actionStatus, authorizeAction.startDate, i,
|
|
73
|
+
updateCount, saveResultCount);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(i, 'actions checked');
|
|
78
|
+
console.log(updateCount, 'actions updated');
|
|
79
|
+
console.log(saveResultCount, 'result saved');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main()
|
|
83
|
+
.then()
|
|
84
|
+
.catch(console.error);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
11
|
+
const cursor = actionRepo.getCursor(
|
|
12
|
+
{
|
|
13
|
+
// _id: { $eq: '666bf2f1903cf9f62b41ca6e' },
|
|
14
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
15
|
+
// actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
|
|
16
|
+
// startDate: {
|
|
17
|
+
// $lte: moment()
|
|
18
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
19
|
+
// .add(-180, 'days'),
|
|
20
|
+
// $gte: moment()
|
|
21
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
22
|
+
// .add(-180, 'days')
|
|
23
|
+
// },
|
|
24
|
+
'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.offer.eventService.ObjectType.SeatReservation },
|
|
25
|
+
'instrument.typeOf': { $exists: true, $eq: chevre.factory.assetTransactionType.Reserve }
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
__id: 1, startDate: 1, project: 1, typeOf: 1, actionStatus: 1, instrument: 1, object: 1
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
console.log('actions found');
|
|
32
|
+
|
|
33
|
+
let i = 0;
|
|
34
|
+
let updateCount = 0;
|
|
35
|
+
const saveResultCount = 0;
|
|
36
|
+
// tslint:disable-next-line:max-func-body-length
|
|
37
|
+
await cursor.eachAsync(async (doc) => {
|
|
38
|
+
i += 1;
|
|
39
|
+
const authorizeAction = <Pick<
|
|
40
|
+
chevre.factory.action.authorize.offer.eventService.IAction<chevre.factory.service.webAPI.Identifier>,
|
|
41
|
+
'id' | 'startDate' | 'project' | 'typeOf' | 'actionStatus' | 'instrument' | 'object'
|
|
42
|
+
>>doc.toObject();
|
|
43
|
+
|
|
44
|
+
let migrated = false;
|
|
45
|
+
if (authorizeAction.instrument.typeOf === chevre.factory.assetTransactionType.COAReserveTransaction) {
|
|
46
|
+
migrated = true;
|
|
47
|
+
} else {
|
|
48
|
+
const pendingTransaction = authorizeAction.object.pendingTransaction;
|
|
49
|
+
if (pendingTransaction === undefined) {
|
|
50
|
+
migrated = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (migrated) {
|
|
55
|
+
console.log(
|
|
56
|
+
'already migrated.',
|
|
57
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.actionStatus, authorizeAction.startDate,
|
|
58
|
+
i, updateCount, saveResultCount);
|
|
59
|
+
|
|
60
|
+
} else {
|
|
61
|
+
// optimize action
|
|
62
|
+
let unsetResult: any;
|
|
63
|
+
unsetResult = await actionRepo.unsetUnnecessaryFields({
|
|
64
|
+
filter: { _id: { $eq: authorizeAction.id } },
|
|
65
|
+
$unset: {
|
|
66
|
+
'object.pendingTransaction': 1
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
updateCount += 1;
|
|
70
|
+
console.log(
|
|
71
|
+
'result unset. unsetResult:', unsetResult,
|
|
72
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.actionStatus, authorizeAction.startDate, i,
|
|
73
|
+
updateCount, saveResultCount);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(i, 'actions checked');
|
|
78
|
+
console.log(updateCount, 'actions updated');
|
|
79
|
+
console.log(saveResultCount, 'result saved');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main()
|
|
83
|
+
.then()
|
|
84
|
+
.catch(console.error);
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
type IInstrumentAsAssetTransaction =
|
|
8
|
+
chevre.factory.action.authorize.offer.eventService.IInstrumentAsAssetTransaction<chevre.factory.service.webAPI.Identifier>;
|
|
9
|
+
|
|
10
|
+
// tslint:disable-next-line:max-func-body-length
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
15
|
+
const cursor = actionRepo.getCursor(
|
|
16
|
+
{
|
|
17
|
+
// _id: { $eq: '65eb218c1fb66e469cb2ba7e' },
|
|
18
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
19
|
+
// actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
|
|
20
|
+
startDate: {
|
|
21
|
+
// $lte: moment()
|
|
22
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
23
|
+
// .add(-90, 'days'),
|
|
24
|
+
$lte: moment('2023-07-22T01:17:42.541Z')
|
|
25
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
26
|
+
.toDate()
|
|
27
|
+
// $gte: moment()
|
|
28
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
29
|
+
// .add(-180, 'days')
|
|
30
|
+
},
|
|
31
|
+
'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.offer.eventService.ObjectType.SeatReservation },
|
|
32
|
+
'project.id': { $ne: 'sskts-production' }
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
__id: 1, startDate: 1, endDate: 1, result: 1, project: 1, typeOf: 1, actionStatus: 1, instrument: 1, object: 1
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
console.log('actions found');
|
|
39
|
+
|
|
40
|
+
let i = 0;
|
|
41
|
+
let updateCount = 0;
|
|
42
|
+
let saveResultCount = 0;
|
|
43
|
+
// tslint:disable-next-line:max-func-body-length
|
|
44
|
+
await cursor.eachAsync(async (doc) => {
|
|
45
|
+
i += 1;
|
|
46
|
+
const authorizeAction = <Pick<
|
|
47
|
+
chevre.factory.action.authorize.offer.eventService.IAction<chevre.factory.service.webAPI.Identifier>,
|
|
48
|
+
'id' | 'startDate' | 'endDate' | 'result' | 'project' | 'typeOf' | 'actionStatus' | 'instrument' | 'object'
|
|
49
|
+
>>doc.toObject();
|
|
50
|
+
const { instrument } = authorizeAction;
|
|
51
|
+
|
|
52
|
+
let migrated = false;
|
|
53
|
+
if ((instrument.typeOf === chevre.factory.assetTransactionType.COAReserveTransaction
|
|
54
|
+
|| instrument.typeOf === chevre.factory.assetTransactionType.Reserve)
|
|
55
|
+
&& typeof instrument.transactionNumber === 'string'
|
|
56
|
+
) {
|
|
57
|
+
migrated = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (migrated) {
|
|
61
|
+
console.log(
|
|
62
|
+
'already migrated.',
|
|
63
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
64
|
+
} else {
|
|
65
|
+
console.log(
|
|
66
|
+
'redefining instrument as AssetTransaction...',
|
|
67
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
68
|
+
if ((<any>instrument).typeOf !== 'WebAPI') {
|
|
69
|
+
throw new Error(`instrument.typeOf must be WebAPI [${authorizeAction.id}]`);
|
|
70
|
+
}
|
|
71
|
+
const pendingTransaction = (authorizeAction.object).pendingTransaction;
|
|
72
|
+
const transactionNumber = pendingTransaction?.transactionNumber;
|
|
73
|
+
let newInstrument: IInstrumentAsAssetTransaction;
|
|
74
|
+
if (pendingTransaction?.typeOf === chevre.factory.assetTransactionType.COAReserveTransaction) {
|
|
75
|
+
newInstrument = {
|
|
76
|
+
typeOf: chevre.factory.assetTransactionType.COAReserveTransaction,
|
|
77
|
+
identifier: chevre.factory.service.webAPI.Identifier.COA,
|
|
78
|
+
...(typeof transactionNumber === 'string') ? { transactionNumber } : { transactionNumber: '' }
|
|
79
|
+
};
|
|
80
|
+
} else if (pendingTransaction?.typeOf === chevre.factory.assetTransactionType.Reserve) {
|
|
81
|
+
if (typeof transactionNumber !== 'string' || transactionNumber === '') {
|
|
82
|
+
throw new Error(`pendingTransaction must exist [${authorizeAction.id}]`);
|
|
83
|
+
}
|
|
84
|
+
newInstrument = {
|
|
85
|
+
typeOf: chevre.factory.assetTransactionType.Reserve,
|
|
86
|
+
identifier: chevre.factory.service.webAPI.Identifier.Chevre,
|
|
87
|
+
transactionNumber
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
if (instrument.identifier === chevre.factory.service.webAPI.Identifier.COA) {
|
|
91
|
+
newInstrument = {
|
|
92
|
+
typeOf: chevre.factory.assetTransactionType.COAReserveTransaction,
|
|
93
|
+
identifier: chevre.factory.service.webAPI.Identifier.COA,
|
|
94
|
+
...(typeof transactionNumber === 'string') ? { transactionNumber } : { transactionNumber: '' }
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error(`invalid pendingTransaction [${(<any>pendingTransaction)?.typeOf}] [${authorizeAction.id}]`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
console.log(
|
|
102
|
+
'saving action...',
|
|
103
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
104
|
+
// tslint:disable-next-line:no-null-keyword
|
|
105
|
+
console.dir({ instrument, newInstrument }, { depth: null });
|
|
106
|
+
await actionRepo.findByIdAndUpdate({
|
|
107
|
+
id: authorizeAction.id,
|
|
108
|
+
update: {
|
|
109
|
+
$set: {
|
|
110
|
+
instrument: newInstrument
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
saveResultCount += 1;
|
|
115
|
+
console.log(
|
|
116
|
+
'action saved.',
|
|
117
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
console.log(i, 'actions checked');
|
|
122
|
+
console.log(updateCount, 'actions updated');
|
|
123
|
+
console.log(saveResultCount, 'result saved');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
main()
|
|
127
|
+
.then()
|
|
128
|
+
.catch(console.error);
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
type IUnitPriceSpecification =
|
|
8
|
+
chevre.factory.priceSpecification.IPriceSpecification<chevre.factory.priceSpecificationType.UnitPriceSpecification>;
|
|
9
|
+
type IAuthorizeAction4chevre = chevre.factory.action.authorize.offer.eventService.IAction<chevre.factory.service.webAPI.Identifier.Chevre>;
|
|
10
|
+
type IAcceptedOffer4chevre = chevre.factory.action.authorize.offer.eventService.IAcceptedOffer4chevre;
|
|
11
|
+
|
|
12
|
+
// tslint:disable-next-line:max-func-body-length
|
|
13
|
+
async function main() {
|
|
14
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
15
|
+
|
|
16
|
+
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
17
|
+
const cursor = actionRepo.getCursor(
|
|
18
|
+
{
|
|
19
|
+
// _id: { $eq: '66697991037c9d7243208261' },
|
|
20
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
21
|
+
actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
|
|
22
|
+
startDate: {
|
|
23
|
+
$lte: moment()
|
|
24
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
25
|
+
.add(-180, 'days')
|
|
26
|
+
// $gte: moment()
|
|
27
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
28
|
+
// .add(-180, 'days')
|
|
29
|
+
},
|
|
30
|
+
'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.offer.eventService.ObjectType.SeatReservation }
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
__id: 1, startDate: 1, endDate: 1, result: 1, project: 1, typeOf: 1, actionStatus: 1, instrument: 1, object: 1
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
console.log('actions found');
|
|
37
|
+
|
|
38
|
+
let i = 0;
|
|
39
|
+
let updateCount = 0;
|
|
40
|
+
let saveResultCount = 0;
|
|
41
|
+
// tslint:disable-next-line:max-func-body-length
|
|
42
|
+
await cursor.eachAsync(async (doc) => {
|
|
43
|
+
i += 1;
|
|
44
|
+
const authorizeAction = <Pick<
|
|
45
|
+
chevre.factory.action.authorize.offer.eventService.IAction<chevre.factory.service.webAPI.Identifier>,
|
|
46
|
+
'id' | 'startDate' | 'endDate' | 'result' | 'project' | 'typeOf' | 'actionStatus' | 'instrument' | 'object'
|
|
47
|
+
>>doc.toObject();
|
|
48
|
+
const result = authorizeAction.result;
|
|
49
|
+
if (result === undefined) {
|
|
50
|
+
throw new Error(`result undefined [${authorizeAction.id}]`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let migrated = false;
|
|
54
|
+
if (authorizeAction.instrument.typeOf === chevre.factory.assetTransactionType.COAReserveTransaction
|
|
55
|
+
|| (<any>authorizeAction.instrument).identifier === chevre.factory.service.webAPI.Identifier.COA) {
|
|
56
|
+
migrated = true;
|
|
57
|
+
} else {
|
|
58
|
+
if (result.typeOf === chevre.factory.offerType.AggregateOffer && Array.isArray(result.offers)) {
|
|
59
|
+
migrated = true;
|
|
60
|
+
}
|
|
61
|
+
if (typeof result.price !== 'number') {
|
|
62
|
+
migrated = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (migrated) {
|
|
67
|
+
console.log(
|
|
68
|
+
'already migrated.',
|
|
69
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
70
|
+
|
|
71
|
+
// optimize action
|
|
72
|
+
if (Array.isArray((<any>authorizeAction.object).acceptedOffer)) {
|
|
73
|
+
let unsetResult: any;
|
|
74
|
+
unsetResult = await actionRepo.unsetUnnecessaryFields({
|
|
75
|
+
filter: { _id: { $eq: authorizeAction.id } },
|
|
76
|
+
$unset: {
|
|
77
|
+
'object.acceptedOffer': 1
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
updateCount += 1;
|
|
81
|
+
console.log(
|
|
82
|
+
'result unset. unsetResult:', unsetResult,
|
|
83
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
console.log(
|
|
87
|
+
'redefining result as AggreagteOffer...',
|
|
88
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
89
|
+
const acceptedOffers = <IAcceptedOffer4chevre[]>(<any>(<IAuthorizeAction4chevre>authorizeAction).object).acceptedOffer;
|
|
90
|
+
if (!Array.isArray(acceptedOffers)) {
|
|
91
|
+
throw new Error(`acceptedOffer undefined [${authorizeAction.id}]`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let offers: chevre.factory.action.authorize.offer.eventService.IAcceptedOfferInResult[] | undefined;
|
|
95
|
+
if (typeof result.price === 'number') {
|
|
96
|
+
// オファーIDごとに集計
|
|
97
|
+
const offerIds = [...new Set(acceptedOffers.map((o) => o.id))];
|
|
98
|
+
offers = offerIds.map<chevre.factory.action.authorize.offer.eventService.IAcceptedOfferInResult>((offerId) => {
|
|
99
|
+
const acceptedOfferInObject = acceptedOffers.find(({ id }) => id === offerId);
|
|
100
|
+
if (acceptedOfferInObject === undefined) {
|
|
101
|
+
throw new Error(`acceptedOffer not found [id:${offerId}]`);
|
|
102
|
+
}
|
|
103
|
+
const amountOfThisGood: number = acceptedOffers.filter(({ id }) => id === offerId).length;
|
|
104
|
+
const { acceptedPaymentMethod, priceSpecification } = acceptedOfferInObject;
|
|
105
|
+
|
|
106
|
+
const unitPriceSpec = <IUnitPriceSpecification | undefined>priceSpecification.priceComponent.find(
|
|
107
|
+
(spec) => spec.typeOf === chevre.factory.priceSpecificationType.UnitPriceSpecification
|
|
108
|
+
&& (!Array.isArray(spec.appliesToAddOn)) // アドオン単価ではない
|
|
109
|
+
);
|
|
110
|
+
if (unitPriceSpec === undefined) {
|
|
111
|
+
throw new Error(`unitPriceSpec not found [id:${offerId}]`);
|
|
112
|
+
}
|
|
113
|
+
const { eligibleQuantity, eligibleTransactionVolume } = unitPriceSpec;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
id: offerId,
|
|
117
|
+
includesObject: { amountOfThisGood },
|
|
118
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
119
|
+
priceSpecification: {
|
|
120
|
+
...(eligibleQuantity !== undefined) ? { eligibleQuantity } : undefined,
|
|
121
|
+
...(eligibleTransactionVolume !== undefined) ? { eligibleTransactionVolume } : undefined
|
|
122
|
+
},
|
|
123
|
+
...(acceptedPaymentMethod !== undefined) ? { acceptedPaymentMethod } : undefined
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const resultAsAggregateOffer: chevre.factory.action.authorize.offer.eventService.IResultAsAggregateOffer = {
|
|
128
|
+
typeOf: chevre.factory.offerType.AggregateOffer,
|
|
129
|
+
offers
|
|
130
|
+
};
|
|
131
|
+
// const newResult: chevre.factory.action.authorize.offer.eventService.IResult = {
|
|
132
|
+
// ...result,
|
|
133
|
+
// ...resultAsAggregateOffer
|
|
134
|
+
// };
|
|
135
|
+
console.log(
|
|
136
|
+
'saving action...',
|
|
137
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
138
|
+
// tslint:disable-next-line:no-null-keyword
|
|
139
|
+
console.dir(resultAsAggregateOffer, { depth: null });
|
|
140
|
+
await actionRepo.findByIdAndUpdate({
|
|
141
|
+
id: authorizeAction.id,
|
|
142
|
+
update: {
|
|
143
|
+
$set: {
|
|
144
|
+
'result.typeOf': resultAsAggregateOffer.typeOf,
|
|
145
|
+
'result.offers': resultAsAggregateOffer.offers
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
saveResultCount += 1;
|
|
150
|
+
console.log(
|
|
151
|
+
'action saved.',
|
|
152
|
+
authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
console.log(i, 'actions checked');
|
|
157
|
+
console.log(updateCount, 'actions updated');
|
|
158
|
+
console.log(saveResultCount, 'result saved');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
main()
|
|
162
|
+
.then()
|
|
163
|
+
.catch(console.error);
|
|
@@ -0,0 +1,55 @@
|
|
|
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 DAYS = 500;
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const now = new Date();
|
|
12
|
+
let updateResult: any;
|
|
13
|
+
|
|
14
|
+
const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
17
|
+
const hours = DAYS * 24;
|
|
18
|
+
// tslint:disable-next-line:no-increment-decrement no-magic-numbers
|
|
19
|
+
for (let index = 0; index < hours; index++) {
|
|
20
|
+
updateResult = await actionRepo.unsetUnnecessaryFields({
|
|
21
|
+
filter: {
|
|
22
|
+
// _id: { $eq: '667379e7be9a532411c29424' },
|
|
23
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
24
|
+
'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
|
|
25
|
+
startDate: {
|
|
26
|
+
$gte: moment(now)
|
|
27
|
+
.add(-(index + 1), 'hours')
|
|
28
|
+
.toDate(),
|
|
29
|
+
$lt: moment(now)
|
|
30
|
+
.add(-index, 'hours')
|
|
31
|
+
.toDate()
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
$unset: {
|
|
35
|
+
'object.paymentMethod': 1,
|
|
36
|
+
'object.additionalProperty': 1,
|
|
37
|
+
'object.amount': 1,
|
|
38
|
+
'object.issuedThrough': 1,
|
|
39
|
+
'object.description': 1,
|
|
40
|
+
'object.name': 1,
|
|
41
|
+
'object.fromLocation': 1,
|
|
42
|
+
'object.method': 1,
|
|
43
|
+
'object.creditCard': 1,
|
|
44
|
+
'object.movieTickets': 1
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
console.log('unset processed.', updateResult, -(index + 1), 'hours', -index, 'hours');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log(DAYS, 'days processed');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
main()
|
|
54
|
+
.then()
|
|
55
|
+
.catch(console.error);
|