@chevre/domain 27.1.0-alpha.9 → 28.0.0-alpha.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/lib/chevre/repo/mongoose/schemas/transaction.js +11 -61
- package/lib/chevre/repo/transaction/returnOrderInProgress.d.ts +3 -1
- package/lib/chevre/repository.d.ts +0 -5
- package/lib/chevre/repository.js +0 -11
- 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 +6 -5
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.d.ts +1 -1
- package/lib/chevre/service/transaction/returnOrder.d.ts +4 -31
- package/lib/chevre/service/transaction/returnOrder.js +35 -110
- package/lib/chevre/service/transaction.d.ts +0 -2
- package/lib/chevre/service/transaction.js +1 -7
- package/package.json +1 -1
- package/lib/chevre/repo/transaction/returnOrder.d.ts +0 -45
- package/lib/chevre/repo/transaction/returnOrder.js +0 -294
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +0 -19
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +0 -104
|
@@ -97,15 +97,6 @@ const indexes = [
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
],
|
|
100
|
-
[
|
|
101
|
-
{ 'object.order.orderNumber': 1, startDate: -1 },
|
|
102
|
-
{
|
|
103
|
-
name: 'searchByObjectOrderNumberAndStartDate',
|
|
104
|
-
partialFilterExpression: {
|
|
105
|
-
'object.order.orderNumber': { $exists: true }
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
100
|
[
|
|
110
101
|
// 注文取引のobject.orderNumberも発行されている場合ユニークなはず(2026-02-21~)
|
|
111
102
|
{
|
|
@@ -121,19 +112,6 @@ const indexes = [
|
|
|
121
112
|
}
|
|
122
113
|
}
|
|
123
114
|
],
|
|
124
|
-
[
|
|
125
|
-
// ひとつの注文取引に対する確定返品取引はユニークなはず
|
|
126
|
-
{ 'object.order.orderNumber': 1 },
|
|
127
|
-
{
|
|
128
|
-
name: 'object.order.orderNumber_1',
|
|
129
|
-
unique: true,
|
|
130
|
-
partialFilterExpression: {
|
|
131
|
-
typeOf: factory_1.factory.transactionType.ReturnOrder, // 返品取引
|
|
132
|
-
status: factory_1.factory.transactionStatusType.Confirmed, // 確定ステータス
|
|
133
|
-
'object.order.orderNumber': { $exists: true }
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
],
|
|
137
115
|
[
|
|
138
116
|
{ 'agent.typeOf': 1, startDate: -1 },
|
|
139
117
|
{
|
|
@@ -210,55 +188,27 @@ const indexes = [
|
|
|
210
188
|
'tasksExportAction.startDate': { $exists: true }
|
|
211
189
|
}
|
|
212
190
|
}
|
|
213
|
-
]
|
|
214
|
-
//
|
|
215
|
-
// [
|
|
216
|
-
// { 'result.order.confirmationNumber': 1, startDate: -1 },
|
|
217
|
-
// {
|
|
218
|
-
// name: 'searchByResultOrderConfirmationNumber',
|
|
219
|
-
// partialFilterExpression: {
|
|
220
|
-
// 'result.order.confirmationNumber': { $exists: true }
|
|
221
|
-
// }
|
|
222
|
-
// }
|
|
223
|
-
// ],
|
|
224
|
-
// [
|
|
225
|
-
// { 'result.order.orderNumber': 1, startDate: -1 },
|
|
226
|
-
// {
|
|
227
|
-
// name: 'searchByResultOrderNumberAndStartDate',
|
|
228
|
-
// partialFilterExpression: {
|
|
229
|
-
// 'result.order.orderNumber': { $exists: true }
|
|
230
|
-
// }
|
|
231
|
-
// }
|
|
232
|
-
// ],
|
|
233
|
-
// result.order廃止につきインデックス廃止(2026-06-28~)
|
|
191
|
+
],
|
|
192
|
+
// typeOf: ReturnOrder廃止につき以下廃止(2026-09-08~)
|
|
234
193
|
// [
|
|
235
|
-
//
|
|
194
|
+
// { 'object.order.orderNumber': 1, startDate: -1 },
|
|
236
195
|
// {
|
|
237
|
-
//
|
|
238
|
-
// 'result.order.orderNumber': 1
|
|
239
|
-
// },
|
|
240
|
-
// {
|
|
241
|
-
// name: 'searchPlaceOrderByOrderNumber',
|
|
242
|
-
// unique: true,
|
|
196
|
+
// name: 'searchByObjectOrderNumberAndStartDate',
|
|
243
197
|
// partialFilterExpression: {
|
|
244
|
-
// '
|
|
198
|
+
// 'object.order.orderNumber': { $exists: true }
|
|
245
199
|
// }
|
|
246
200
|
// }
|
|
247
201
|
// ],
|
|
248
|
-
// uniquePlacingOrderNumberと重複しているので廃止(2026-06-28~)
|
|
249
202
|
// [
|
|
250
|
-
// //
|
|
251
|
-
// {
|
|
252
|
-
// typeOf: 1,
|
|
253
|
-
// 'object.orderNumber': 1
|
|
254
|
-
// },
|
|
203
|
+
// // ひとつの注文取引に対する確定返品取引はユニークなはず
|
|
204
|
+
// { 'object.order.orderNumber': 1 },
|
|
255
205
|
// {
|
|
256
|
-
// name: '
|
|
206
|
+
// name: 'object.order.orderNumber_1',
|
|
257
207
|
// unique: true,
|
|
258
208
|
// partialFilterExpression: {
|
|
259
|
-
// typeOf: factory.transactionType.
|
|
260
|
-
//
|
|
261
|
-
//
|
|
209
|
+
// typeOf: factory.transactionType.ReturnOrder, // 返品取引
|
|
210
|
+
// status: factory.transactionStatusType.Confirmed, // 確定ステータス
|
|
211
|
+
// 'object.order.orderNumber': { $exists: true }
|
|
262
212
|
// }
|
|
263
213
|
// }
|
|
264
214
|
// ],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RedisClientType } from '@redis/client';
|
|
2
2
|
import { factory } from '../../factory';
|
|
3
|
-
|
|
3
|
+
type IStartedTransactionFields = 'expires' | 'id' | 'startDate' | 'status';
|
|
4
|
+
export type IStartedTransaction = Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IStartedTransactionFields>;
|
|
4
5
|
/**
|
|
5
6
|
* 返品取引リポジトリ
|
|
6
7
|
*/
|
|
@@ -17,3 +18,4 @@ export declare class ReturnOrderInProgressRepo {
|
|
|
17
18
|
id: string;
|
|
18
19
|
}): Promise<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>>;
|
|
19
20
|
}
|
|
21
|
+
export {};
|
|
@@ -113,7 +113,6 @@ import type { TaskDelayedRepo } from './repo/taskDelayed';
|
|
|
113
113
|
import type { TicketRepo } from './repo/ticket';
|
|
114
114
|
import type { TransactionRepo } from './repo/transaction';
|
|
115
115
|
import type { PlaceOrderRepo } from './repo/transaction/placeOrder';
|
|
116
|
-
import type { ReturnOrderRepo } from './repo/transaction/returnOrder';
|
|
117
116
|
import type { ReturnOrderInProgressRepo } from './repo/transaction/returnOrderInProgress';
|
|
118
117
|
import type { TransactionNumberRepo } from './repo/transactionNumber';
|
|
119
118
|
import type { TransactionProcessRepo } from './repo/transactionProcess';
|
|
@@ -604,10 +603,6 @@ export declare namespace transaction {
|
|
|
604
603
|
namespace PlaceOrder {
|
|
605
604
|
function createInstance(...params: ConstructorParameters<typeof PlaceOrderRepo>): Promise<PlaceOrderRepo>;
|
|
606
605
|
}
|
|
607
|
-
type ReturnOrder = ReturnOrderRepo;
|
|
608
|
-
namespace ReturnOrder {
|
|
609
|
-
function createInstance(...params: ConstructorParameters<typeof ReturnOrderRepo>): Promise<ReturnOrderRepo>;
|
|
610
|
-
}
|
|
611
606
|
type ReturnOrderInProgress = ReturnOrderInProgressRepo;
|
|
612
607
|
namespace ReturnOrderInProgress {
|
|
613
608
|
function createInstance(...params: ConstructorParameters<typeof ReturnOrderInProgressRepo>): Promise<ReturnOrderInProgressRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -1288,17 +1288,6 @@ var transaction;
|
|
|
1288
1288
|
}
|
|
1289
1289
|
PlaceOrder.createInstance = createInstance;
|
|
1290
1290
|
})(PlaceOrder = transaction.PlaceOrder || (transaction.PlaceOrder = {}));
|
|
1291
|
-
let ReturnOrder;
|
|
1292
|
-
(function (ReturnOrder) {
|
|
1293
|
-
let repo;
|
|
1294
|
-
async function createInstance(...params) {
|
|
1295
|
-
if (repo === undefined) {
|
|
1296
|
-
repo = (await import('./repo/transaction/returnOrder.js')).ReturnOrderRepo;
|
|
1297
|
-
}
|
|
1298
|
-
return new repo(...params);
|
|
1299
|
-
}
|
|
1300
|
-
ReturnOrder.createInstance = createInstance;
|
|
1301
|
-
})(ReturnOrder = transaction.ReturnOrder || (transaction.ReturnOrder = {}));
|
|
1302
1291
|
let ReturnOrderInProgress;
|
|
1303
1292
|
(function (ReturnOrderInProgress) {
|
|
1304
1293
|
let repo;
|
|
@@ -11,7 +11,6 @@ const note_1 = require("../../repo/note");
|
|
|
11
11
|
const order_1 = require("../../repo/order");
|
|
12
12
|
const reservation_1 = require("../../repo/reservation");
|
|
13
13
|
const placeOrder_1 = require("../../repo/transaction/placeOrder");
|
|
14
|
-
const returnOrder_1 = require("../../repo/transaction/returnOrder");
|
|
15
14
|
const transaction_1 = require("../transaction");
|
|
16
15
|
/**
|
|
17
16
|
* タスク実行関数
|
|
@@ -32,7 +31,6 @@ function call(params) {
|
|
|
32
31
|
order: new order_1.OrderRepo(connection),
|
|
33
32
|
reservation: new reservation_1.ReservationRepo(connection),
|
|
34
33
|
placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
|
|
35
|
-
returnOrder: new returnOrder_1.ReturnOrderRepo(connection),
|
|
36
34
|
});
|
|
37
35
|
};
|
|
38
36
|
}
|
|
@@ -9,7 +9,6 @@ import type { NoteRepo } from '../../repo/note';
|
|
|
9
9
|
import type { OrderRepo } from '../../repo/order';
|
|
10
10
|
import type { ReservationRepo } from '../../repo/reservation';
|
|
11
11
|
import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
|
|
12
|
-
import type { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
|
|
13
12
|
interface IDeleteTransactionRepos {
|
|
14
13
|
acceptedOffer: AcceptedOfferRepo;
|
|
15
14
|
adminAccountingReport: AdminAccountingReportRepo;
|
|
@@ -23,7 +22,6 @@ interface IDeleteTransactionRepos {
|
|
|
23
22
|
order: OrderRepo;
|
|
24
23
|
reservation: ReservationRepo;
|
|
25
24
|
placeOrder: PlaceOrderRepo;
|
|
26
|
-
returnOrder: ReturnOrderRepo;
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* 取引に関わるリソースを削除する
|
|
@@ -41,11 +41,12 @@ function deleteTransactionById(params) {
|
|
|
41
41
|
})).shift();
|
|
42
42
|
}
|
|
43
43
|
else if (params.object.typeOf === factory_1.factory.transactionType.ReturnOrder) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
// 廃止済(ドキュメントはマニュアルで削除済)につき何もしない(2026-09-08~)
|
|
45
|
+
// transaction = (await repos.returnOrder.findReturnOrderTransactions({
|
|
46
|
+
// ids: [deletingTransactionId],
|
|
47
|
+
// typeOf: params.object.typeOf,
|
|
48
|
+
// inclusion: ['typeOf', 'project', 'status']
|
|
49
|
+
// })).shift();
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
52
|
throw new factory_1.factory.errors.NotImplemented(`object not implemented. typeOf:${params.object.typeOf}`);
|
package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { factory } from '../../../../factory';
|
|
2
2
|
import type { ISetting } from '../../../../repo/setting';
|
|
3
3
|
export declare function createReturnPaymentMethodActions(params: {
|
|
4
|
-
order: Pick<factory.order.IOrder, 'confirmationNumber' | 'customer' | 'orderDate' | 'orderNumber' | '
|
|
4
|
+
order: Pick<factory.order.IOrder, 'confirmationNumber' | 'customer' | 'orderDate' | 'orderNumber' | 'orderedItem' | 'paymentMethods' | 'price' | 'priceCurrency' | 'seller' | 'typeOf'>;
|
|
5
5
|
returnOrderActionParams?: factory.transaction.returnOrder.IReturnOrderActionParams;
|
|
6
6
|
transaction: Pick<factory.transaction.returnOrder.ITransaction, 'object'>;
|
|
7
7
|
}, setting: Pick<ISetting, 'defaultSenderEmail'>): Promise<{
|
|
@@ -11,10 +11,8 @@ import type { ReservationRepo } from '../../repo/reservation';
|
|
|
11
11
|
import type { SellerRepo } from '../../repo/seller';
|
|
12
12
|
import type { SellerReturnPolicyRepo } from '../../repo/sellerReturnPolicy';
|
|
13
13
|
import type { SettingRepo } from '../../repo/setting';
|
|
14
|
-
import type { ScheduledTaskRepo } from '../../repo/scheduledTask';
|
|
15
14
|
import type { TaskRepo } from '../../repo/task';
|
|
16
|
-
import type { IStartedTransaction,
|
|
17
|
-
import type { ReturnOrderInProgressRepo } from '../../repo/transaction/returnOrderInProgress';
|
|
15
|
+
import type { IStartedTransaction, ReturnOrderInProgressRepo } from '../../repo/transaction/returnOrderInProgress';
|
|
18
16
|
import { preStart } from './returnOrder/preStart';
|
|
19
17
|
interface IStartOperationRepos {
|
|
20
18
|
acceptedOffer: AcceptedOfferRepo;
|
|
@@ -27,29 +25,18 @@ interface IStartOperationRepos {
|
|
|
27
25
|
reservation: ReservationRepo;
|
|
28
26
|
seller: SellerRepo;
|
|
29
27
|
sellerReturnPolicy: SellerReturnPolicyRepo;
|
|
30
|
-
returnOrder: ReturnOrderRepo;
|
|
31
28
|
returnOrderInProgress: ReturnOrderInProgressRepo;
|
|
32
29
|
}
|
|
33
30
|
type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
|
|
34
|
-
interface IExportTasksByIdRepos {
|
|
35
|
-
setting: SettingRepo;
|
|
36
|
-
scheduledTask: ScheduledTaskRepo;
|
|
37
|
-
task: TaskRepo;
|
|
38
|
-
returnOrder: ReturnOrderRepo;
|
|
39
|
-
}
|
|
40
|
-
type ITaskAndTransactionOperation<T> = (repos: IExportTasksByIdRepos) => Promise<T>;
|
|
41
31
|
/**
|
|
42
32
|
* 返品取引開始
|
|
43
33
|
*/
|
|
44
|
-
declare function start(params: factory.transaction.returnOrder.IStartParamsWithoutDetail
|
|
45
|
-
useConfirmReturnOrderTask: boolean;
|
|
46
|
-
}): IStartOperation<IStartedTransaction>;
|
|
34
|
+
declare function start(params: factory.transaction.returnOrder.IStartParamsWithoutDetail): IStartOperation<IStartedTransaction>;
|
|
47
35
|
interface IConfirmRepos {
|
|
48
36
|
acceptedOffer: AcceptedOfferRepo;
|
|
49
37
|
message: MessageRepo;
|
|
50
38
|
order: OrderRepo;
|
|
51
39
|
setting: SettingRepo;
|
|
52
|
-
returnOrder: ReturnOrderRepo;
|
|
53
40
|
returnOrderInProgress: ReturnOrderInProgressRepo;
|
|
54
41
|
task: TaskRepo;
|
|
55
42
|
}
|
|
@@ -62,19 +49,5 @@ declare function confirm(params: factory.transaction.returnOrder.IConfirmParams
|
|
|
62
49
|
dateReturned: Date;
|
|
63
50
|
};
|
|
64
51
|
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}): (repos: IConfirmRepos) => Promise<import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined>;
|
|
68
|
-
/**
|
|
69
|
-
* 取引のタスクを出力します
|
|
70
|
-
* 複数タスクが生成されます
|
|
71
|
-
* この関数では、取引のタスクエクスポートステータスは見ません
|
|
72
|
-
*/
|
|
73
|
-
declare function exportTasksById(params: {
|
|
74
|
-
id: string;
|
|
75
|
-
/**
|
|
76
|
-
* タスク実行日時バッファ
|
|
77
|
-
*/
|
|
78
|
-
runsTasksAfterInSeconds?: number;
|
|
79
|
-
}): ITaskAndTransactionOperation<void>;
|
|
80
|
-
export { IStartOperationRepos, IConfirmRepos, IExportTasksByIdRepos, preStart, start, confirm, exportTasksById };
|
|
52
|
+
}): (repos: IConfirmRepos) => Promise<import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult>;
|
|
53
|
+
export { IStartOperationRepos, IConfirmRepos, preStart, start, confirm, };
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.preStart = void 0;
|
|
7
4
|
exports.start = start;
|
|
8
5
|
exports.confirm = confirm;
|
|
9
|
-
exports.exportTasksById = exportTasksById;
|
|
10
6
|
/**
|
|
11
7
|
* 返品取引サービス
|
|
12
8
|
*/
|
|
13
|
-
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
14
9
|
const util_1 = require("util");
|
|
15
10
|
const factory_1 = require("../../factory");
|
|
16
|
-
const factory_2 = require("./returnOrder/exportTasks/factory");
|
|
17
11
|
const potentialActions_1 = require("./returnOrder/potentialActions");
|
|
18
12
|
const preStart_1 = require("./returnOrder/preStart");
|
|
19
13
|
Object.defineProperty(exports, "preStart", { enumerable: true, get: function () { return preStart_1.preStart; } });
|
|
20
|
-
const errorHandler_1 = require("../../errorHandler");
|
|
21
14
|
/**
|
|
22
15
|
* 返品取引開始
|
|
23
16
|
*/
|
|
24
|
-
function start(params
|
|
17
|
+
function start(params) {
|
|
25
18
|
return async (repos) => {
|
|
26
|
-
const { useConfirmReturnOrderTask } = options;
|
|
27
19
|
const { transactionObject, expiresInSeconds, seller } = await (0, preStart_1.preStart)(params)(repos);
|
|
28
20
|
const returnOrderAttributes = {
|
|
29
21
|
project: params.project,
|
|
@@ -37,23 +29,7 @@ function start(params, options) {
|
|
|
37
29
|
object: transactionObject,
|
|
38
30
|
expiresInSeconds
|
|
39
31
|
};
|
|
40
|
-
|
|
41
|
-
if (useConfirmReturnOrderTask) {
|
|
42
|
-
returnOrderTransaction = await repos.returnOrderInProgress.startReturnOrder(returnOrderAttributes);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
try {
|
|
46
|
-
returnOrderTransaction = await repos.returnOrder.startReturnOrder(returnOrderAttributes);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
|
|
50
|
-
// 同一取引に対して返品取引を作成しようとすると、MongoDBでE11000 duplicate key errorが発生する
|
|
51
|
-
throw new factory_1.factory.errors.Argument('orderNumber', 'Already returned');
|
|
52
|
-
}
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return returnOrderTransaction;
|
|
32
|
+
return repos.returnOrderInProgress.startReturnOrder(returnOrderAttributes);
|
|
57
33
|
};
|
|
58
34
|
}
|
|
59
35
|
function saveMessagesIfNeeded(params) {
|
|
@@ -85,26 +61,9 @@ function saveMessagesIfNeeded(params) {
|
|
|
85
61
|
/**
|
|
86
62
|
* 取引確定
|
|
87
63
|
*/
|
|
88
|
-
function confirm(params
|
|
64
|
+
function confirm(params) {
|
|
89
65
|
return async (repos) => {
|
|
90
|
-
const {
|
|
91
|
-
let transaction;
|
|
92
|
-
if (useConfirmReturnOrderTask) {
|
|
93
|
-
transaction = await repos.returnOrderInProgress.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id });
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'agent', 'object', 'result', 'startDate']);
|
|
97
|
-
if (transaction.status === factory_1.factory.transactionStatusType.Confirmed) {
|
|
98
|
-
// すでに確定済の場合
|
|
99
|
-
return transaction.result;
|
|
100
|
-
}
|
|
101
|
-
else if (transaction.status === factory_1.factory.transactionStatusType.Expired) {
|
|
102
|
-
throw new factory_1.factory.errors.Argument('transaction', 'Transaction already expired');
|
|
103
|
-
}
|
|
104
|
-
else if (transaction.status === factory_1.factory.transactionStatusType.Canceled) {
|
|
105
|
-
throw new factory_1.factory.errors.Argument('transaction', 'Transaction already canceled');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
66
|
+
const transaction = await repos.returnOrderInProgress.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id });
|
|
108
67
|
if (typeof params.agent?.id === 'string' && transaction.agent.id !== params.agent.id) {
|
|
109
68
|
throw new factory_1.factory.errors.Forbidden('Transaction not yours');
|
|
110
69
|
}
|
|
@@ -113,7 +72,7 @@ function confirm(params, options) {
|
|
|
113
72
|
throw new factory_1.factory.errors.Argument('object.order', 'number of orders must be 1');
|
|
114
73
|
}
|
|
115
74
|
const returningOrders = await repos.order.projectFields({
|
|
116
|
-
limit: 1,
|
|
75
|
+
limit: 1, // 1に限定なので1で十分
|
|
117
76
|
page: 1,
|
|
118
77
|
project: { id: { $eq: transaction.project.id } },
|
|
119
78
|
confirmationNumbers: [transaction.object.order[0].confirmationNumber],
|
|
@@ -124,6 +83,14 @@ function confirm(params, options) {
|
|
|
124
83
|
'orderedItem', 'paymentMethods', 'price', 'priceCurrency', 'project', 'seller', 'typeOf'
|
|
125
84
|
]
|
|
126
85
|
});
|
|
86
|
+
if (returningOrders.length === 0) {
|
|
87
|
+
throw new factory_1.factory.errors.NotFound(factory_1.factory.order.OrderType.Order);
|
|
88
|
+
}
|
|
89
|
+
// 既に返品済であれば400(2026-09-08~)
|
|
90
|
+
const orderStatus = returningOrders[0].orderStatus;
|
|
91
|
+
if (orderStatus === factory_1.factory.orderStatus.OrderReturned) {
|
|
92
|
+
throw new factory_1.factory.errors.Argument('orderNumber', `invalid orderStatus: ${orderStatus}`);
|
|
93
|
+
}
|
|
127
94
|
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['defaultSenderEmail']);
|
|
128
95
|
if (typeof setting?.defaultSenderEmail !== 'string') {
|
|
129
96
|
throw new factory_1.factory.errors.NotFound('setting.defaultSenderEmail');
|
|
@@ -143,72 +110,30 @@ function confirm(params, options) {
|
|
|
143
110
|
project: { id: transaction.project.id },
|
|
144
111
|
order: { orderNumber: returningOrders[0].orderNumber }, seller: { id: returningOrders[0].seller.id }, emailMessages
|
|
145
112
|
})(repos);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
data: {
|
|
160
|
-
typeOf: transaction.typeOf,
|
|
161
|
-
id: transaction.id,
|
|
162
|
-
agent: transaction.agent,
|
|
163
|
-
startDate: transaction.startDate,
|
|
164
|
-
object: transaction.object,
|
|
165
|
-
project: transaction.project,
|
|
166
|
-
potentialActions,
|
|
167
|
-
endDate
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
await repos.task.runTaskByIdentifier(confirmReturnOrderTask);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// ステータス変更
|
|
174
|
-
await repos.returnOrder.confirmReturnOrder({
|
|
113
|
+
// タスク作成(注文番号でユニークネス保証)
|
|
114
|
+
const taskIdentifier = (0, util_1.format)('%s:%s:%s', transaction.project.id, factory_1.factory.taskName.ConfirmReturnOrder, returningOrders[0].orderNumber);
|
|
115
|
+
const endDate = new Date();
|
|
116
|
+
const confirmReturnOrderTask = {
|
|
117
|
+
identifier: taskIdentifier,
|
|
118
|
+
project: transaction.project,
|
|
119
|
+
name: factory_1.factory.taskName.ConfirmReturnOrder,
|
|
120
|
+
status: factory_1.factory.taskStatus.Ready,
|
|
121
|
+
runsAt: endDate,
|
|
122
|
+
remainingNumberOfTries: 10,
|
|
123
|
+
numberOfTried: 0,
|
|
124
|
+
executionResults: [],
|
|
125
|
+
data: {
|
|
175
126
|
typeOf: transaction.typeOf,
|
|
176
127
|
id: transaction.id,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
128
|
+
agent: transaction.agent,
|
|
129
|
+
startDate: transaction.startDate,
|
|
130
|
+
object: transaction.object,
|
|
131
|
+
project: transaction.project,
|
|
132
|
+
potentialActions,
|
|
133
|
+
endDate
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
await repos.task.runTaskByIdentifier(confirmReturnOrderTask);
|
|
180
137
|
return result;
|
|
181
138
|
};
|
|
182
139
|
}
|
|
183
|
-
/**
|
|
184
|
-
* 取引のタスクを出力します
|
|
185
|
-
* 複数タスクが生成されます
|
|
186
|
-
* この関数では、取引のタスクエクスポートステータスは見ません
|
|
187
|
-
*/
|
|
188
|
-
function exportTasksById(params) {
|
|
189
|
-
return async (repos) => {
|
|
190
|
-
const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
|
|
191
|
-
// タスク実行日時バッファの指定があれば調整
|
|
192
|
-
let taskRunsAt = new Date();
|
|
193
|
-
if (typeof params.runsTasksAfterInSeconds === 'number') {
|
|
194
|
-
taskRunsAt = (0, moment_timezone_1.default)(taskRunsAt)
|
|
195
|
-
.add(params.runsTasksAfterInSeconds, 'seconds')
|
|
196
|
-
.toDate();
|
|
197
|
-
}
|
|
198
|
-
// search settings
|
|
199
|
-
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
|
|
200
|
-
const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
|
|
201
|
-
if (typeof deleteTransactionTaskExpiresInDays !== 'number') {
|
|
202
|
-
throw new factory_1.factory.errors.Internal('settings.storage.deleteTransactionTaskExpiresInDays required');
|
|
203
|
-
}
|
|
204
|
-
const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
|
|
205
|
-
// support scheduledTask(2026-08-02~)
|
|
206
|
-
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
207
|
-
await repos.scheduledTask.addScheduledTasks([{
|
|
208
|
-
...deleteTask,
|
|
209
|
-
expires: (0, moment_timezone_1.default)(deleteTask.runsAt)
|
|
210
|
-
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
211
|
-
.toDate()
|
|
212
|
-
}]);
|
|
213
|
-
};
|
|
214
|
-
}
|
|
@@ -7,7 +7,6 @@ import type { ScheduledTaskRepo } from '../repo/scheduledTask';
|
|
|
7
7
|
import type { TaskRepo } from '../repo/task';
|
|
8
8
|
import type { TransactionRepo } from '../repo/transaction';
|
|
9
9
|
import type { PlaceOrderRepo } from '../repo/transaction/placeOrder';
|
|
10
|
-
import type { ReturnOrderRepo } from '../repo/transaction/returnOrder';
|
|
11
10
|
import { deleteTransaction } from './transaction/deleteTransaction';
|
|
12
11
|
import * as PlaceOrderTransactionService from './transaction/placeOrder';
|
|
13
12
|
import * as ReturnOrderTransactionService from './transaction/returnOrder';
|
|
@@ -22,7 +21,6 @@ export type IExportTasksOperation<T> = (repos: {
|
|
|
22
21
|
scheduledTask: ScheduledTaskRepo;
|
|
23
22
|
task: TaskRepo;
|
|
24
23
|
placeOrder: PlaceOrderRepo;
|
|
25
|
-
returnOrder: ReturnOrderRepo;
|
|
26
24
|
transaction: TransactionRepo;
|
|
27
25
|
}) => Promise<T>;
|
|
28
26
|
export declare function exportOneTransactionTasksIfExists(params: {
|
|
@@ -70,13 +70,7 @@ function exportOneTransactionTasksIfExists(params) {
|
|
|
70
70
|
})(repos);
|
|
71
71
|
break;
|
|
72
72
|
case factory_1.factory.transactionType.ReturnOrder:
|
|
73
|
-
|
|
74
|
-
id: transaction.id,
|
|
75
|
-
...(typeof params.runsTasksAfterInSeconds === 'number')
|
|
76
|
-
? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
|
|
77
|
-
: undefined
|
|
78
|
-
})(repos);
|
|
79
|
-
break;
|
|
73
|
+
throw new factory_1.factory.errors.NotImplemented(`${factory_1.factory.transactionType.ReturnOrder} not implemented`);
|
|
80
74
|
default:
|
|
81
75
|
}
|
|
82
76
|
await repos.transaction.setTasksExportedById({ id: transaction.id });
|
package/package.json
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
|
-
import { factory } from '../../factory';
|
|
3
|
-
type IKeyOfProjection = keyof Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'agent' | 'endDate' | 'expires' | 'project' | 'startDate' | 'status' | 'typeOf'> | Exclude<keyof factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'id'>;
|
|
4
|
-
type IStartedTransactionFields = 'expires' | 'id' | 'startDate' | 'status';
|
|
5
|
-
export type IStartedTransaction = Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IStartedTransactionFields>;
|
|
6
|
-
/**
|
|
7
|
-
* 返品取引リポジトリ
|
|
8
|
-
*/
|
|
9
|
-
export declare class ReturnOrderRepo {
|
|
10
|
-
private readonly transactionModel;
|
|
11
|
-
constructor(connection: Connection);
|
|
12
|
-
static CREATE_MONGO_CONDITIONS(params: factory.transaction.ISearchConditions<factory.transactionType.ReturnOrder>): FilterQuery<import("@chevre/factory/lib/chevre/transaction/returnOrder").ITransaction>[];
|
|
13
|
-
countReturnOrder(params: factory.transaction.ISearchConditions<factory.transactionType.ReturnOrder>): Promise<{
|
|
14
|
-
count: number;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* 取引を検索する
|
|
18
|
-
*/
|
|
19
|
-
findReturnOrderTransactions(params: factory.transaction.ISearchConditions<factory.transactionType.ReturnOrder> & {
|
|
20
|
-
inclusion: IKeyOfProjection[];
|
|
21
|
-
}): Promise<(Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IKeyOfProjection> & {
|
|
22
|
-
id: string;
|
|
23
|
-
})[]>;
|
|
24
|
-
/**
|
|
25
|
-
* 取引を開始する
|
|
26
|
-
*/
|
|
27
|
-
startReturnOrder(params: factory.transaction.IStartParams<factory.transactionType.ReturnOrder>): Promise<IStartedTransaction>;
|
|
28
|
-
/**
|
|
29
|
-
* 特定取引検索
|
|
30
|
-
*/
|
|
31
|
-
findReturnOrderById(params: {
|
|
32
|
-
typeOf: factory.transactionType.ReturnOrder;
|
|
33
|
-
id: string;
|
|
34
|
-
}, inclusion: IKeyOfProjection[]): Promise<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>>;
|
|
35
|
-
/**
|
|
36
|
-
* 取引を確定する
|
|
37
|
-
*/
|
|
38
|
-
confirmReturnOrder(params: {
|
|
39
|
-
typeOf: factory.transactionType.ReturnOrder;
|
|
40
|
-
id: string;
|
|
41
|
-
result: factory.transaction.IResult<factory.transactionType.ReturnOrder>;
|
|
42
|
-
potentialActions: factory.transaction.IPotentialActions<factory.transactionType.ReturnOrder>;
|
|
43
|
-
}): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
export {};
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ReturnOrderRepo = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const transaction_1 = require("../../eventEmitter/transaction");
|
|
9
|
-
const factory_1 = require("../../factory");
|
|
10
|
-
const settings_1 = require("../../settings");
|
|
11
|
-
const transaction_2 = require("../mongoose/schemas/transaction");
|
|
12
|
-
const AVAILABLE_PROJECT_FIELDS = [
|
|
13
|
-
'project',
|
|
14
|
-
'status',
|
|
15
|
-
'typeOf',
|
|
16
|
-
'agent',
|
|
17
|
-
'recipient',
|
|
18
|
-
'seller',
|
|
19
|
-
'error',
|
|
20
|
-
'result',
|
|
21
|
-
'object',
|
|
22
|
-
'expires',
|
|
23
|
-
'startDate',
|
|
24
|
-
'endDate',
|
|
25
|
-
'tasksExportAction',
|
|
26
|
-
'potentialActions',
|
|
27
|
-
// 'instrument'
|
|
28
|
-
];
|
|
29
|
-
/**
|
|
30
|
-
* 返品取引リポジトリ
|
|
31
|
-
*/
|
|
32
|
-
class ReturnOrderRepo {
|
|
33
|
-
transactionModel;
|
|
34
|
-
constructor(connection) {
|
|
35
|
-
this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
|
|
36
|
-
}
|
|
37
|
-
static CREATE_MONGO_CONDITIONS(params) {
|
|
38
|
-
if (params.typeOf !== factory_1.factory.transactionType.ReturnOrder) {
|
|
39
|
-
throw new factory_1.factory.errors.Argument('typeOf', `must be ${factory_1.factory.transactionType.ReturnOrder}`);
|
|
40
|
-
}
|
|
41
|
-
const andConditions = [];
|
|
42
|
-
const projectIdEq = params.project?.id?.$eq;
|
|
43
|
-
if (typeof projectIdEq === 'string') {
|
|
44
|
-
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
45
|
-
}
|
|
46
|
-
if (typeof params.typeOf === 'string') {
|
|
47
|
-
andConditions.push({ typeOf: { $eq: params.typeOf } });
|
|
48
|
-
}
|
|
49
|
-
if (params.startFrom !== undefined) {
|
|
50
|
-
andConditions.push({
|
|
51
|
-
startDate: { $gte: params.startFrom }
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (params.startThrough !== undefined) {
|
|
55
|
-
andConditions.push({
|
|
56
|
-
startDate: { $lte: params.startThrough }
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (params.endFrom !== undefined) {
|
|
60
|
-
andConditions.push({
|
|
61
|
-
endDate: {
|
|
62
|
-
$exists: true,
|
|
63
|
-
$gte: params.endFrom
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (params.endThrough !== undefined) {
|
|
68
|
-
andConditions.push({
|
|
69
|
-
endDate: {
|
|
70
|
-
$exists: true,
|
|
71
|
-
$lt: params.endThrough
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (Array.isArray(params.ids)) {
|
|
76
|
-
andConditions.push({
|
|
77
|
-
_id: { $in: params.ids }
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
if (Array.isArray(params.statuses)) {
|
|
81
|
-
andConditions.push({ status: { $in: params.statuses } });
|
|
82
|
-
}
|
|
83
|
-
const statusIn = params.status?.$in;
|
|
84
|
-
if (Array.isArray(statusIn)) {
|
|
85
|
-
andConditions.push({ status: { $in: statusIn } });
|
|
86
|
-
}
|
|
87
|
-
if (params.agent !== undefined) {
|
|
88
|
-
if (params.agent.typeOf !== undefined) {
|
|
89
|
-
andConditions.push({
|
|
90
|
-
'agent.typeOf': {
|
|
91
|
-
$exists: true,
|
|
92
|
-
$eq: params.agent.typeOf
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (Array.isArray(params.agent.ids)) {
|
|
97
|
-
andConditions.push({
|
|
98
|
-
'agent.id': {
|
|
99
|
-
$exists: true,
|
|
100
|
-
$in: params.agent.ids
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (Array.isArray(params.agent.identifiers)) {
|
|
105
|
-
andConditions.push({
|
|
106
|
-
'agent.identifier': {
|
|
107
|
-
$exists: true,
|
|
108
|
-
$in: params.agent.identifiers
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const tasksExportActionStatusIn = params.tasksExportAction?.actionStatus?.$in;
|
|
114
|
-
if (Array.isArray(tasksExportActionStatusIn)) {
|
|
115
|
-
andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $in: tasksExportActionStatusIn } });
|
|
116
|
-
}
|
|
117
|
-
const tasksExportActionStatusEq = params.tasksExportAction?.actionStatus?.$eq;
|
|
118
|
-
if (typeof tasksExportActionStatusEq === 'string') {
|
|
119
|
-
andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $eq: tasksExportActionStatusEq } });
|
|
120
|
-
}
|
|
121
|
-
if (params.object !== undefined) {
|
|
122
|
-
if (params.object.order !== undefined) {
|
|
123
|
-
if (Array.isArray(params.object.order.orderNumbers)) {
|
|
124
|
-
andConditions.push({
|
|
125
|
-
'object.order.orderNumber': {
|
|
126
|
-
$exists: true,
|
|
127
|
-
$in: params.object.order.orderNumbers
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return andConditions;
|
|
134
|
-
}
|
|
135
|
-
async countReturnOrder(params) {
|
|
136
|
-
const { limit } = params;
|
|
137
|
-
const conditions = ReturnOrderRepo.CREATE_MONGO_CONDITIONS(params);
|
|
138
|
-
const query = this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
|
|
139
|
-
if (typeof limit === 'number' && limit >= 0) {
|
|
140
|
-
query.limit(limit);
|
|
141
|
-
}
|
|
142
|
-
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
143
|
-
.exec();
|
|
144
|
-
return { count };
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 取引を検索する
|
|
148
|
-
*/
|
|
149
|
-
async findReturnOrderTransactions(params) {
|
|
150
|
-
const { inclusion } = params;
|
|
151
|
-
const conditions = ReturnOrderRepo.CREATE_MONGO_CONDITIONS(params);
|
|
152
|
-
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
153
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
154
|
-
positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
|
|
155
|
-
}
|
|
156
|
-
const projection = {
|
|
157
|
-
_id: 0,
|
|
158
|
-
id: { $toString: '$_id' },
|
|
159
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
160
|
-
};
|
|
161
|
-
const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
|
|
162
|
-
.select(projection);
|
|
163
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
164
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
165
|
-
query.limit(params.limit)
|
|
166
|
-
.skip(params.limit * (page - 1));
|
|
167
|
-
}
|
|
168
|
-
if (params.sort?.startDate !== undefined) {
|
|
169
|
-
query.sort({ startDate: params.sort.startDate });
|
|
170
|
-
}
|
|
171
|
-
// const explainResult = await (<any>query).explain();
|
|
172
|
-
// console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
173
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
174
|
-
.lean()
|
|
175
|
-
.exec();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* 取引を開始する
|
|
179
|
-
*/
|
|
180
|
-
async startReturnOrder(params) {
|
|
181
|
-
const status = factory_1.factory.transactionStatusType.InProgress;
|
|
182
|
-
const tasksExportAction = { actionStatus: factory_1.factory.actionStatusType.PotentialActionStatus };
|
|
183
|
-
// const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
|
|
184
|
-
const startDate = new Date();
|
|
185
|
-
let expires;
|
|
186
|
-
const { typeOf } = params;
|
|
187
|
-
// expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
|
|
188
|
-
if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
|
|
189
|
-
expires = (0, moment_1.default)(startDate)
|
|
190
|
-
.add(params.expiresInSeconds, 'seconds')
|
|
191
|
-
.toDate();
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
throw new factory_1.factory.errors.ArgumentNull('expiresInSeconds');
|
|
195
|
-
}
|
|
196
|
-
let creatingTransaction;
|
|
197
|
-
if (typeOf === factory_1.factory.transactionType.ReturnOrder) {
|
|
198
|
-
const { agent, project, object, seller } = params;
|
|
199
|
-
creatingTransaction = {
|
|
200
|
-
status, startDate, expires, typeOf, tasksExportAction,
|
|
201
|
-
agent, project, seller, object
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
throw new factory_1.factory.errors.NotImplemented(`${typeOf} not implemented`);
|
|
206
|
-
}
|
|
207
|
-
// reimplemnt with insertMany(2024-05-30~)
|
|
208
|
-
const result = await this.transactionModel.insertMany(creatingTransaction, { rawResult: true });
|
|
209
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
210
|
-
if (typeof id !== 'string') {
|
|
211
|
-
throw new factory_1.factory.errors.Internal('transaction not saved');
|
|
212
|
-
}
|
|
213
|
-
// 取引開始時にも取引イベントエミッター連携(2024-03-21~)
|
|
214
|
-
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({ id, typeOf, status });
|
|
215
|
-
return { expires, id, startDate, status }; // minimize response(2024-05-30~)
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* 特定取引検索
|
|
219
|
-
*/
|
|
220
|
-
async findReturnOrderById(params, inclusion // make required(2024-05-31~)
|
|
221
|
-
) {
|
|
222
|
-
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
223
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
224
|
-
positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
throw new factory_1.factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
|
|
228
|
-
}
|
|
229
|
-
const projection = {
|
|
230
|
-
_id: 0,
|
|
231
|
-
id: { $toString: '$_id' },
|
|
232
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
233
|
-
};
|
|
234
|
-
const doc = await this.transactionModel.findOne({
|
|
235
|
-
_id: { $eq: params.id },
|
|
236
|
-
typeOf: { $eq: params.typeOf }
|
|
237
|
-
}, projection)
|
|
238
|
-
.lean() // 2024-08-26~
|
|
239
|
-
.exec();
|
|
240
|
-
if (doc === null) {
|
|
241
|
-
throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} not found`);
|
|
242
|
-
}
|
|
243
|
-
return doc;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* 取引を確定する
|
|
247
|
-
*/
|
|
248
|
-
async confirmReturnOrder(params) {
|
|
249
|
-
const endDate = new Date();
|
|
250
|
-
const doc = await this.transactionModel.findOneAndUpdate({
|
|
251
|
-
_id: { $eq: params.id },
|
|
252
|
-
typeOf: { $eq: params.typeOf },
|
|
253
|
-
status: { $eq: factory_1.factory.transactionStatusType.InProgress },
|
|
254
|
-
expires: { $gt: endDate } // add expires(2025-02-27~)
|
|
255
|
-
}, {
|
|
256
|
-
status: factory_1.factory.transactionStatusType.Confirmed, // ステータス変更
|
|
257
|
-
endDate,
|
|
258
|
-
// 'object.authorizeActions': params.authorizeActions,
|
|
259
|
-
result: params.result, // resultを更新
|
|
260
|
-
potentialActions: params.potentialActions // resultを更新
|
|
261
|
-
}, {
|
|
262
|
-
new: true,
|
|
263
|
-
projection: { _id: 1 }
|
|
264
|
-
})
|
|
265
|
-
.lean()
|
|
266
|
-
.exec();
|
|
267
|
-
// NotFoundであれば取引状態確認
|
|
268
|
-
if (doc === null) {
|
|
269
|
-
const { expires, status } = await this.findReturnOrderById({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
|
|
270
|
-
if (status === factory_1.factory.transactionStatusType.Confirmed) {
|
|
271
|
-
// すでに確定済の場合スルー
|
|
272
|
-
}
|
|
273
|
-
else if (status === factory_1.factory.transactionStatusType.Expired) {
|
|
274
|
-
throw new factory_1.factory.errors.Argument('Transaction id', 'Already expired');
|
|
275
|
-
}
|
|
276
|
-
else if (status === factory_1.factory.transactionStatusType.Canceled) {
|
|
277
|
-
throw new factory_1.factory.errors.Argument('Transaction id', 'Already canceled');
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
if ((0, moment_1.default)(expires)
|
|
281
|
-
.isSameOrBefore((0, moment_1.default)(endDate))) {
|
|
282
|
-
throw new factory_1.factory.errors.Argument('Transaction id', 'potentially expired');
|
|
283
|
-
}
|
|
284
|
-
throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory_1.factory.transactionStatusType.InProgress} not found`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
288
|
-
id: params.id,
|
|
289
|
-
typeOf: params.typeOf,
|
|
290
|
-
status: factory_1.factory.transactionStatusType.Confirmed
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
exports.ReturnOrderRepo = ReturnOrderRepo;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ISetting } from '../../../../repo/setting';
|
|
2
|
-
import { factory } from '../../../../factory';
|
|
3
|
-
type IReturnOrderPotentialTask = factory.task.IAttributes<factory.taskName.ReturnOrder>;
|
|
4
|
-
/**
|
|
5
|
-
* 取引のタスクを作成する
|
|
6
|
-
* 取引削除タスクを分離(2026-08-02~)
|
|
7
|
-
*/
|
|
8
|
-
export declare function createImmediateTasks(params: {
|
|
9
|
-
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'startDate' | 'object' | 'potentialActions'>;
|
|
10
|
-
taskRunsAt: Date;
|
|
11
|
-
}): IReturnOrderPotentialTask[];
|
|
12
|
-
/**
|
|
13
|
-
* 取引のタスクを作成する
|
|
14
|
-
* 取引削除タスクを分離(2026-08-02~)
|
|
15
|
-
*/
|
|
16
|
-
export declare function createScheduledTasks(params: {
|
|
17
|
-
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'object'>;
|
|
18
|
-
}, setting: Pick<ISetting, 'storage'> | null): factory.task.deleteTransaction.IAttributes;
|
|
19
|
-
export {};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createImmediateTasks = createImmediateTasks;
|
|
7
|
-
exports.createScheduledTasks = createScheduledTasks;
|
|
8
|
-
const moment_1 = __importDefault(require("moment"));
|
|
9
|
-
const factory_1 = require("../../../../factory");
|
|
10
|
-
/**
|
|
11
|
-
* 取引のタスクを作成する
|
|
12
|
-
* 取引削除タスクを分離(2026-08-02~)
|
|
13
|
-
*/
|
|
14
|
-
function createImmediateTasks(params) {
|
|
15
|
-
const taskAttributes = [];
|
|
16
|
-
const transaction = params.transaction;
|
|
17
|
-
const taskRunsAt = params.taskRunsAt;
|
|
18
|
-
switch (transaction.status) {
|
|
19
|
-
case factory_1.factory.transactionStatusType.Confirmed: {
|
|
20
|
-
const returnOrderPotentialActions = transaction.potentialActions?.returnOrder;
|
|
21
|
-
if (Array.isArray(returnOrderPotentialActions)) {
|
|
22
|
-
// 返品タスク
|
|
23
|
-
const returnOrderTask = returnOrderPotentialActions.map((r) => {
|
|
24
|
-
const { object, potentialActions, typeOf } = transaction;
|
|
25
|
-
// data最適化(2023-08-22~)
|
|
26
|
-
const returnOrderTaskData = {
|
|
27
|
-
agent: r.agent,
|
|
28
|
-
object: r.object,
|
|
29
|
-
project: transaction.project,
|
|
30
|
-
typeOf: r.typeOf,
|
|
31
|
-
returnOrderTransaction: { object, potentialActions, typeOf } // add(2026-09-05~)
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
project: transaction.project,
|
|
35
|
-
name: factory_1.factory.taskName.ReturnOrder,
|
|
36
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
37
|
-
runsAt: taskRunsAt,
|
|
38
|
-
remainingNumberOfTries: 10,
|
|
39
|
-
numberOfTried: 0,
|
|
40
|
-
executionResults: [],
|
|
41
|
-
data: returnOrderTaskData
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
taskAttributes.push(...returnOrderTask);
|
|
45
|
-
}
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
case factory_1.factory.transactionStatusType.Expired:
|
|
49
|
-
// 特にタスクなし
|
|
50
|
-
break;
|
|
51
|
-
default:
|
|
52
|
-
throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
|
53
|
-
}
|
|
54
|
-
return taskAttributes;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 取引のタスクを作成する
|
|
58
|
-
* 取引削除タスクを分離(2026-08-02~)
|
|
59
|
-
*/
|
|
60
|
-
function createScheduledTasks(params, setting) {
|
|
61
|
-
const transaction = params.transaction;
|
|
62
|
-
const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
|
|
63
|
-
const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
|
|
64
|
-
if (typeof confirmedStoragePeriodInDays !== 'number') {
|
|
65
|
-
throw new factory_1.factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
|
|
66
|
-
}
|
|
67
|
-
if (typeof canceledStoragePeriodInDays !== 'number') {
|
|
68
|
-
throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
|
|
69
|
-
}
|
|
70
|
-
// 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
|
|
71
|
-
let deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
72
|
-
.add(confirmedStoragePeriodInDays, 'days')
|
|
73
|
-
.toDate();
|
|
74
|
-
switch (transaction.status) {
|
|
75
|
-
case factory_1.factory.transactionStatusType.Confirmed:
|
|
76
|
-
break;
|
|
77
|
-
case factory_1.factory.transactionStatusType.Canceled:
|
|
78
|
-
case factory_1.factory.transactionStatusType.Expired:
|
|
79
|
-
deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
80
|
-
.add(canceledStoragePeriodInDays, 'days')
|
|
81
|
-
.toDate();
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
project: transaction.project,
|
|
87
|
-
name: factory_1.factory.taskName.DeleteTransaction,
|
|
88
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
89
|
-
runsAt: deleteAt,
|
|
90
|
-
remainingNumberOfTries: 3,
|
|
91
|
-
numberOfTried: 0,
|
|
92
|
-
executionResults: [],
|
|
93
|
-
data: {
|
|
94
|
-
object: {
|
|
95
|
-
specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id,
|
|
96
|
-
id: transaction.id,
|
|
97
|
-
object: {
|
|
98
|
-
order: transaction.object.order
|
|
99
|
-
},
|
|
100
|
-
typeOf: transaction.typeOf,
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|