@chevre/domain 21.7.0-alpha.6 → 21.7.0-alpha.8
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/migrateAuthorizePaymentActionResult.ts +83 -0
- package/lib/chevre/repo/action.d.ts +4 -0
- package/lib/chevre/repo/action.js +6 -0
- package/lib/chevre/service/payment/any/factory.js +12 -21
- package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +0 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/result.js +7 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +6 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +5 -19
- package/lib/chevre/service/transaction/placeOrderInProgress.js +0 -1
- package/package.json +2 -2
- package/example/src/chevre/migrateReservationProvider.ts +0 -119
|
@@ -0,0 +1,83 @@
|
|
|
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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
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 = new chevre.repository.Action(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = actionRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
|
|
19
|
+
actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
|
|
20
|
+
'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
|
|
21
|
+
'result.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
|
|
22
|
+
startDate: {
|
|
23
|
+
$gte: moment('2023-05-01T00:00:00Z')
|
|
24
|
+
.toDate(),
|
|
25
|
+
$lte: moment('2023-08-01T00:00:00Z')
|
|
26
|
+
.toDate()
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
_id: 1,
|
|
31
|
+
typeOf: 1,
|
|
32
|
+
result: 1,
|
|
33
|
+
project: 1,
|
|
34
|
+
startDate: 1,
|
|
35
|
+
actionStatus: 1
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
console.log('actions found');
|
|
39
|
+
|
|
40
|
+
let i = 0;
|
|
41
|
+
let updateCount = 0;
|
|
42
|
+
await cursor.eachAsync(async (doc) => {
|
|
43
|
+
i += 1;
|
|
44
|
+
const action: Pick<
|
|
45
|
+
chevre.factory.action.authorize.paymentMethod.any.IAction,
|
|
46
|
+
'id' | 'project' | 'result' | 'typeOf' | 'startDate' | 'actionStatus'
|
|
47
|
+
> = doc.toObject();
|
|
48
|
+
|
|
49
|
+
const oldPaymentMethodType = action.result?.paymentMethod;
|
|
50
|
+
const paymentMethodType = action.result?.paymentMethodAsObject?.typeOf;
|
|
51
|
+
const alreadyMigrated = typeof paymentMethodType === 'string' && oldPaymentMethodType === paymentMethodType;
|
|
52
|
+
|
|
53
|
+
if (alreadyMigrated) {
|
|
54
|
+
console.log('already exist...', action.project.id, action.id, action.startDate, paymentMethodType, i);
|
|
55
|
+
} else {
|
|
56
|
+
if (typeof oldPaymentMethodType !== 'string') {
|
|
57
|
+
console.error('updating action...', action.project.id, action.id, action.startDate, oldPaymentMethodType, i, updateCount);
|
|
58
|
+
throw new Error('oldPaymentMethodType undefined');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const newPaymentMethodAsObject: chevre.factory.action.authorize.paymentMethod.any.IResultPaymentMethod = {
|
|
62
|
+
typeOf: oldPaymentMethodType
|
|
63
|
+
};
|
|
64
|
+
console.log(
|
|
65
|
+
'updating action...', action.project.id, action.id, action.startDate, newPaymentMethodAsObject.typeOf, i, updateCount);
|
|
66
|
+
await actionRepo.updateById({
|
|
67
|
+
id: action.id,
|
|
68
|
+
update: {
|
|
69
|
+
'result.paymentMethodAsObject': newPaymentMethodAsObject
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
updateCount += 1;
|
|
73
|
+
console.log('updated.', action.project.id, action.id, action.startDate, newPaymentMethodAsObject.typeOf, i, updateCount);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(i, 'actions checked');
|
|
78
|
+
console.log(updateCount, 'actions updated');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
main()
|
|
82
|
+
.then()
|
|
83
|
+
.catch(console.error);
|
|
@@ -150,6 +150,10 @@ export declare class MongoRepository {
|
|
|
150
150
|
object: factory.action.authorize.offer.seatReservation.IObject<T>;
|
|
151
151
|
result: factory.action.authorize.offer.seatReservation.IResult<T>;
|
|
152
152
|
}): Promise<factory.action.authorize.offer.seatReservation.IAction<T>>;
|
|
153
|
+
updateById(params: {
|
|
154
|
+
id: string;
|
|
155
|
+
update: any;
|
|
156
|
+
}): Promise<void>;
|
|
153
157
|
findByIdAndUpdate<T extends factory.actionType>(params: {
|
|
154
158
|
id: string;
|
|
155
159
|
update: any;
|
|
@@ -643,6 +643,12 @@ class MongoRepository {
|
|
|
643
643
|
});
|
|
644
644
|
});
|
|
645
645
|
}
|
|
646
|
+
updateById(params) {
|
|
647
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
648
|
+
yield this.actionModel.updateOne({ _id: { $eq: params.id } }, params.update)
|
|
649
|
+
.exec();
|
|
650
|
+
});
|
|
651
|
+
}
|
|
646
652
|
findByIdAndUpdate(params) {
|
|
647
653
|
return __awaiter(this, void 0, void 0, function* () {
|
|
648
654
|
return this.actionModel.findOneAndUpdate({ _id: params.id }, params.update, { new: true })
|
|
@@ -80,7 +80,7 @@ function createMovieTicket(params) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
function createAuthorizeResult(params) {
|
|
83
|
-
var _a, _b, _c, _d;
|
|
83
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
84
84
|
const payTransactionObject = params.payTransaction.object;
|
|
85
85
|
const totalPaymentDue = (_a = payTransactionObject.paymentMethod) === null || _a === void 0 ? void 0 : _a.totalPaymentDue;
|
|
86
86
|
if (typeof (totalPaymentDue === null || totalPaymentDue === void 0 ? void 0 : totalPaymentDue.typeOf) !== 'string') {
|
|
@@ -89,26 +89,17 @@ function createAuthorizeResult(params) {
|
|
|
89
89
|
const issuedThrough = {
|
|
90
90
|
typeOf: payTransactionObject.typeOf,
|
|
91
91
|
id: (typeof payTransactionObject.id === 'string') ? payTransactionObject.id : ''
|
|
92
|
-
// CreditCardIFのカード通貨区分を追加(2023-08-07~)
|
|
93
|
-
// ...(typeof payTransactionObject.paymentMethod?.amount !== 'number'
|
|
94
|
-
// && typeof payTransactionObject.paymentMethod?.amount?.currency === 'string')
|
|
95
|
-
// ? {
|
|
96
|
-
// serviceOutput: {
|
|
97
|
-
// paymentMethod: {
|
|
98
|
-
// amount: {
|
|
99
|
-
// currency: payTransactionObject.paymentMethod.amount.currency,
|
|
100
|
-
// value: payTransactionObject.paymentMethod.amount.value
|
|
101
|
-
// }
|
|
102
|
-
// }
|
|
103
|
-
// }
|
|
104
|
-
// }
|
|
105
|
-
// : undefined
|
|
106
|
-
};
|
|
107
|
-
const paymentMethodAsObject = {
|
|
108
|
-
typeOf: params.object.paymentMethod
|
|
109
92
|
};
|
|
93
|
+
// 決済取引から決済カード通貨区分を取り出す
|
|
94
|
+
const paymentMethodAmountCurrencyByPayTransaction = (typeof ((_b = payTransactionObject.paymentMethod) === null || _b === void 0 ? void 0 : _b.amount) !== 'number')
|
|
95
|
+
? (_d = (_c = payTransactionObject.paymentMethod) === null || _c === void 0 ? void 0 : _c.amount) === null || _d === void 0 ? void 0 : _d.currency
|
|
96
|
+
: undefined;
|
|
97
|
+
const paymentMethodAsObject = Object.assign({ typeOf: params.object.paymentMethod }, (payTransactionObject.typeOf === factory.service.paymentService.PaymentServiceType.CreditCard
|
|
98
|
+
&& typeof paymentMethodAmountCurrencyByPayTransaction === 'string')
|
|
99
|
+
? { amount: { currency: paymentMethodAmountCurrencyByPayTransaction } }
|
|
100
|
+
: undefined);
|
|
110
101
|
return {
|
|
111
|
-
accountId: (typeof ((
|
|
102
|
+
accountId: (typeof ((_e = payTransactionObject.paymentMethod) === null || _e === void 0 ? void 0 : _e.accountId) === 'string')
|
|
112
103
|
? payTransactionObject.paymentMethod.accountId
|
|
113
104
|
: '',
|
|
114
105
|
// 廃止(2023-08-07~)
|
|
@@ -117,10 +108,10 @@ function createAuthorizeResult(params) {
|
|
|
117
108
|
paymentMethod: params.object.paymentMethod,
|
|
118
109
|
paymentMethodAsObject,
|
|
119
110
|
paymentStatus: factory.paymentStatusType.PaymentDue,
|
|
120
|
-
paymentMethodId: (typeof ((
|
|
111
|
+
paymentMethodId: (typeof ((_f = payTransactionObject.paymentMethod) === null || _f === void 0 ? void 0 : _f.paymentMethodId) === 'string')
|
|
121
112
|
? payTransactionObject.paymentMethod.paymentMethodId
|
|
122
113
|
: '',
|
|
123
|
-
name: (typeof ((
|
|
114
|
+
name: (typeof ((_g = payTransactionObject.paymentMethod) === null || _g === void 0 ? void 0 : _g.name) === 'string')
|
|
124
115
|
? payTransactionObject.paymentMethod.name
|
|
125
116
|
: params.object.paymentMethod,
|
|
126
117
|
totalPaymentDue: totalPaymentDue,
|
|
@@ -117,10 +117,6 @@ function createProductItems(params) {
|
|
|
117
117
|
exports.createProductItems = createProductItems;
|
|
118
118
|
function createMoneyTransferAcceptedOffers(params) {
|
|
119
119
|
// 通貨転送承認アクション
|
|
120
|
-
// const authorizeMoneyTansferActions = (<IAuthorizeMoneyTransferOffer[]>params.transaction.object.authorizeActions)
|
|
121
|
-
// .filter((a) => a.actionStatus === factory.actionStatusType.CompletedActionStatus)
|
|
122
|
-
// .filter((a) => a.object.typeOf === factory.offerType.Offer)
|
|
123
|
-
// .filter((a) => a.object.itemOffered?.typeOf === factory.actionType.MoneyTransfer);
|
|
124
120
|
const authorizeMoneyTansferActions = params.authorizeActions
|
|
125
121
|
.filter((a) => a.actionStatus === factory.actionStatusType.CompletedActionStatus)
|
|
126
122
|
.filter((a) => a.object.typeOf === factory.offerType.Offer)
|
|
@@ -70,13 +70,18 @@ function createPaymentMethods(params) {
|
|
|
70
70
|
});
|
|
71
71
|
// 決済方法をセット
|
|
72
72
|
authorizePaymentActions.forEach((a) => {
|
|
73
|
-
var _a, _b;
|
|
73
|
+
var _a, _b, _c;
|
|
74
74
|
const result = a.result;
|
|
75
75
|
const paymentMethodAmountCurrencyByAuthorizeAction = (_b = (_a = result.paymentMethodAsObject) === null || _a === void 0 ? void 0 : _a.amount) === null || _b === void 0 ? void 0 : _b.currency;
|
|
76
76
|
const paymentMethodOfInvoice = (typeof paymentMethodAmountCurrencyByAuthorizeAction === 'string') ?
|
|
77
77
|
{ amount: { currency: paymentMethodAmountCurrencyByAuthorizeAction } }
|
|
78
78
|
: undefined;
|
|
79
|
-
|
|
79
|
+
// 決済方法区分は必ず存在するはず(2023-08-15~)
|
|
80
|
+
const paymentMethodType = (_c = result.paymentMethodAsObject) === null || _c === void 0 ? void 0 : _c.typeOf;
|
|
81
|
+
if (typeof paymentMethodType !== 'string') {
|
|
82
|
+
throw new factory.errors.NotFound('authorizePaymentAction.result.paymentMethodAsObject.typeOf');
|
|
83
|
+
}
|
|
84
|
+
paymentMethods.push(Object.assign({ accountId: result.accountId, additionalProperty: (Array.isArray(result.additionalProperty)) ? result.additionalProperty : [], issuedThrough: result.issuedThrough, name: result.name, paymentMethodId: result.paymentMethodId, totalPaymentDue: result.totalPaymentDue, typeOf: paymentMethodType }, (paymentMethodOfInvoice !== undefined) ? { paymentMethod: paymentMethodOfInvoice } : undefined));
|
|
80
85
|
});
|
|
81
86
|
// 決済方法から注文金額の計算
|
|
82
87
|
// price += authorizePaymentActions
|
package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js
CHANGED
|
@@ -11,14 +11,16 @@ const debug = createDebug('cinerino-domain:service:validateMovieTicket');
|
|
|
11
11
|
* 座席予約オファー承認に対してムビチケ承認条件が整っているかどうか検証する
|
|
12
12
|
*/
|
|
13
13
|
function validateMovieTicket(paymentMethodType, transaction, authorizeActions) {
|
|
14
|
-
// const authorizeActions = transaction.object.authorizeActions;
|
|
15
14
|
const authorizeMovieTicketActions = authorizeActions.filter((a) => {
|
|
16
|
-
var _a, _b, _c;
|
|
15
|
+
var _a, _b, _c, _d;
|
|
17
16
|
return a.actionStatus === factory.actionStatusType.CompletedActionStatus
|
|
18
17
|
&& ((_a = a.result) === null || _a === void 0 ? void 0 : _a.typeOf) === factory.action.authorize.paymentMethod.any.ResultType.Payment
|
|
19
18
|
&& ((_b = a.result) === null || _b === void 0 ? void 0 : _b.issuedThrough.typeOf) === factory.service.paymentService.PaymentServiceType.MovieTicket
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// 決済方法区分は必ず存在するはず(2023-08-15~)
|
|
20
|
+
&& ((_d = (_c = a.result) === null || _c === void 0 ? void 0 : _c.paymentMethodAsObject) === null || _d === void 0 ? void 0 : _d.typeOf) === paymentMethodType;
|
|
21
|
+
}
|
|
22
|
+
// && a.result?.paymentMethod === paymentMethodType
|
|
23
|
+
);
|
|
22
24
|
const seatReservationAuthorizeActions = authorizeActions.filter((a) => a.actionStatus === factory.actionStatusType.CompletedActionStatus
|
|
23
25
|
&& a.object.typeOf === factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation);
|
|
24
26
|
// 予約によって必要とされるMovieTicket
|
|
@@ -38,10 +38,7 @@ function validateTransaction(transaction, authorizeActions) {
|
|
|
38
38
|
validatePaymentUrl(transaction, authorizeActions);
|
|
39
39
|
}
|
|
40
40
|
exports.validateTransaction = validateTransaction;
|
|
41
|
-
function findMovieTicketPaymentMethodTypesFromTransaction(
|
|
42
|
-
// transaction: factory.transaction.placeOrder.ITransaction,
|
|
43
|
-
authorizeActions) {
|
|
44
|
-
// const authorizeActions = transaction.object.authorizeActions;
|
|
41
|
+
function findMovieTicketPaymentMethodTypesFromTransaction(authorizeActions) {
|
|
45
42
|
const authorizeMovieTicketPaymentActions = authorizeActions.filter((a) => {
|
|
46
43
|
var _a, _b;
|
|
47
44
|
return a.actionStatus === factory.actionStatusType.CompletedActionStatus
|
|
@@ -55,9 +52,6 @@ authorizeActions) {
|
|
|
55
52
|
seatReservationAuthorizeActions.forEach((action) => {
|
|
56
53
|
var _a;
|
|
57
54
|
// a.objectではなくa.resultを使用する(2022-06-04~)
|
|
58
|
-
// const acceptedOffer =
|
|
59
|
-
// tslint:disable-next-line:max-line-length
|
|
60
|
-
// (<factory.action.authorize.offer.seatReservation.IObject<factory.service.webAPI.Identifier.Chevre>>action.object).acceptedOffer;
|
|
61
55
|
const acceptedOffers = (_a = action.result) === null || _a === void 0 ? void 0 : _a.acceptedOffers;
|
|
62
56
|
acceptedOffers === null || acceptedOffers === void 0 ? void 0 : acceptedOffers.forEach((offer) => {
|
|
63
57
|
var _a;
|
|
@@ -72,14 +66,15 @@ authorizeActions) {
|
|
|
72
66
|
});
|
|
73
67
|
});
|
|
74
68
|
const paymentMethodTypes = [
|
|
75
|
-
|
|
69
|
+
// 決済方法区分は必ず存在するはず(2023-08-15~)
|
|
70
|
+
...authorizeMovieTicketPaymentActions.map((a) => { var _a, _b; return String((_b = (_a = a.result) === null || _a === void 0 ? void 0 : _a.paymentMethodAsObject) === null || _b === void 0 ? void 0 : _b.typeOf); }),
|
|
71
|
+
// ...authorizeMovieTicketPaymentActions.map((a) => String(a.result?.paymentMethod)),
|
|
76
72
|
...requiredMovieTicketPaymentMethodTypes
|
|
77
73
|
];
|
|
78
74
|
return [...new Set(paymentMethodTypes)];
|
|
79
75
|
}
|
|
80
76
|
function validateProfile(transaction) {
|
|
81
77
|
// object.customerで検証(2022-05-26~)
|
|
82
|
-
// const profile = transaction.agent;
|
|
83
78
|
const profile = transaction.object.customer;
|
|
84
79
|
if (typeof (profile === null || profile === void 0 ? void 0 : profile.email) !== 'string' || (profile === null || profile === void 0 ? void 0 : profile.email.length) === 0
|
|
85
80
|
|| typeof (profile === null || profile === void 0 ? void 0 : profile.familyName) !== 'string' || (profile === null || profile === void 0 ? void 0 : profile.familyName.length) === 0
|
|
@@ -89,7 +84,6 @@ function validateProfile(transaction) {
|
|
|
89
84
|
}
|
|
90
85
|
}
|
|
91
86
|
function validatePrice(transaction, authorizeActions) {
|
|
92
|
-
// const authorizeActions = transaction.object.authorizeActions;
|
|
93
87
|
let priceByAgent = 0;
|
|
94
88
|
let priceBySeller = 0;
|
|
95
89
|
// 決済承認を確認
|
|
@@ -121,7 +115,6 @@ function validatePrice(transaction, authorizeActions) {
|
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
117
|
function validatePaymentUrl(transaction, authorizeActions) {
|
|
124
|
-
// const authorizeActions = transaction.object.authorizeActions;
|
|
125
118
|
var _a, _b;
|
|
126
119
|
// 決済URLが発行されている場合、検証
|
|
127
120
|
const paymentMethodId = (_a = transaction.object.paymentMethods) === null || _a === void 0 ? void 0 : _a.paymentMethodId;
|
|
@@ -145,10 +138,7 @@ function validatePaymentUrl(transaction, authorizeActions) {
|
|
|
145
138
|
/**
|
|
146
139
|
* JPY以外の通貨について取引を検証する
|
|
147
140
|
*/
|
|
148
|
-
function validateMonetaryAmount(
|
|
149
|
-
// transaction: factory.transaction.placeOrder.ITransaction,
|
|
150
|
-
authorizeActions) {
|
|
151
|
-
// const authorizeActions = transaction.object.authorizeActions;
|
|
141
|
+
function validateMonetaryAmount(authorizeActions) {
|
|
152
142
|
const authorizeMonetaryAmountActions = authorizeActions
|
|
153
143
|
.filter((a) => {
|
|
154
144
|
var _a, _b;
|
|
@@ -230,10 +220,6 @@ exports.validatePaymentMethods = validatePaymentMethods;
|
|
|
230
220
|
* イベントオファー適用条件確認
|
|
231
221
|
*/
|
|
232
222
|
function validateEventOffers(params) {
|
|
233
|
-
// const seatReservationAuthorizeActions = <IAuthorizeSeatReservationOffer[]>
|
|
234
|
-
// params.transaction.object.authorizeActions
|
|
235
|
-
// .filter((a) => a.actionStatus === factory.actionStatusType.CompletedActionStatus)
|
|
236
|
-
// .filter((a) => a.object.typeOf === factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation);
|
|
237
223
|
const seatReservationAuthorizeActions = params.authorizeActions
|
|
238
224
|
.filter((a) => a.actionStatus === factory.actionStatusType.CompletedActionStatus)
|
|
239
225
|
.filter((a) => a.object.typeOf === factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation);
|
|
@@ -102,7 +102,6 @@ function confirm(params) {
|
|
|
102
102
|
}
|
|
103
103
|
// 取引に対する全ての承認アクションをマージ
|
|
104
104
|
const authorizeActions = yield searchAuthorizeActions(params)(repos);
|
|
105
|
-
// transaction.object.authorizeActions = authorizeActions;
|
|
106
105
|
// 注文番号を発行
|
|
107
106
|
const orderNumber = yield publishOrderNumberIfNotExist({
|
|
108
107
|
project: { id: transaction.project.id },
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.325.0-alpha.
|
|
12
|
+
"@chevre/factory": "4.325.0-alpha.5",
|
|
13
13
|
"@cinerino/sdk": "3.164.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"postversion": "git push origin --tags",
|
|
118
118
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
119
119
|
},
|
|
120
|
-
"version": "21.7.0-alpha.
|
|
120
|
+
"version": "21.7.0-alpha.8"
|
|
121
121
|
}
|
|
@@ -1,119 +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 EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
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 reservationRepo = new chevre.repository.Reservation(mongoose.connection);
|
|
15
|
-
const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
16
|
-
|
|
17
|
-
const cursor = reservationRepo.getCursor(
|
|
18
|
-
{
|
|
19
|
-
typeOf: {
|
|
20
|
-
$in: [
|
|
21
|
-
chevre.factory.reservationType.EventReservation
|
|
22
|
-
]
|
|
23
|
-
},
|
|
24
|
-
// bookingTime: {
|
|
25
|
-
// $gte: moment('2022-07-01T00:00:00Z')
|
|
26
|
-
// .toDate(),
|
|
27
|
-
// $lte: moment('2022-03-01T00:00:00Z')
|
|
28
|
-
// .toDate()
|
|
29
|
-
// },
|
|
30
|
-
'provider.id': { $exists: false }
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
_id: 1,
|
|
34
|
-
project: 1,
|
|
35
|
-
provider: 1,
|
|
36
|
-
bookingTime: 1,
|
|
37
|
-
reservationFor: 1
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
console.log('reservations found');
|
|
41
|
-
|
|
42
|
-
let i = 0;
|
|
43
|
-
let updateCount = 0;
|
|
44
|
-
await cursor.eachAsync(async (doc) => {
|
|
45
|
-
i += 1;
|
|
46
|
-
const reservation: Pick<
|
|
47
|
-
chevre.factory.reservation.IReservation<chevre.factory.reservationType.EventReservation>,
|
|
48
|
-
'id' | 'project' | 'provider' | 'bookingTime' | 'reservationFor'
|
|
49
|
-
> = doc.toObject();
|
|
50
|
-
|
|
51
|
-
const providerId = reservation.provider?.id;
|
|
52
|
-
const alreadyMigrated = typeof providerId === 'string';
|
|
53
|
-
|
|
54
|
-
if (alreadyMigrated) {
|
|
55
|
-
console.log('already exist...', reservation.project.id, reservation.id, reservation.bookingTime, providerId, i);
|
|
56
|
-
} else {
|
|
57
|
-
const movieTheaterId: string = reservation.reservationFor.superEvent.location.id;
|
|
58
|
-
const movieTheaterBranchCode: string = reservation.reservationFor.superEvent.location.branchCode;
|
|
59
|
-
const movieTheaters = <Pick<
|
|
60
|
-
chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom,
|
|
61
|
-
'parentOrganization' | 'branchCode'
|
|
62
|
-
>[]>
|
|
63
|
-
await placeRepo.searchMovieTheaters(
|
|
64
|
-
{
|
|
65
|
-
limit: 1,
|
|
66
|
-
page: 1,
|
|
67
|
-
project: { id: { $eq: reservation.project.id } },
|
|
68
|
-
id: { $eq: movieTheaterId }
|
|
69
|
-
},
|
|
70
|
-
['parentOrganization', 'branchCode'],
|
|
71
|
-
[]
|
|
72
|
-
);
|
|
73
|
-
const movieTheater = movieTheaters.shift();
|
|
74
|
-
const sellerId = movieTheater?.parentOrganization?.id;
|
|
75
|
-
console.log(
|
|
76
|
-
'movieTheater found',
|
|
77
|
-
reservation.project.id, reservation.id, reservation.bookingTime, providerId, 'sellerId:', sellerId,
|
|
78
|
-
'movieTheaterId:', movieTheaterId,
|
|
79
|
-
'movieTheaterBranchCode:', movieTheaterBranchCode,
|
|
80
|
-
i
|
|
81
|
-
);
|
|
82
|
-
if (typeof sellerId !== 'string') {
|
|
83
|
-
console.error(
|
|
84
|
-
'movieTheater not found',
|
|
85
|
-
reservation.project.id, reservation.id, reservation.bookingTime, providerId, 'sellerId:', sellerId,
|
|
86
|
-
'movieTheaterId:', movieTheaterId,
|
|
87
|
-
'movieTheaterBranchCode:', movieTheaterBranchCode,
|
|
88
|
-
i
|
|
89
|
-
);
|
|
90
|
-
throw new Error('movieTheater not found');
|
|
91
|
-
|
|
92
|
-
// return;
|
|
93
|
-
}
|
|
94
|
-
if (typeof sellerId === 'string') {
|
|
95
|
-
const newProvider: chevre.factory.reservation.IProvider = {
|
|
96
|
-
id: sellerId,
|
|
97
|
-
typeOf: chevre.factory.organizationType.Corporation
|
|
98
|
-
};
|
|
99
|
-
console.log(
|
|
100
|
-
'updating reservation...', reservation.project.id, reservation.id, reservation.bookingTime, providerId, i, updateCount);
|
|
101
|
-
await reservationRepo.updatePartiallyById({
|
|
102
|
-
id: reservation.id,
|
|
103
|
-
update: <any>{
|
|
104
|
-
provider: newProvider
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
updateCount += 1;
|
|
108
|
-
console.log('updated.', reservation.project.id, reservation.id, reservation.bookingTime, providerId, i, updateCount);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
console.log(i, 'reservations checked');
|
|
114
|
-
console.log(updateCount, 'reservations updated');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
main()
|
|
118
|
-
.then()
|
|
119
|
-
.catch(console.error);
|