@chevre/domain 20.4.0-alpha.3 → 20.4.0-alpha.5
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/unsetUnnecessaryFields.ts +26 -0
- package/lib/chevre/repo/account.d.ts +4 -10
- package/lib/chevre/repo/account.js +72 -60
- package/lib/chevre/repo/event.js +4 -13
- package/lib/chevre/repo/serviceOutput.d.ts +4 -0
- package/lib/chevre/repo/serviceOutput.js +6 -0
- package/lib/chevre/service/account.d.ts +0 -8
- package/lib/chevre/service/account.js +16 -10
- package/lib/chevre/service/accountTransaction/deposit.js +2 -1
- package/lib/chevre/service/accountTransaction/factory.js +25 -20
- package/lib/chevre/service/accountTransaction/transfer.js +4 -2
- package/lib/chevre/service/accountTransaction/withdraw.js +2 -1
- package/lib/chevre/service/assetTransaction/pay.js +11 -11
- package/lib/chevre/service/assetTransaction/registerService/factory.js +3 -2
- package/lib/chevre/service/payment/paymentCard.d.ts +4 -1
- package/lib/chevre/service/payment/paymentCard.js +16 -8
- package/package.json +3 -3
- package/example/src/chevre/migrateProjectSubscription.ts +0 -51
- package/example/src/chevre/migrateSection.ts +0 -105
|
@@ -0,0 +1,26 @@
|
|
|
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);
|
|
8
|
+
|
|
9
|
+
const accountRepo = new chevre.repository.Account(mongoose.connection);
|
|
10
|
+
const permitRepo = new chevre.repository.ServiceOutput(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
let updateResult = await accountRepo.unsetUnnecessaryFields({
|
|
13
|
+
filter: { status: { $exists: true } },
|
|
14
|
+
$unset: { status: 1 }
|
|
15
|
+
});
|
|
16
|
+
console.log('accounts unset.', updateResult);
|
|
17
|
+
updateResult = await permitRepo.unsetUnnecessaryFields({
|
|
18
|
+
filter: { 'paymentAccount.accountType': { $exists: true } },
|
|
19
|
+
$unset: { 'paymentAccount.accountType': 1 }
|
|
20
|
+
});
|
|
21
|
+
console.log('permits unset', updateResult);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
main()
|
|
25
|
+
.then()
|
|
26
|
+
.catch(console.error);
|
|
@@ -45,16 +45,6 @@ export declare class MongoRepository {
|
|
|
45
45
|
/**
|
|
46
46
|
* 口座を解約する
|
|
47
47
|
*/
|
|
48
|
-
close(params: {
|
|
49
|
-
/**
|
|
50
|
-
* 口座番号
|
|
51
|
-
*/
|
|
52
|
-
accountNumber: string;
|
|
53
|
-
/**
|
|
54
|
-
* 解約日時
|
|
55
|
-
*/
|
|
56
|
-
closeDate: Date;
|
|
57
|
-
}): Promise<void>;
|
|
58
48
|
/**
|
|
59
49
|
* 口座番号で検索する
|
|
60
50
|
*/
|
|
@@ -134,4 +124,8 @@ export declare class MongoRepository {
|
|
|
134
124
|
* 口座を検索する
|
|
135
125
|
*/
|
|
136
126
|
search(params: factory.account.ISearchConditions): Promise<factory.account.IAccount[]>;
|
|
127
|
+
unsetUnnecessaryFields(params: {
|
|
128
|
+
filter: any;
|
|
129
|
+
$unset: any;
|
|
130
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
137
131
|
}
|
|
@@ -10,11 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MongoRepository = exports.modelName = void 0;
|
|
13
|
-
const createDebug = require("debug");
|
|
14
13
|
const account_1 = require("./mongoose/model/account");
|
|
15
14
|
Object.defineProperty(exports, "modelName", { enumerable: true, get: function () { return account_1.modelName; } });
|
|
16
15
|
const factory = require("../factory");
|
|
17
|
-
const debug = createDebug('chevre-domain:repository');
|
|
18
16
|
/**
|
|
19
17
|
* 口座リポジトリ
|
|
20
18
|
*/
|
|
@@ -93,11 +91,11 @@ class MongoRepository {
|
|
|
93
91
|
}
|
|
94
92
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
95
93
|
/* istanbul ignore else */
|
|
96
|
-
if (Array.isArray(params.statuses) && params.statuses.length > 0) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
94
|
+
// if (Array.isArray(params.statuses) && params.statuses.length > 0) {
|
|
95
|
+
// andConditions.push({
|
|
96
|
+
// status: { $in: params.statuses }
|
|
97
|
+
// });
|
|
98
|
+
// }
|
|
101
99
|
const nameRegex = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$regex;
|
|
102
100
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
103
101
|
/* istanbul ignore else */
|
|
@@ -159,8 +157,8 @@ class MongoRepository {
|
|
|
159
157
|
balance: p.initialBalance,
|
|
160
158
|
availableBalance: p.initialBalance,
|
|
161
159
|
pendingTransactions: [],
|
|
162
|
-
openDate: p.openDate
|
|
163
|
-
status: factory.account.AccountStatusType.Opened
|
|
160
|
+
openDate: p.openDate
|
|
161
|
+
// status: factory.account.AccountStatusType.Opened
|
|
164
162
|
};
|
|
165
163
|
});
|
|
166
164
|
// const doc = await this.accountModel.create(account);
|
|
@@ -179,39 +177,47 @@ class MongoRepository {
|
|
|
179
177
|
/**
|
|
180
178
|
* 口座を解約する
|
|
181
179
|
*/
|
|
182
|
-
close(params
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
180
|
+
// public async close(params: {
|
|
181
|
+
// /**
|
|
182
|
+
// * 口座番号
|
|
183
|
+
// */
|
|
184
|
+
// accountNumber: string;
|
|
185
|
+
// /**
|
|
186
|
+
// * 解約日時
|
|
187
|
+
// */
|
|
188
|
+
// closeDate: Date;
|
|
189
|
+
// }) {
|
|
190
|
+
// const doc = await this.accountModel.findOneAndUpdate(
|
|
191
|
+
// {
|
|
192
|
+
// accountNumber: params.accountNumber,
|
|
193
|
+
// pendingTransactions: { $size: 0 },
|
|
194
|
+
// status: factory.account.AccountStatusType.Opened
|
|
195
|
+
// },
|
|
196
|
+
// {
|
|
197
|
+
// closeDate: params.closeDate,
|
|
198
|
+
// status: factory.account.AccountStatusType.Closed
|
|
199
|
+
// },
|
|
200
|
+
// {
|
|
201
|
+
// new: true
|
|
202
|
+
// }
|
|
203
|
+
// )
|
|
204
|
+
// .exec();
|
|
205
|
+
// // NotFoundであれば口座状態確認
|
|
206
|
+
// if (doc === null) {
|
|
207
|
+
// const account = await this.findByAccountNumber({
|
|
208
|
+
// accountNumber: params.accountNumber
|
|
209
|
+
// });
|
|
210
|
+
// if (account.status === factory.account.AccountStatusType.Closed) {
|
|
211
|
+
// // すでに口座解約済の場合
|
|
212
|
+
// return;
|
|
213
|
+
// } else if (Array.isArray(account.pendingTransactions) && account.pendingTransactions.length > 0) {
|
|
214
|
+
// // 進行中取引が存在する場合の場合
|
|
215
|
+
// throw new factory.errors.Argument('accountNumber', 'Pending transactions exist');
|
|
216
|
+
// } else {
|
|
217
|
+
// throw new factory.errors.NotFound(this.accountModel.modelName);
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
220
|
+
// }
|
|
215
221
|
/**
|
|
216
222
|
* 口座番号で検索する
|
|
217
223
|
*/
|
|
@@ -233,7 +239,7 @@ class MongoRepository {
|
|
|
233
239
|
*/
|
|
234
240
|
authorizeAmount(params) {
|
|
235
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
const doc = yield this.accountModel.findOneAndUpdate(Object.assign({ accountNumber: params.accountNumber
|
|
242
|
+
const doc = yield this.accountModel.findOneAndUpdate(Object.assign({ accountNumber: params.accountNumber }, (params.force === true) ? undefined : { availableBalance: { $gte: params.amount } } // 利用可能金額確認
|
|
237
243
|
), {
|
|
238
244
|
$inc: { availableBalance: -params.amount },
|
|
239
245
|
$push: { pendingTransactions: params.transaction } // 進行中取引追加
|
|
@@ -244,11 +250,11 @@ class MongoRepository {
|
|
|
244
250
|
const account = yield this.findByAccountNumber({
|
|
245
251
|
accountNumber: params.accountNumber
|
|
246
252
|
});
|
|
247
|
-
if (account.status === factory.account.AccountStatusType.Closed) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
253
|
+
// if (account.status === factory.account.AccountStatusType.Closed) {
|
|
254
|
+
// // 口座解約済の場合
|
|
255
|
+
// throw new factory.errors.Argument('accountNumber', 'Account already closed');
|
|
256
|
+
// } else
|
|
257
|
+
if (typeof account.availableBalance === 'number' && account.availableBalance < params.amount) {
|
|
252
258
|
// 残高不足の場合
|
|
253
259
|
throw new factory.errors.Argument('accountNumber', 'Insufficient balance');
|
|
254
260
|
}
|
|
@@ -264,22 +270,22 @@ class MongoRepository {
|
|
|
264
270
|
startTransaction(params) {
|
|
265
271
|
return __awaiter(this, void 0, void 0, function* () {
|
|
266
272
|
const doc = yield this.accountModel.findOneAndUpdate({
|
|
267
|
-
accountNumber: params.accountNumber
|
|
268
|
-
status: factory.account.AccountStatusType.Opened // 開いている口座
|
|
273
|
+
accountNumber: params.accountNumber
|
|
274
|
+
// status: factory.account.AccountStatusType.Opened // 開いている口座
|
|
269
275
|
}, { $push: { pendingTransactions: params.transaction } })
|
|
270
276
|
.exec();
|
|
271
277
|
// NotFoundであれば口座状態確認
|
|
272
278
|
if (doc === null) {
|
|
273
|
-
const account =
|
|
274
|
-
|
|
275
|
-
});
|
|
276
|
-
if (account.status === factory.account.AccountStatusType.Closed) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
// const account = await this.findByAccountNumber({
|
|
280
|
+
// accountNumber: params.accountNumber
|
|
281
|
+
// });
|
|
282
|
+
// if (account.status === factory.account.AccountStatusType.Closed) {
|
|
283
|
+
// // 口座解約済の場合
|
|
284
|
+
// throw new factory.errors.Argument('accountNumber', 'Account already closed');
|
|
285
|
+
// } else {
|
|
286
|
+
// throw new factory.errors.NotFound(this.accountModel.modelName);
|
|
287
|
+
// }
|
|
288
|
+
throw new factory.errors.NotFound(this.accountModel.modelName);
|
|
283
289
|
}
|
|
284
290
|
});
|
|
285
291
|
}
|
|
@@ -419,5 +425,11 @@ class MongoRepository {
|
|
|
419
425
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
420
426
|
});
|
|
421
427
|
}
|
|
428
|
+
unsetUnnecessaryFields(params) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
return this.accountModel.updateMany(params.filter, { $unset: params.$unset })
|
|
431
|
+
.exec();
|
|
432
|
+
});
|
|
433
|
+
}
|
|
422
434
|
}
|
|
423
435
|
exports.MongoRepository = MongoRepository;
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -473,11 +473,11 @@ class MongoRepository {
|
|
|
473
473
|
if (typeof additionalPropertyValue !== 'string') {
|
|
474
474
|
throw new factory.errors.NotFound('additionalProperty.value');
|
|
475
475
|
}
|
|
476
|
-
const _c = creatingEventParams.attributes, {
|
|
476
|
+
const _c = creatingEventParams.attributes, { eventStatus } = _c, setOnInsertFields = __rest(_c, ["eventStatus"]);
|
|
477
477
|
bulkWriteOps.push({
|
|
478
478
|
updateOne: {
|
|
479
479
|
filter: {
|
|
480
|
-
typeOf,
|
|
480
|
+
typeOf: creatingEventParams.attributes.typeOf,
|
|
481
481
|
// 追加特性をキーに更新
|
|
482
482
|
additionalProperty: {
|
|
483
483
|
$exists: true,
|
|
@@ -485,18 +485,9 @@ class MongoRepository {
|
|
|
485
485
|
}
|
|
486
486
|
},
|
|
487
487
|
update: {
|
|
488
|
-
$setOnInsert: {
|
|
489
|
-
_id: uniqid(),
|
|
490
|
-
typeOf,
|
|
491
|
-
project,
|
|
492
|
-
superEvent,
|
|
493
|
-
workPerformed,
|
|
494
|
-
location,
|
|
495
|
-
name
|
|
496
|
-
// ...creatingEventParams.attributes
|
|
497
|
-
},
|
|
488
|
+
$setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() }),
|
|
498
489
|
// 変更可能な属性のみ上書き
|
|
499
|
-
$set:
|
|
490
|
+
$set: { eventStatus }
|
|
500
491
|
},
|
|
501
492
|
upsert: true
|
|
502
493
|
}
|
|
@@ -169,5 +169,11 @@ class MongoRepository {
|
|
|
169
169
|
.exec();
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
|
+
unsetUnnecessaryFields(params) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
return this.serviceOutputModel.updateMany(params.filter, { $unset: params.$unset })
|
|
175
|
+
.exec();
|
|
176
|
+
});
|
|
177
|
+
}
|
|
172
178
|
}
|
|
173
179
|
exports.MongoRepository = MongoRepository;
|
|
@@ -37,14 +37,6 @@ export declare function open(params: {
|
|
|
37
37
|
/**
|
|
38
38
|
* 口座を解約する
|
|
39
39
|
*/
|
|
40
|
-
export declare function close(params: {
|
|
41
|
-
/**
|
|
42
|
-
* 口座番号
|
|
43
|
-
*/
|
|
44
|
-
accountNumber: string;
|
|
45
|
-
}): (repos: {
|
|
46
|
-
account: AccountRepo;
|
|
47
|
-
}) => Promise<void>;
|
|
48
40
|
/**
|
|
49
41
|
* 転送する
|
|
50
42
|
* 確定取引結果から、実際の転送アクションを実行します。
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.cancelMoneyTransfer = exports.transferMoney = exports.
|
|
12
|
+
exports.cancelMoneyTransfer = exports.transferMoney = exports.open = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* 口座サービス
|
|
15
15
|
* 開設、閉鎖等、口座アクション実行など
|
|
@@ -38,15 +38,21 @@ exports.open = open;
|
|
|
38
38
|
/**
|
|
39
39
|
* 口座を解約する
|
|
40
40
|
*/
|
|
41
|
-
function close(params
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
// export function close(params: {
|
|
42
|
+
// /**
|
|
43
|
+
// * 口座番号
|
|
44
|
+
// */
|
|
45
|
+
// accountNumber: string;
|
|
46
|
+
// }) {
|
|
47
|
+
// return async (repos: {
|
|
48
|
+
// account: AccountRepo;
|
|
49
|
+
// }) => {
|
|
50
|
+
// await repos.account.close({
|
|
51
|
+
// accountNumber: params.accountNumber,
|
|
52
|
+
// closeDate: new Date()
|
|
53
|
+
// });
|
|
54
|
+
// };
|
|
55
|
+
// }
|
|
50
56
|
/**
|
|
51
57
|
* 転送する
|
|
52
58
|
* 確定取引結果から、実際の転送アクションを実行します。
|
|
@@ -29,7 +29,8 @@ function start(params) {
|
|
|
29
29
|
amount: params.object.amount,
|
|
30
30
|
toLocation: {
|
|
31
31
|
typeOf: account.typeOf,
|
|
32
|
-
|
|
32
|
+
// 廃止(2023-02-16~)
|
|
33
|
+
// accountType: account.accountType,
|
|
33
34
|
accountNumber: account.accountNumber,
|
|
34
35
|
name: account.name
|
|
35
36
|
},
|
|
@@ -22,7 +22,8 @@ function createMoneyTransferActionAttributes(params) {
|
|
|
22
22
|
case factory.account.transactionType.Deposit:
|
|
23
23
|
toLocation = {
|
|
24
24
|
typeOf: transaction.object.toLocation.typeOf,
|
|
25
|
-
|
|
25
|
+
// 廃止(2023-02-16~)
|
|
26
|
+
// accountType: transaction.object.toLocation.accountType,
|
|
26
27
|
accountNumber: transaction.object.toLocation.accountNumber,
|
|
27
28
|
name: transaction.recipient.name
|
|
28
29
|
};
|
|
@@ -30,13 +31,15 @@ function createMoneyTransferActionAttributes(params) {
|
|
|
30
31
|
case factory.account.transactionType.Transfer:
|
|
31
32
|
fromLocation = {
|
|
32
33
|
typeOf: transaction.object.fromLocation.typeOf,
|
|
33
|
-
|
|
34
|
+
// 廃止(2023-02-16~)
|
|
35
|
+
// accountType: transaction.object.fromLocation.accountType,
|
|
34
36
|
accountNumber: transaction.object.fromLocation.accountNumber,
|
|
35
37
|
name: transaction.agent.name
|
|
36
38
|
};
|
|
37
39
|
toLocation = {
|
|
38
40
|
typeOf: transaction.object.toLocation.typeOf,
|
|
39
|
-
|
|
41
|
+
// 廃止(2023-02-16~)
|
|
42
|
+
// accountType: transaction.object.toLocation.accountType,
|
|
40
43
|
accountNumber: transaction.object.toLocation.accountNumber,
|
|
41
44
|
name: transaction.recipient.name
|
|
42
45
|
};
|
|
@@ -44,28 +47,29 @@ function createMoneyTransferActionAttributes(params) {
|
|
|
44
47
|
case factory.account.transactionType.Withdraw:
|
|
45
48
|
fromLocation = {
|
|
46
49
|
typeOf: transaction.object.fromLocation.typeOf,
|
|
47
|
-
|
|
50
|
+
// 廃止(2023-02-16~)
|
|
51
|
+
// accountType: transaction.object.fromLocation.accountType,
|
|
48
52
|
accountNumber: transaction.object.fromLocation.accountNumber,
|
|
49
53
|
name: transaction.agent.name
|
|
50
54
|
};
|
|
51
55
|
break;
|
|
52
56
|
default:
|
|
53
57
|
}
|
|
54
|
-
let accountType;
|
|
55
|
-
const transactionType = params.transaction.typeOf;
|
|
56
|
-
switch (transactionType) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
58
|
+
// let accountType: string;
|
|
59
|
+
// const transactionType = params.transaction.typeOf;
|
|
60
|
+
// switch (transactionType) {
|
|
61
|
+
// case factory.account.transactionType.Deposit:
|
|
62
|
+
// accountType = params.transaction.object.toLocation.accountType;
|
|
63
|
+
// break;
|
|
64
|
+
// case factory.account.transactionType.Transfer:
|
|
65
|
+
// accountType = params.transaction.object.fromLocation.accountType;
|
|
66
|
+
// break;
|
|
67
|
+
// case factory.account.transactionType.Withdraw:
|
|
68
|
+
// accountType = params.transaction.object.fromLocation.accountType;
|
|
69
|
+
// break;
|
|
70
|
+
// default:
|
|
71
|
+
// throw new factory.errors.NotImplemented(`transaction type ${transactionType} not implemented`);
|
|
72
|
+
// }
|
|
69
73
|
const purpose = {
|
|
70
74
|
typeOf: transaction.typeOf,
|
|
71
75
|
id: transaction.id,
|
|
@@ -84,7 +88,8 @@ function createMoneyTransferActionAttributes(params) {
|
|
|
84
88
|
recipient: transaction.recipient,
|
|
85
89
|
amount: {
|
|
86
90
|
typeOf: 'MonetaryAmount',
|
|
87
|
-
|
|
91
|
+
// 廃止(2023-02-16~)
|
|
92
|
+
// currency: accountType,
|
|
88
93
|
value: (typeof transaction.object.amount === 'number')
|
|
89
94
|
? transaction.object.amount
|
|
90
95
|
: transaction.object.amount.value
|
|
@@ -47,13 +47,15 @@ function start(params) {
|
|
|
47
47
|
amount: params.object.amount,
|
|
48
48
|
fromLocation: {
|
|
49
49
|
typeOf: fromAccount.typeOf,
|
|
50
|
-
|
|
50
|
+
// 廃止(2023-02-16~)
|
|
51
|
+
// accountType: fromAccount.accountType,
|
|
51
52
|
accountNumber: fromAccount.accountNumber,
|
|
52
53
|
name: fromAccount.name
|
|
53
54
|
},
|
|
54
55
|
toLocation: {
|
|
55
56
|
typeOf: toAccount.typeOf,
|
|
56
|
-
|
|
57
|
+
// 廃止(2023-02-16~)
|
|
58
|
+
// accountType: toAccount.accountType,
|
|
57
59
|
accountNumber: toAccount.accountNumber,
|
|
58
60
|
name: toAccount.name
|
|
59
61
|
},
|
|
@@ -36,7 +36,8 @@ function start(params) {
|
|
|
36
36
|
amount: params.object.amount,
|
|
37
37
|
fromLocation: {
|
|
38
38
|
typeOf: fromAccount.typeOf,
|
|
39
|
-
|
|
39
|
+
// 廃止(2023-02-16~)
|
|
40
|
+
// accountType: fromAccount.accountType,
|
|
40
41
|
accountNumber: fromAccount.accountNumber,
|
|
41
42
|
name: fromAccount.name
|
|
42
43
|
},
|
|
@@ -221,25 +221,25 @@ function validateSeller(params) {
|
|
|
221
221
|
function processAuthorizeAccount(params, transaction, paymentServiceId) {
|
|
222
222
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
223
223
|
yield (0, validation_1.validateAccount)(params)(repos);
|
|
224
|
-
const
|
|
224
|
+
const { pendingTransaction, currency } = yield PaymentCardPayment.authorize(params, paymentServiceId)(repos);
|
|
225
225
|
const totalPaymentDue = {
|
|
226
226
|
typeOf: 'MonetaryAmount',
|
|
227
|
-
currency
|
|
228
|
-
value: (typeof
|
|
229
|
-
?
|
|
230
|
-
:
|
|
227
|
+
currency,
|
|
228
|
+
value: (typeof pendingTransaction.object.amount === 'number')
|
|
229
|
+
? pendingTransaction.object.amount
|
|
230
|
+
: pendingTransaction.object.amount.value
|
|
231
231
|
};
|
|
232
|
-
const
|
|
233
|
-
typeOf:
|
|
234
|
-
id:
|
|
235
|
-
transactionNumber:
|
|
236
|
-
object: { fromLocation: { accountNumber:
|
|
232
|
+
const savingPendingTransaction = {
|
|
233
|
+
typeOf: pendingTransaction.typeOf,
|
|
234
|
+
id: pendingTransaction.id,
|
|
235
|
+
transactionNumber: pendingTransaction.transactionNumber,
|
|
236
|
+
object: { fromLocation: { accountNumber: pendingTransaction.object.fromLocation.accountNumber } }
|
|
237
237
|
};
|
|
238
238
|
return saveAuthorizeResult({
|
|
239
239
|
id: transaction.id,
|
|
240
240
|
update: {
|
|
241
241
|
'object.paymentMethod.totalPaymentDue': totalPaymentDue,
|
|
242
|
-
'object.pendingTransaction':
|
|
242
|
+
'object.pendingTransaction': savingPendingTransaction
|
|
243
243
|
}
|
|
244
244
|
})(repos);
|
|
245
245
|
});
|
|
@@ -63,8 +63,9 @@ function createServiceOutput(params) {
|
|
|
63
63
|
// 口座は複数のプロダクトに結合する可能性もあり、どのように利用されるかは知らない。ただbalanceを管理するだけ。通貨は知っている。
|
|
64
64
|
typeOf: factory.accountType.Account,
|
|
65
65
|
// ひとまずPermit識別子と口座番号は同一
|
|
66
|
-
accountNumber: identifier
|
|
67
|
-
|
|
66
|
+
accountNumber: identifier
|
|
67
|
+
// 廃止(2023-02-16~)
|
|
68
|
+
// accountType: amount.currency
|
|
68
69
|
};
|
|
69
70
|
break;
|
|
70
71
|
case factory.product.ProductType.MembershipService:
|
|
@@ -10,7 +10,10 @@ declare type IPendingTransaction = Pick<factory.account.transaction.withdraw.ITr
|
|
|
10
10
|
declare function authorize(params: factory.assetTransaction.pay.IStartParamsWithoutDetail, paymentServiceId: string): (repos: {
|
|
11
11
|
product: ProductRepo;
|
|
12
12
|
project: ProjectRepo;
|
|
13
|
-
}) => Promise<
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
pendingTransaction: IPendingTransaction;
|
|
15
|
+
currency: string;
|
|
16
|
+
}>;
|
|
14
17
|
declare function voidTransaction(params: factory.task.voidPayment.IData): (repos: {
|
|
15
18
|
product: ProductRepo;
|
|
16
19
|
}) => Promise<void>;
|
|
@@ -29,7 +29,7 @@ function authorize(params, paymentServiceId) {
|
|
|
29
29
|
throw new factory.errors.ArgumentNull('transactionNumber');
|
|
30
30
|
}
|
|
31
31
|
// 決済方法検証
|
|
32
|
-
const permit = yield validatePaymentMethod(params, paymentServiceId)(repos);
|
|
32
|
+
const { permit, currency } = yield validatePaymentMethod(params, paymentServiceId)(repos);
|
|
33
33
|
const accountNumber = (_a = permit.paymentAccount) === null || _a === void 0 ? void 0 : _a.accountNumber;
|
|
34
34
|
if (typeof accountNumber !== 'string') {
|
|
35
35
|
throw new factory.errors.ArgumentNull('permit.paymentAccount.accountNumber');
|
|
@@ -55,13 +55,13 @@ function authorize(params, paymentServiceId) {
|
|
|
55
55
|
// PecorinoAPIのエラーをハンドリング
|
|
56
56
|
throw (0, errorHandler_1.handlePecorinoError)(error);
|
|
57
57
|
}
|
|
58
|
-
return pendingTransaction;
|
|
58
|
+
return { pendingTransaction, currency };
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
exports.authorize = authorize;
|
|
62
62
|
function validatePaymentMethod(params, paymentServiceId) {
|
|
63
63
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
64
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
65
65
|
const serviceOutputIdentifier = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.accountId;
|
|
66
66
|
const amount = (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.amount;
|
|
67
67
|
const paymentMethodType = (_c = params.object.paymentMethod) === null || _c === void 0 ? void 0 : _c.typeOf;
|
|
@@ -74,6 +74,14 @@ function validatePaymentMethod(params, paymentServiceId) {
|
|
|
74
74
|
if (typeof paymentMethodType !== 'string') {
|
|
75
75
|
throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
|
|
76
76
|
}
|
|
77
|
+
// プロダクトから通貨区分を取得
|
|
78
|
+
const paymentCatdProduct = yield repos.product.findById({
|
|
79
|
+
id: paymentServiceId
|
|
80
|
+
});
|
|
81
|
+
const currency = (_e = (_d = paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
|
|
82
|
+
if (typeof currency !== 'string') {
|
|
83
|
+
throw new factory.errors.NotFound('product.serviceOutput.amount.currency');
|
|
84
|
+
}
|
|
77
85
|
// プロダクトのavailableChannelを取得する
|
|
78
86
|
const availableChannel = yield repos.product.findAvailableChannel({
|
|
79
87
|
project: { id: params.project.id },
|
|
@@ -83,9 +91,9 @@ function validatePaymentMethod(params, paymentServiceId) {
|
|
|
83
91
|
const permitService = new pecorinoapi.service.Permit({
|
|
84
92
|
endpoint: String(availableChannel.serviceUrl),
|
|
85
93
|
auth: new pecorinoapi.auth.ClientCredentials({
|
|
86
|
-
domain: String((
|
|
87
|
-
clientId: String((
|
|
88
|
-
clientSecret: String((
|
|
94
|
+
domain: String((_f = availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.authorizeServerDomain),
|
|
95
|
+
clientId: String((_g = availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.clientId),
|
|
96
|
+
clientSecret: String((_h = availableChannel.credentials) === null || _h === void 0 ? void 0 : _h.clientSecret),
|
|
89
97
|
scopes: [],
|
|
90
98
|
state: ''
|
|
91
99
|
})
|
|
@@ -97,7 +105,7 @@ function validatePaymentMethod(params, paymentServiceId) {
|
|
|
97
105
|
issuedThrough: { typeOf: factory.product.ProductType.PaymentCard }
|
|
98
106
|
});
|
|
99
107
|
// サービスタイプを確認
|
|
100
|
-
if (((
|
|
108
|
+
if (((_k = (_j = serviceOutput.issuedThrough) === null || _j === void 0 ? void 0 : _j.serviceType) === null || _k === void 0 ? void 0 : _k.codeValue) !== paymentMethodType) {
|
|
101
109
|
throw new factory.errors.Argument('object.paymentMethod.accountId', 'paymentMethodType not matched');
|
|
102
110
|
}
|
|
103
111
|
// 出金金額設定を確認
|
|
@@ -112,7 +120,7 @@ function validatePaymentMethod(params, paymentServiceId) {
|
|
|
112
120
|
throw new factory.errors.Argument('object.paymentMethod.amount', `maximum payment amount requirement not satisfied`);
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
|
-
return serviceOutput;
|
|
123
|
+
return { permit: serviceOutput, currency };
|
|
116
124
|
});
|
|
117
125
|
}
|
|
118
126
|
function processAccountTransaction(params) {
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.289.0-alpha.
|
|
13
|
-
"@cinerino/sdk": "3.140.0-alpha.
|
|
12
|
+
"@chevre/factory": "4.289.0-alpha.6",
|
|
13
|
+
"@cinerino/sdk": "3.140.0-alpha.7",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"postversion": "git push origin --tags",
|
|
121
121
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
122
122
|
},
|
|
123
|
-
"version": "20.4.0-alpha.
|
|
123
|
+
"version": "20.4.0-alpha.5"
|
|
124
124
|
}
|
|
@@ -1,51 +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
|
-
// 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 projectRepo = new chevre.repository.Project(mongoose.connection);
|
|
12
|
-
|
|
13
|
-
const cursor = projectRepo.getCursor(
|
|
14
|
-
{
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
// _id: 1,
|
|
18
|
-
}
|
|
19
|
-
);
|
|
20
|
-
console.log('projects found');
|
|
21
|
-
|
|
22
|
-
let i = 0;
|
|
23
|
-
let updateCount = 0;
|
|
24
|
-
// tslint:disable-next-line:max-func-body-length
|
|
25
|
-
await cursor.eachAsync(async (doc) => {
|
|
26
|
-
i += 1;
|
|
27
|
-
const project: chevre.factory.project.IProject = doc.toObject();
|
|
28
|
-
|
|
29
|
-
const useEventServiceAsProduct = project.subscription?.useEventServiceAsProduct;
|
|
30
|
-
const alreadyMigrated = useEventServiceAsProduct === true;
|
|
31
|
-
|
|
32
|
-
if (alreadyMigrated) {
|
|
33
|
-
console.log('already migrated.', project.id, i);
|
|
34
|
-
} else {
|
|
35
|
-
console.log(
|
|
36
|
-
'updating product...', project.id, i);
|
|
37
|
-
await projectRepo.findByIdAndIUpdate({
|
|
38
|
-
id: project.id,
|
|
39
|
-
subscription: { useEventServiceAsProduct: true }
|
|
40
|
-
});
|
|
41
|
-
updateCount += 1;
|
|
42
|
-
console.log('updated...', project.id, i);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
console.log(i, 'projects checked');
|
|
46
|
-
console.log(updateCount, 'projects updated');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
main()
|
|
50
|
-
.then()
|
|
51
|
-
.catch(console.error);
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console no-magic-numbers
|
|
2
|
-
// import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
import * as redis from 'redis';
|
|
5
|
-
|
|
6
|
-
import { chevre } from '../../../lib/index';
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
-
|
|
11
|
-
const client = redis.createClient({
|
|
12
|
-
host: <string>process.env.REDIS_HOST,
|
|
13
|
-
port: Number(process.env.REDIS_PORT),
|
|
14
|
-
password: <string>process.env.REDIS_KEY
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
18
|
-
|
|
19
|
-
const events = await eventRepo.search({
|
|
20
|
-
typeOf: chevre.factory.eventType.ScreeningEvent,
|
|
21
|
-
project: { id: { $eq: '' } },
|
|
22
|
-
startFrom: new Date()
|
|
23
|
-
// startThrough: moment().add(4, 'day').toDate()
|
|
24
|
-
});
|
|
25
|
-
console.log(events.length, 'events found');
|
|
26
|
-
|
|
27
|
-
const sectionCode = 'Default';
|
|
28
|
-
await Promise.all(events.map(async (event) => {
|
|
29
|
-
await new Promise<void>((resolve) => {
|
|
30
|
-
const key = `chevre:itemAvailability:screeningEvent:${event.id}`;
|
|
31
|
-
client.hgetall(key, async (__, reply) => {
|
|
32
|
-
if (reply !== null && Object.keys(reply).length > 0) {
|
|
33
|
-
|
|
34
|
-
const fieldAndValues = reply;
|
|
35
|
-
for (const field of Object.keys(fieldAndValues)) {
|
|
36
|
-
// セクションがなければキーを更新
|
|
37
|
-
if (field.slice(0, 7) !== sectionCode) {
|
|
38
|
-
console.log(event.id, field);
|
|
39
|
-
const newField = `${sectionCode}${field}`;
|
|
40
|
-
const newValue = fieldAndValues[field];
|
|
41
|
-
console.log('saving...', newField, newValue);
|
|
42
|
-
|
|
43
|
-
await new Promise<void>((resolveSet) => {
|
|
44
|
-
client.hsetnx(key, newField, newValue, (___, setReply) => {
|
|
45
|
-
console.log('set', setReply, newField, newValue);
|
|
46
|
-
|
|
47
|
-
resolveSet();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// 元のフィールドを削除
|
|
52
|
-
await new Promise<void>((resolveSet) => {
|
|
53
|
-
client.hdel(key, field, (___, setReply) => {
|
|
54
|
-
console.log('deleted', setReply, field);
|
|
55
|
-
|
|
56
|
-
resolveSet();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
resolve();
|
|
64
|
-
// if (err !== null) {
|
|
65
|
-
// reject(err);
|
|
66
|
-
// } else {
|
|
67
|
-
// if (reply !== null) {
|
|
68
|
-
// client.ttl(targetKey, (ttlErr, ttl) => {
|
|
69
|
-
// console.log('ttl:', ttl);
|
|
70
|
-
// const args = Object.keys(reply)
|
|
71
|
-
// .reduce(
|
|
72
|
-
// (a, b) => {
|
|
73
|
-
// return [...a, b, reply[b]];
|
|
74
|
-
// },
|
|
75
|
-
// []
|
|
76
|
-
// );
|
|
77
|
-
// console.log(args.length, 'args ready');
|
|
78
|
-
|
|
79
|
-
// newClient.multi()
|
|
80
|
-
// .hmset(newKey, ...args)
|
|
81
|
-
// .expire(newKey, ttl)
|
|
82
|
-
// .exec((hmsetErr, reply) => {
|
|
83
|
-
// console.log('hmset result:', hmsetErr, reply);
|
|
84
|
-
// resolve();
|
|
85
|
-
// });
|
|
86
|
-
// });
|
|
87
|
-
// } else {
|
|
88
|
-
// console.error('targetKey not found');
|
|
89
|
-
// }
|
|
90
|
-
// }
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}));
|
|
94
|
-
|
|
95
|
-
// client.keys('chevre:itemAvailability:screeningEvent:*', async (err, reply) => {
|
|
96
|
-
// console.log(err, reply.length, 'keys found');
|
|
97
|
-
// const targetKeys = reply;
|
|
98
|
-
|
|
99
|
-
// });
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
main()
|
|
104
|
-
.then(console.log)
|
|
105
|
-
.catch(console.error);
|