@chevre/domain 24.0.0-alpha.32 → 24.0.0-alpha.33
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/lib/chevre/factory/transaction.d.ts +0 -3
- package/lib/chevre/repo/action/actionProcess.d.ts +1 -1
- package/lib/chevre/repo/action.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +1 -2
- package/lib/chevre/repo/passport.d.ts +1 -1
- package/lib/chevre/repo/task.d.ts +1 -1
- package/lib/chevre/repo/transaction.d.ts +1 -39
- package/lib/chevre/repository.d.ts +0 -10
- package/lib/chevre/repository.js +0 -22
- package/lib/chevre/service/delivery/factory.js +4 -4
- package/lib/chevre/service/offer/any.d.ts +1 -1
- package/lib/chevre/service/offer.d.ts +1 -2
- package/lib/chevre/service/offer.js +1 -3
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +54 -36
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +78 -64
- package/lib/chevre/service/order/placeOrder/factory/orderedItem.d.ts +0 -1
- package/lib/chevre/service/order/placeOrder/factory/orderedItem.js +3 -8
- package/lib/chevre/service/order/placeOrder/factory.js +5 -5
- package/lib/chevre/service/task/deletePerson.js +0 -1
- package/lib/chevre/service/task/deleteTransaction.js +0 -2
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +0 -2
- package/lib/chevre/service/transaction/deleteTransaction.js +2 -47
- package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +0 -1
- package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.d.ts +2 -2
- package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +2 -3
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +3 -3
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +2 -2
- package/lib/chevre/service/transaction/placeOrder/confirm.js +12 -17
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +1 -15
- package/lib/chevre/service/transaction.d.ts +0 -4
- package/lib/chevre/service/transaction.js +1 -11
- package/lib/chevre/service/validation/validateOrder.js +2 -2
- package/package.json +3 -3
- package/lib/chevre/repo/action/authorizeMoneyTransferOffer.d.ts +0 -40
- package/lib/chevre/repo/action/authorizeMoneyTransferOffer.js +0 -61
- package/lib/chevre/repo/transaction/moneyTransfer.d.ts +0 -61
- package/lib/chevre/repo/transaction/moneyTransfer.js +0 -379
- package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +0 -38
- package/lib/chevre/service/offer/moneyTransfer/authorize.js +0 -250
- package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.d.ts +0 -16
- package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +0 -96
- package/lib/chevre/service/offer/moneyTransfer/settleTransaction.d.ts +0 -9
- package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +0 -91
- package/lib/chevre/service/offer/moneyTransfer/voidTransaction.d.ts +0 -10
- package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +0 -81
- package/lib/chevre/service/offer/moneyTransfer.d.ts +0 -5
- package/lib/chevre/service/offer/moneyTransfer.js +0 -11
- package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +0 -6
- package/lib/chevre/service/task/confirmMoneyTransfer.js +0 -19
- package/lib/chevre/service/task/returnMoneyTransfer.d.ts +0 -6
- package/lib/chevre/service/task/returnMoneyTransfer.js +0 -55
- package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +0 -6
- package/lib/chevre/service/task/voidMoneyTransferTransaction.js +0 -27
- package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.d.ts +0 -9
- package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +0 -138
- package/lib/chevre/service/transaction/moneyTransfer/factory.d.ts +0 -2
- package/lib/chevre/service/transaction/moneyTransfer/factory.js +0 -55
- package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +0 -9
- package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +0 -65
- package/lib/chevre/service/transaction/moneyTransfer.d.ts +0 -72
- package/lib/chevre/service/transaction/moneyTransfer.js +0 -649
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.MoneyTransferRepo = void 0;
|
|
30
|
-
const moment_1 = __importDefault(require("moment"));
|
|
31
|
-
const transaction_1 = require("../../eventEmitter/transaction");
|
|
32
|
-
const factory = __importStar(require("../../factory"));
|
|
33
|
-
const settings_1 = require("../../settings");
|
|
34
|
-
const transaction_2 = require("../mongoose/schemas/transaction");
|
|
35
|
-
const AVAILABLE_PROJECT_FIELDS = [
|
|
36
|
-
'project',
|
|
37
|
-
'status',
|
|
38
|
-
'typeOf',
|
|
39
|
-
'agent',
|
|
40
|
-
'recipient',
|
|
41
|
-
'seller',
|
|
42
|
-
'error',
|
|
43
|
-
'result',
|
|
44
|
-
'object',
|
|
45
|
-
'expires',
|
|
46
|
-
'startDate',
|
|
47
|
-
'endDate',
|
|
48
|
-
'tasksExportAction',
|
|
49
|
-
'potentialActions',
|
|
50
|
-
// 'instrument'
|
|
51
|
-
];
|
|
52
|
-
/**
|
|
53
|
-
* 通貨転送取引リポジトリ
|
|
54
|
-
*/
|
|
55
|
-
class MoneyTransferRepo {
|
|
56
|
-
transactionModel;
|
|
57
|
-
constructor(connection) {
|
|
58
|
-
this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
|
|
59
|
-
}
|
|
60
|
-
static CREATE_MONGO_CONDITIONS(params) {
|
|
61
|
-
if (params.typeOf !== factory.transactionType.MoneyTransfer) {
|
|
62
|
-
throw new factory.errors.Argument('typeOf', `must be ${factory.transactionType.MoneyTransfer}`);
|
|
63
|
-
}
|
|
64
|
-
const andConditions = [];
|
|
65
|
-
const projectIdEq = params.project?.id?.$eq;
|
|
66
|
-
if (typeof projectIdEq === 'string') {
|
|
67
|
-
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
68
|
-
}
|
|
69
|
-
if (typeof params.typeOf === 'string') {
|
|
70
|
-
andConditions.push({ typeOf: { $eq: params.typeOf } });
|
|
71
|
-
}
|
|
72
|
-
if (params.startFrom !== undefined) {
|
|
73
|
-
andConditions.push({
|
|
74
|
-
startDate: { $gte: params.startFrom }
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (params.startThrough !== undefined) {
|
|
78
|
-
andConditions.push({
|
|
79
|
-
startDate: { $lte: params.startThrough }
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (params.endFrom !== undefined) {
|
|
83
|
-
andConditions.push({
|
|
84
|
-
endDate: {
|
|
85
|
-
$exists: true,
|
|
86
|
-
$gte: params.endFrom
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (params.endThrough !== undefined) {
|
|
91
|
-
andConditions.push({
|
|
92
|
-
endDate: {
|
|
93
|
-
$exists: true,
|
|
94
|
-
$lt: params.endThrough
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (Array.isArray(params.ids)) {
|
|
99
|
-
andConditions.push({
|
|
100
|
-
_id: { $in: params.ids }
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (Array.isArray(params.statuses)) {
|
|
104
|
-
andConditions.push({ status: { $in: params.statuses } });
|
|
105
|
-
}
|
|
106
|
-
const statusIn = params.status?.$in;
|
|
107
|
-
if (Array.isArray(statusIn)) {
|
|
108
|
-
andConditions.push({ status: { $in: statusIn } });
|
|
109
|
-
}
|
|
110
|
-
if (params.agent !== undefined) {
|
|
111
|
-
if (params.agent.typeOf !== undefined) {
|
|
112
|
-
andConditions.push({
|
|
113
|
-
'agent.typeOf': {
|
|
114
|
-
$exists: true,
|
|
115
|
-
$eq: params.agent.typeOf
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
if (Array.isArray(params.agent.ids)) {
|
|
120
|
-
andConditions.push({
|
|
121
|
-
'agent.id': {
|
|
122
|
-
$exists: true,
|
|
123
|
-
$in: params.agent.ids
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (Array.isArray(params.agent.identifiers)) {
|
|
128
|
-
andConditions.push({
|
|
129
|
-
'agent.identifier': {
|
|
130
|
-
$exists: true,
|
|
131
|
-
$in: params.agent.identifiers
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const tasksExportActionStatusIn = params.tasksExportAction?.actionStatus?.$in;
|
|
137
|
-
if (Array.isArray(tasksExportActionStatusIn)) {
|
|
138
|
-
andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $in: tasksExportActionStatusIn } });
|
|
139
|
-
}
|
|
140
|
-
const tasksExportActionStatusEq = params.tasksExportAction?.actionStatus?.$eq;
|
|
141
|
-
if (typeof tasksExportActionStatusEq === 'string') {
|
|
142
|
-
andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $eq: tasksExportActionStatusEq } });
|
|
143
|
-
}
|
|
144
|
-
// switch (params.typeOf) {
|
|
145
|
-
// case factory.transactionType.PlaceOrder:
|
|
146
|
-
// throw new factory.errors.NotImplemented(`use PlaceOrderRepo`);
|
|
147
|
-
// case factory.transactionType.ReturnOrder:
|
|
148
|
-
// throw new factory.errors.NotImplemented(`use ReturnOrderRepo`);
|
|
149
|
-
// default:
|
|
150
|
-
// }
|
|
151
|
-
return andConditions;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* 取引を開始する
|
|
155
|
-
*/
|
|
156
|
-
// public async startNoPlaceOrder<
|
|
157
|
-
async startMoneyTransfer(params) {
|
|
158
|
-
const status = factory.transactionStatusType.InProgress;
|
|
159
|
-
const tasksExportAction = { actionStatus: factory.actionStatusType.PotentialActionStatus };
|
|
160
|
-
// const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
|
|
161
|
-
const startDate = new Date();
|
|
162
|
-
// let expires: Date;
|
|
163
|
-
const { typeOf } = params;
|
|
164
|
-
const expires = params.expires;
|
|
165
|
-
let creatingTransaction;
|
|
166
|
-
if (typeOf === factory.transactionType.MoneyTransfer) {
|
|
167
|
-
const { agent, project, object, seller, recipient } = params;
|
|
168
|
-
creatingTransaction = {
|
|
169
|
-
status, startDate, expires, typeOf, tasksExportAction,
|
|
170
|
-
agent, project, seller, object, recipient
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
|
|
175
|
-
}
|
|
176
|
-
// reimplemnt with insertMany(2024-05-30~)
|
|
177
|
-
const result = await this.transactionModel.insertMany(creatingTransaction, { rawResult: true });
|
|
178
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
179
|
-
if (typeof id !== 'string') {
|
|
180
|
-
throw new factory.errors.Internal('transaction not saved');
|
|
181
|
-
}
|
|
182
|
-
// 取引開始時にも取引イベントエミッター連携(2024-03-21~)
|
|
183
|
-
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({ id, typeOf, status });
|
|
184
|
-
return { expires, id, startDate, status }; // minimize response(2024-05-30~)
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 特定取引検索
|
|
188
|
-
*/
|
|
189
|
-
async findMoneyTransferById(params, inclusion // make required(2024-05-31~)
|
|
190
|
-
) {
|
|
191
|
-
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
192
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
193
|
-
positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
throw new factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
|
|
197
|
-
}
|
|
198
|
-
const projection = {
|
|
199
|
-
_id: 0,
|
|
200
|
-
id: { $toString: '$_id' },
|
|
201
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
202
|
-
};
|
|
203
|
-
const doc = await this.transactionModel.findOne({
|
|
204
|
-
_id: { $eq: params.id },
|
|
205
|
-
typeOf: { $eq: params.typeOf }
|
|
206
|
-
}, projection)
|
|
207
|
-
.lean() // 2024-08-26~
|
|
208
|
-
.exec();
|
|
209
|
-
if (doc === null) {
|
|
210
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} not found`);
|
|
211
|
-
}
|
|
212
|
-
return doc;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 進行中の取引を取得する
|
|
216
|
-
*/
|
|
217
|
-
async findMoneyTransferInProgressById(params, inclusion // make required(2024-05-29~)
|
|
218
|
-
) {
|
|
219
|
-
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
220
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
221
|
-
positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
throw new factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
|
|
225
|
-
}
|
|
226
|
-
const projection = {
|
|
227
|
-
_id: 0,
|
|
228
|
-
id: { $toString: '$_id' },
|
|
229
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
230
|
-
};
|
|
231
|
-
const filter = {
|
|
232
|
-
_id: { $eq: params.id },
|
|
233
|
-
typeOf: { $eq: params.typeOf },
|
|
234
|
-
status: { $eq: factory.transactionStatusType.InProgress },
|
|
235
|
-
// expiresを条件に追加(2023-05-12~),
|
|
236
|
-
expires: { $gt: new Date() }
|
|
237
|
-
};
|
|
238
|
-
const doc = await this.transactionModel.findOne(filter, projection)
|
|
239
|
-
.lean() // 2024-08-26~
|
|
240
|
-
.exec();
|
|
241
|
-
if (doc === null) {
|
|
242
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
243
|
-
}
|
|
244
|
-
return doc;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* 取引を確定する
|
|
248
|
-
*/
|
|
249
|
-
// public async confirmNoPlaceOrder<
|
|
250
|
-
async confirmMoneyTransfer(params) {
|
|
251
|
-
const endDate = new Date();
|
|
252
|
-
const doc = await this.transactionModel.findOneAndUpdate({
|
|
253
|
-
_id: { $eq: params.id },
|
|
254
|
-
typeOf: { $eq: params.typeOf },
|
|
255
|
-
status: { $eq: factory.transactionStatusType.InProgress },
|
|
256
|
-
expires: { $gt: endDate } // add expires(2025-02-27~)
|
|
257
|
-
}, {
|
|
258
|
-
status: factory.transactionStatusType.Confirmed, // ステータス変更
|
|
259
|
-
endDate,
|
|
260
|
-
// 'object.authorizeActions': params.authorizeActions,
|
|
261
|
-
result: params.result, // resultを更新
|
|
262
|
-
potentialActions: params.potentialActions // resultを更新
|
|
263
|
-
}, {
|
|
264
|
-
new: true,
|
|
265
|
-
projection: { _id: 1 }
|
|
266
|
-
})
|
|
267
|
-
.lean()
|
|
268
|
-
.exec();
|
|
269
|
-
// NotFoundであれば取引状態確認
|
|
270
|
-
if (doc === null) {
|
|
271
|
-
const { expires, status } = await this.findMoneyTransferById({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
|
|
272
|
-
if (status === factory.transactionStatusType.Confirmed) {
|
|
273
|
-
// すでに確定済の場合スルー
|
|
274
|
-
}
|
|
275
|
-
else if (status === factory.transactionStatusType.Expired) {
|
|
276
|
-
throw new factory.errors.Argument('Transaction id', 'Already expired');
|
|
277
|
-
}
|
|
278
|
-
else if (status === factory.transactionStatusType.Canceled) {
|
|
279
|
-
throw new factory.errors.Argument('Transaction id', 'Already canceled');
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
if ((0, moment_1.default)(expires)
|
|
283
|
-
.isSameOrBefore((0, moment_1.default)(endDate))) {
|
|
284
|
-
throw new factory.errors.Argument('Transaction id', 'potentially expired');
|
|
285
|
-
}
|
|
286
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
290
|
-
id: params.id,
|
|
291
|
-
typeOf: params.typeOf,
|
|
292
|
-
status: factory.transactionStatusType.Confirmed
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* 取引を中止する
|
|
297
|
-
*/
|
|
298
|
-
async cancelMoneyTransfer(params) {
|
|
299
|
-
const endDate = new Date();
|
|
300
|
-
// 進行中ステータスの取引を中止する
|
|
301
|
-
const doc = await this.transactionModel.findOneAndUpdate({
|
|
302
|
-
typeOf: params.typeOf,
|
|
303
|
-
_id: params.id,
|
|
304
|
-
status: factory.transactionStatusType.InProgress
|
|
305
|
-
}, {
|
|
306
|
-
status: factory.transactionStatusType.Canceled,
|
|
307
|
-
endDate: endDate
|
|
308
|
-
}, {
|
|
309
|
-
new: true,
|
|
310
|
-
projection: { _id: 1 }
|
|
311
|
-
})
|
|
312
|
-
.lean()
|
|
313
|
-
.exec();
|
|
314
|
-
// NotFoundであれば取引状態確認
|
|
315
|
-
if (doc === null) {
|
|
316
|
-
const { status } = await this.findMoneyTransferById(params, ['status']);
|
|
317
|
-
if (status === factory.transactionStatusType.Canceled) {
|
|
318
|
-
// すでに中止済の場合スルー
|
|
319
|
-
}
|
|
320
|
-
else if (status === factory.transactionStatusType.Expired) {
|
|
321
|
-
throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
|
|
322
|
-
}
|
|
323
|
-
else if (status === factory.transactionStatusType.Confirmed) {
|
|
324
|
-
throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
331
|
-
id: params.id,
|
|
332
|
-
typeOf: params.typeOf,
|
|
333
|
-
status: factory.transactionStatusType.Canceled
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
async countMoneyTransfer(params) {
|
|
337
|
-
const { limit } = params;
|
|
338
|
-
const conditions = MoneyTransferRepo.CREATE_MONGO_CONDITIONS(params);
|
|
339
|
-
const query = this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
|
|
340
|
-
if (typeof limit === 'number' && limit >= 0) {
|
|
341
|
-
query.limit(limit);
|
|
342
|
-
}
|
|
343
|
-
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
344
|
-
.exec();
|
|
345
|
-
return { count };
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* 取引を検索する
|
|
349
|
-
*/
|
|
350
|
-
async findMoneyTransferTransactions(params) {
|
|
351
|
-
const { inclusion } = params;
|
|
352
|
-
const conditions = MoneyTransferRepo.CREATE_MONGO_CONDITIONS(params);
|
|
353
|
-
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
354
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
355
|
-
positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
|
|
356
|
-
}
|
|
357
|
-
const projection = {
|
|
358
|
-
_id: 0,
|
|
359
|
-
id: { $toString: '$_id' },
|
|
360
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
361
|
-
};
|
|
362
|
-
const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
|
|
363
|
-
.select(projection);
|
|
364
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
365
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
366
|
-
query.limit(params.limit)
|
|
367
|
-
.skip(params.limit * (page - 1));
|
|
368
|
-
}
|
|
369
|
-
if (params.sort?.startDate !== undefined) {
|
|
370
|
-
query.sort({ startDate: params.sort.startDate });
|
|
371
|
-
}
|
|
372
|
-
// const explainResult = await (<any>query).explain();
|
|
373
|
-
// console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
374
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
375
|
-
.lean()
|
|
376
|
-
.exec();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
exports.MoneyTransferRepo = MoneyTransferRepo;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as factory from '../../../factory';
|
|
2
|
-
import type { AuthorizeMoneyTransferOfferActionRepo } from '../../../repo/action/authorizeMoneyTransferOffer';
|
|
3
|
-
import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
|
|
4
|
-
import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
|
|
5
|
-
import type { OrderNumberRepo } from '../../../repo/orderNumber';
|
|
6
|
-
import type { ProductRepo } from '../../../repo/product';
|
|
7
|
-
import type { ProjectRepo } from '../../../repo/project';
|
|
8
|
-
import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
|
|
9
|
-
import type { TransactionNumberRepo } from '../../../repo/transactionNumber';
|
|
10
|
-
interface IAuthorizeRepos {
|
|
11
|
-
action?: never;
|
|
12
|
-
authorizeMoneyTransferOfferAction: AuthorizeMoneyTransferOfferActionRepo;
|
|
13
|
-
product: ProductRepo;
|
|
14
|
-
project: ProjectRepo;
|
|
15
|
-
assetTransaction: AssetTransactionRepo;
|
|
16
|
-
orderInTransaction: OrderInTransactionRepo;
|
|
17
|
-
orderNumber: OrderNumberRepo;
|
|
18
|
-
placeOrder: PlaceOrderRepo;
|
|
19
|
-
transactionNumber: TransactionNumberRepo;
|
|
20
|
-
}
|
|
21
|
-
type IAuthorizeOperation<T> = (repos: IAuthorizeRepos) => Promise<T>;
|
|
22
|
-
export declare function authorize(params: {
|
|
23
|
-
project: {
|
|
24
|
-
id: string;
|
|
25
|
-
typeOf: factory.organizationType.Project;
|
|
26
|
-
};
|
|
27
|
-
agent: {
|
|
28
|
-
id: string;
|
|
29
|
-
};
|
|
30
|
-
object: factory.action.authorize.offer.moneyTransfer.IObject;
|
|
31
|
-
purpose: factory.action.authorize.offer.moneyTransfer.IPurpose;
|
|
32
|
-
}): IAuthorizeOperation<{
|
|
33
|
-
/**
|
|
34
|
-
* 承認アクションID
|
|
35
|
-
*/
|
|
36
|
-
id: string;
|
|
37
|
-
}>;
|
|
38
|
-
export {};
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.authorize = authorize;
|
|
30
|
-
const moment_1 = __importDefault(require("moment"));
|
|
31
|
-
const factory = __importStar(require("../../../factory"));
|
|
32
|
-
const MoneyTransferAssetTransactionService = __importStar(require("../../assetTransaction/moneyTransfer"));
|
|
33
|
-
const issueOrderNumberIfNotExist_1 = require("../../transaction/placeOrder/issueOrderNumberIfNotExist");
|
|
34
|
-
const any_1 = require("../any");
|
|
35
|
-
function authorize(params) {
|
|
36
|
-
return async (repos) => {
|
|
37
|
-
if (params.purpose.typeOf !== factory.transactionType.PlaceOrder) {
|
|
38
|
-
throw new factory.errors.NotImplemented(`purpose.typeOf: ${params.purpose.typeOf} not implemented`);
|
|
39
|
-
}
|
|
40
|
-
const transaction = await repos.placeOrder.findPlaceOrderInProgressById({
|
|
41
|
-
typeOf: params.purpose.typeOf,
|
|
42
|
-
id: params.purpose.id
|
|
43
|
-
}, ['seller', 'project', 'agent', 'typeOf']);
|
|
44
|
-
if (transaction.agent.id !== params.agent.id) {
|
|
45
|
-
throw new factory.errors.Forbidden('Transaction not yours');
|
|
46
|
-
}
|
|
47
|
-
const now = new Date();
|
|
48
|
-
const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
|
|
49
|
-
project: { id: params.project.id },
|
|
50
|
-
id: transaction.id,
|
|
51
|
-
object: { orderDate: now }
|
|
52
|
-
})(repos);
|
|
53
|
-
// まず取引番号発行
|
|
54
|
-
const { transactionNumber } = await repos.transactionNumber.publishByTimestamp({ startDate: now });
|
|
55
|
-
let requestBody;
|
|
56
|
-
let responseBody;
|
|
57
|
-
let acceptedOffers4result;
|
|
58
|
-
// 承認アクションを開始
|
|
59
|
-
const actionAttributes = createAuthorizeMoneyTransferOfferActionattributes({
|
|
60
|
-
transaction,
|
|
61
|
-
object: params.object,
|
|
62
|
-
transactionNumber
|
|
63
|
-
});
|
|
64
|
-
const action = await repos.authorizeMoneyTransferOfferAction.start(actionAttributes);
|
|
65
|
-
// priceを確定する
|
|
66
|
-
let price = 0;
|
|
67
|
-
try {
|
|
68
|
-
const startDepositTransactionResult = await processStartDepositTransaction({
|
|
69
|
-
project: params.project,
|
|
70
|
-
transaction: transaction,
|
|
71
|
-
object: params.object,
|
|
72
|
-
transactionNumber
|
|
73
|
-
})(repos);
|
|
74
|
-
requestBody = startDepositTransactionResult.requestBody;
|
|
75
|
-
responseBody = startDepositTransactionResult.responseBody;
|
|
76
|
-
// 通貨がJPYであればpriceに反映
|
|
77
|
-
if (responseBody.object.amount.currency === factory.priceCurrency.JPY) {
|
|
78
|
-
price = Number(responseBody.object.amount.value);
|
|
79
|
-
}
|
|
80
|
-
acceptedOffers4result = responseBody2resultAcceptedOffer({ responseBody, object: actionAttributes.object });
|
|
81
|
-
await (0, any_1.acceptOffer)({
|
|
82
|
-
orderNumber,
|
|
83
|
-
project: transaction.project,
|
|
84
|
-
acceptedOffers: acceptedOffers4result
|
|
85
|
-
})(repos);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
try {
|
|
89
|
-
await repos.authorizeMoneyTransferOfferAction.giveUp({ typeOf: action.typeOf, id: action.id, error });
|
|
90
|
-
}
|
|
91
|
-
catch (__) {
|
|
92
|
-
// 失敗したら仕方ない
|
|
93
|
-
}
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
const result = {
|
|
97
|
-
price,
|
|
98
|
-
priceCurrency: factory.priceCurrency.JPY,
|
|
99
|
-
requestBody,
|
|
100
|
-
responseBody
|
|
101
|
-
// acceptedOffers: acceptedOffers4result // discontinue(2024-06-17~)
|
|
102
|
-
};
|
|
103
|
-
await repos.authorizeMoneyTransferOfferAction.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: result });
|
|
104
|
-
return { id: action.id };
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function responseBody2resultAcceptedOffer(params) {
|
|
108
|
-
const acceptedOffers = [];
|
|
109
|
-
const { typeOf, transactionNumber } = params.responseBody;
|
|
110
|
-
const amountValue = params.responseBody.object.amount.value;
|
|
111
|
-
const currency = params.responseBody.object.amount.currency;
|
|
112
|
-
const itemOffered = {
|
|
113
|
-
typeOf: factory.actionType.MoneyTransfer,
|
|
114
|
-
amount: {
|
|
115
|
-
typeOf: 'MonetaryAmount',
|
|
116
|
-
value: amountValue,
|
|
117
|
-
currency
|
|
118
|
-
},
|
|
119
|
-
toLocation: {
|
|
120
|
-
typeOf: params.object.itemOffered.toLocation.typeOf,
|
|
121
|
-
// いったんマスク
|
|
122
|
-
identifier: 'xxx',
|
|
123
|
-
issuedThrough: { id: params.object.itemOffered.toLocation.issuedThrough?.id }
|
|
124
|
-
},
|
|
125
|
-
object: {
|
|
126
|
-
// MonetaryAmountの識別子として、MoneyTransfer取引番号をセットする
|
|
127
|
-
pendingTransaction: { typeOf, transactionNumber }
|
|
128
|
-
},
|
|
129
|
-
name: `${amountValue} ${currency}`
|
|
130
|
-
};
|
|
131
|
-
acceptedOffers.push({
|
|
132
|
-
typeOf: factory.offerType.Offer,
|
|
133
|
-
itemOffered,
|
|
134
|
-
serialNumber: transactionNumber
|
|
135
|
-
});
|
|
136
|
-
return acceptedOffers;
|
|
137
|
-
}
|
|
138
|
-
function createAuthorizeMoneyTransferOfferActionattributes(params) {
|
|
139
|
-
const transaction = params.transaction;
|
|
140
|
-
const seller = transaction.seller;
|
|
141
|
-
return {
|
|
142
|
-
project: transaction.project,
|
|
143
|
-
typeOf: factory.actionType.AuthorizeAction,
|
|
144
|
-
instrument: {
|
|
145
|
-
typeOf: factory.assetTransactionType.MoneyTransfer,
|
|
146
|
-
transactionNumber: params.transactionNumber
|
|
147
|
-
},
|
|
148
|
-
object: {
|
|
149
|
-
project: { typeOf: transaction.project.typeOf, id: transaction.project.id },
|
|
150
|
-
typeOf: factory.offerType.Offer,
|
|
151
|
-
itemOffered: {
|
|
152
|
-
typeOf: factory.actionType.MoneyTransfer,
|
|
153
|
-
amount: params.object.itemOffered.amount,
|
|
154
|
-
toLocation: params.object.itemOffered.toLocation,
|
|
155
|
-
object: {
|
|
156
|
-
pendingTransaction: {
|
|
157
|
-
typeOf: factory.assetTransactionType.MoneyTransfer,
|
|
158
|
-
transactionNumber: params.transactionNumber
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
...(typeof params.object.itemOffered.description === 'string')
|
|
162
|
-
? { description: params.object.itemOffered.description }
|
|
163
|
-
: undefined,
|
|
164
|
-
...(typeof params.object.itemOffered.name === 'string')
|
|
165
|
-
? { name: params.object.itemOffered.name }
|
|
166
|
-
: undefined
|
|
167
|
-
},
|
|
168
|
-
seller: {
|
|
169
|
-
// ...transaction.seller,
|
|
170
|
-
// project: transaction.project,
|
|
171
|
-
id: transaction.seller.id,
|
|
172
|
-
typeOf: transaction.seller.typeOf,
|
|
173
|
-
name: (typeof transaction.seller.name === 'string')
|
|
174
|
-
? transaction.seller.name
|
|
175
|
-
: String(transaction.seller.name?.ja)
|
|
176
|
-
},
|
|
177
|
-
priceCurrency: factory.priceCurrency.JPY
|
|
178
|
-
},
|
|
179
|
-
agent: {
|
|
180
|
-
id: seller.id,
|
|
181
|
-
typeOf: seller.typeOf,
|
|
182
|
-
name: (typeof seller.name === 'string')
|
|
183
|
-
? seller.name
|
|
184
|
-
: String(seller.name?.ja)
|
|
185
|
-
},
|
|
186
|
-
recipient: {
|
|
187
|
-
id: transaction.agent.id,
|
|
188
|
-
typeOf: transaction.agent.typeOf
|
|
189
|
-
},
|
|
190
|
-
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function processStartDepositTransaction(params) {
|
|
194
|
-
return async (repos) => {
|
|
195
|
-
const description = `for ${params.transaction.typeOf} Transaction ${params.transaction.id}`;
|
|
196
|
-
// 最大1ヵ月のオーソリ
|
|
197
|
-
const expires = (0, moment_1.default)()
|
|
198
|
-
.add(1, 'month')
|
|
199
|
-
.toDate();
|
|
200
|
-
const toLocation = {
|
|
201
|
-
typeOf: factory.permit.PermitType.Permit,
|
|
202
|
-
identifier: params.object.itemOffered.toLocation.identifier,
|
|
203
|
-
issuedThrough: { id: params.object.itemOffered.toLocation.issuedThrough?.id }
|
|
204
|
-
};
|
|
205
|
-
// 販売者が取引人に入金
|
|
206
|
-
const requestBody = {
|
|
207
|
-
typeOf: factory.assetTransactionType.MoneyTransfer,
|
|
208
|
-
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
209
|
-
transactionNumber: params.transactionNumber,
|
|
210
|
-
agent: {
|
|
211
|
-
// project: params.transaction.project,
|
|
212
|
-
typeOf: params.transaction.seller.typeOf,
|
|
213
|
-
id: String(params.transaction.seller.id),
|
|
214
|
-
name: (typeof params.transaction.seller.name === 'string')
|
|
215
|
-
? params.transaction.seller.name
|
|
216
|
-
: String(params.transaction.seller.name?.ja)
|
|
217
|
-
},
|
|
218
|
-
object: {
|
|
219
|
-
amount: {
|
|
220
|
-
typeOf: 'MonetaryAmount',
|
|
221
|
-
value: Number(params.object.itemOffered.amount.value),
|
|
222
|
-
currency: ''
|
|
223
|
-
},
|
|
224
|
-
fromLocation: {
|
|
225
|
-
typeOf: params.transaction.agent.typeOf,
|
|
226
|
-
id: params.transaction.agent.id,
|
|
227
|
-
name: (typeof params.transaction.agent.name === 'string')
|
|
228
|
-
? params.transaction.agent.name
|
|
229
|
-
: `${params.transaction.typeOf} Transaction ${params.transaction.id}`
|
|
230
|
-
},
|
|
231
|
-
toLocation,
|
|
232
|
-
description: description,
|
|
233
|
-
pendingTransaction: {
|
|
234
|
-
typeOf: factory.account.transactionType.Deposit,
|
|
235
|
-
transactionNumber: params.transactionNumber
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
recipient: {
|
|
239
|
-
typeOf: params.transaction.agent.typeOf,
|
|
240
|
-
id: params.transaction.agent.id,
|
|
241
|
-
name: (typeof params.transaction.agent.name === 'string')
|
|
242
|
-
? params.transaction.agent.name
|
|
243
|
-
: `${params.transaction.typeOf} Transaction ${params.transaction.id}`
|
|
244
|
-
},
|
|
245
|
-
expires: expires
|
|
246
|
-
};
|
|
247
|
-
const responseBody = await MoneyTransferAssetTransactionService.start(requestBody)(repos);
|
|
248
|
-
return { requestBody, responseBody };
|
|
249
|
-
};
|
|
250
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as factory from '../../../factory';
|
|
2
|
-
import type { ActionRepo } from '../../../repo/action';
|
|
3
|
-
import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
|
|
4
|
-
import type { ProductRepo } from '../../../repo/product';
|
|
5
|
-
import type { ProjectRepo } from '../../../repo/project';
|
|
6
|
-
import type { TransactionNumberRepo } from '../../../repo/transactionNumber';
|
|
7
|
-
/**
|
|
8
|
-
* 入金を返却する
|
|
9
|
-
*/
|
|
10
|
-
export declare function returnMoneyTransfer(params: factory.task.IData<factory.taskName.ReturnMoneyTransfer>): (repos: {
|
|
11
|
-
action: ActionRepo;
|
|
12
|
-
assetTransaction: AssetTransactionRepo;
|
|
13
|
-
product: ProductRepo;
|
|
14
|
-
project: ProjectRepo;
|
|
15
|
-
transactionNumber: TransactionNumberRepo;
|
|
16
|
-
}) => Promise<void>;
|