@chevre/domain 21.20.0-alpha.12 → 21.20.0-alpha.14
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/onAssetTransactionStatusChanged.ts +36 -0
- package/example/src/chevre/searchSlicedAcceptedOffersByOrderNumber.ts +28 -0
- package/example/src/chevre/sendOrder.ts +36 -0
- package/example/src/chevre/transaction/processPlaceOrder.ts +1 -1
- package/lib/chevre/repo/acceptedOffer.d.ts +21 -1
- package/lib/chevre/repo/acceptedOffer.js +26 -0
- package/lib/chevre/service/assetTransaction/pay.js +1 -1
- package/lib/chevre/service/order/confirmPayTransaction.js +1 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +11 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +109 -3
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +45 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.d.ts +14 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +36 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +82 -0
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +3 -1
- package/lib/chevre/service/order/onOrderStatusChanged.js +5 -1
- package/lib/chevre/service/order/placeOrder.js +24 -27
- package/lib/chevre/service/order/sendOrder.d.ts +4 -0
- package/lib/chevre/service/order/sendOrder.js +67 -29
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -1
- package/lib/chevre/service/task/confirmReserveTransaction.js +41 -2
- package/lib/chevre/service/task/sendOrder.js +5 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +6 -2
- package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
- package/lib/chevre/settings.d.ts +1 -1
- package/lib/chevre/settings.js +5 -2
- package/package.json +2 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
(await chevre.service.order.createService())
|
|
12
|
+
.onAssetTransactionStatusChanged({
|
|
13
|
+
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
14
|
+
object: {
|
|
15
|
+
typeOf: chevre.factory.assetTransactionType.Reserve,
|
|
16
|
+
transactionNumber: '863918387495116',
|
|
17
|
+
status: chevre.factory.transactionStatusType.Confirmed
|
|
18
|
+
},
|
|
19
|
+
purpose: {
|
|
20
|
+
confirmationNumber: '',
|
|
21
|
+
orderNumber: 'CIN1-3748070-2008463',
|
|
22
|
+
typeOf: chevre.factory.order.OrderType.Order
|
|
23
|
+
},
|
|
24
|
+
useOnOrderStatusChanged: true
|
|
25
|
+
})({
|
|
26
|
+
assetTransaction: await chevre.repository.AssetTransaction.createInstance(mongoose.connection),
|
|
27
|
+
acceptedOffer: await chevre.repository.AcceptedOffer.createInstance(mongoose.connection),
|
|
28
|
+
order: await chevre.repository.Order.createInstance(mongoose.connection),
|
|
29
|
+
task: await chevre.repository.Task.createInstance(mongoose.connection),
|
|
30
|
+
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main()
|
|
35
|
+
.then(console.log)
|
|
36
|
+
.catch(console.error);
|
|
@@ -0,0 +1,28 @@
|
|
|
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 acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const result = await acceptedOfferRepo.searchSlicedAcceptedOffersByOrderNumber(
|
|
12
|
+
{
|
|
13
|
+
orderNumber: { $eq: 'CIN1-3748070-2008463' },
|
|
14
|
+
project: { id: { $eq: String(process.env.PROJECT_ID) } },
|
|
15
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
16
|
+
$slice: [0, 2]
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
console.log(result);
|
|
20
|
+
console.log(result.acceptedOffers.map((offer) => {
|
|
21
|
+
return `${(<any>offer.itemOffered).id}`;
|
|
22
|
+
}));
|
|
23
|
+
console.log(result.acceptedOffers.length);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
main()
|
|
27
|
+
.then(console.log)
|
|
28
|
+
.catch(console.error);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
(await chevre.service.order.createService())
|
|
12
|
+
.sendOrder({
|
|
13
|
+
agent: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
14
|
+
project: { id: project.id },
|
|
15
|
+
object: {
|
|
16
|
+
confirmationNumber: '57761',
|
|
17
|
+
orderNumber: 'CIN1-3748070-2008463',
|
|
18
|
+
acceptedOffers: {
|
|
19
|
+
limit: 1,
|
|
20
|
+
page: 1
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
useOnOrderStatusChanged: false
|
|
24
|
+
})({
|
|
25
|
+
acceptedOffer: await chevre.repository.AcceptedOffer.createInstance(mongoose.connection),
|
|
26
|
+
action: await chevre.repository.Action.createInstance(mongoose.connection),
|
|
27
|
+
order: await chevre.repository.Order.createInstance(mongoose.connection),
|
|
28
|
+
ownershipInfo: await chevre.repository.OwnershipInfo.createInstance(mongoose.connection),
|
|
29
|
+
task: await chevre.repository.Task.createInstance(mongoose.connection),
|
|
30
|
+
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main()
|
|
35
|
+
.then(console.log)
|
|
36
|
+
.catch(console.error);
|
|
@@ -133,7 +133,7 @@ async function main() {
|
|
|
133
133
|
transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
|
|
134
134
|
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
135
135
|
});
|
|
136
|
-
console.log('payment authorized.', authorizeResult.
|
|
136
|
+
console.log('payment authorized.', authorizeResult.id);
|
|
137
137
|
} else if (jobCd === 'VOID') {
|
|
138
138
|
await (await chevre.service.payment.any.createService()).invalidatePaymentUrl({
|
|
139
139
|
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
@@ -6,6 +6,11 @@ type IProjection4searchWithUnwoundAcceptedOffers = {
|
|
|
6
6
|
_id?: 0 | 1;
|
|
7
7
|
};
|
|
8
8
|
type IDistinctField = 'acceptedOffers.id' | 'acceptedOffers.itemOffered.reservationNumber' | 'acceptedOffers.itemOffered.reservationFor.id' | 'acceptedOffers.itemOffered.issuedThrough.id' | 'acceptedOffers.offeredThrough.identifier' | 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode';
|
|
9
|
+
type IAcceptedOffer = factory.order.IAcceptedOffer<factory.order.IItemOffered>;
|
|
10
|
+
interface ISearchSlicedAcceptedOffersResult {
|
|
11
|
+
acceptedOffers: IAcceptedOffer[];
|
|
12
|
+
numAcceptedOffers: number;
|
|
13
|
+
}
|
|
9
14
|
/**
|
|
10
15
|
* 注文オファーリポジトリ
|
|
11
16
|
*/
|
|
@@ -29,6 +34,7 @@ export declare class MongoRepository {
|
|
|
29
34
|
searchAcceptedOffersByOrderNumber(filter: {
|
|
30
35
|
limit?: number;
|
|
31
36
|
page?: number;
|
|
37
|
+
$slice?: [number, number];
|
|
32
38
|
orderNumber: {
|
|
33
39
|
$eq: string;
|
|
34
40
|
};
|
|
@@ -47,7 +53,21 @@ export declare class MongoRepository {
|
|
|
47
53
|
};
|
|
48
54
|
};
|
|
49
55
|
};
|
|
50
|
-
}, inclusion?: (keyof
|
|
56
|
+
}, inclusion?: (keyof IAcceptedOffer)[]): Promise<IAcceptedOffer[]>;
|
|
57
|
+
/**
|
|
58
|
+
* 注文オファーをsliceして検索する(2024-01-10~)
|
|
59
|
+
*/
|
|
60
|
+
searchSlicedAcceptedOffersByOrderNumber(filter: {
|
|
61
|
+
$slice: [number, number];
|
|
62
|
+
orderNumber: {
|
|
63
|
+
$eq: string;
|
|
64
|
+
};
|
|
65
|
+
project: {
|
|
66
|
+
id: {
|
|
67
|
+
$eq: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}): Promise<ISearchSlicedAcceptedOffersResult>;
|
|
51
71
|
/**
|
|
52
72
|
* 特定のフィールド値リストを検索する
|
|
53
73
|
*/
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MongoRepository = void 0;
|
|
13
|
+
const factory = require("../factory");
|
|
13
14
|
const order_1 = require("./mongoose/schemas/order");
|
|
14
15
|
const order_2 = require("./order");
|
|
15
16
|
const settings_1 = require("../settings");
|
|
@@ -137,6 +138,31 @@ class MongoRepository {
|
|
|
137
138
|
.exec();
|
|
138
139
|
});
|
|
139
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* 注文オファーをsliceして検索する(2024-01-10~)
|
|
143
|
+
*/
|
|
144
|
+
searchSlicedAcceptedOffersByOrderNumber(filter) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const aggregate = this.orderModel.aggregate([
|
|
147
|
+
{ $match: { 'project.id': { $eq: filter.project.id.$eq } } },
|
|
148
|
+
{ $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
|
|
149
|
+
{
|
|
150
|
+
$project: {
|
|
151
|
+
_id: 0,
|
|
152
|
+
acceptedOffers: { $slice: ['$acceptedOffers', ...filter.$slice] },
|
|
153
|
+
numAcceptedOffers: { $size: '$acceptedOffers' }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
]);
|
|
157
|
+
const result = (yield aggregate
|
|
158
|
+
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
159
|
+
.exec()).shift();
|
|
160
|
+
if (result === undefined) {
|
|
161
|
+
throw new factory.errors.NotFound(factory.order.OrderType.Order);
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
140
166
|
/**
|
|
141
167
|
* 特定のフィールド値リストを検索する
|
|
142
168
|
*/
|
|
@@ -74,7 +74,7 @@ function onConfirmed(params) {
|
|
|
74
74
|
purpose: {
|
|
75
75
|
confirmationNumber: params.purpose.confirmationNumber,
|
|
76
76
|
orderNumber: params.purpose.orderNumber,
|
|
77
|
-
typeOf:
|
|
77
|
+
typeOf: factory.order.OrderType.Order
|
|
78
78
|
},
|
|
79
79
|
useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
|
|
80
80
|
};
|
|
@@ -24,4 +24,14 @@ declare function paymentDue2Processing(params: {
|
|
|
24
24
|
task: TaskRepo;
|
|
25
25
|
transaction: TransactionRepo;
|
|
26
26
|
}) => Promise<void>;
|
|
27
|
-
|
|
27
|
+
declare function processing2inTransit(params: {
|
|
28
|
+
project: {
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
orderNumber: string;
|
|
32
|
+
useOnOrderStatusChanged: boolean;
|
|
33
|
+
}): (repos: {
|
|
34
|
+
order: OrderRepo;
|
|
35
|
+
task: TaskRepo;
|
|
36
|
+
}) => Promise<void>;
|
|
37
|
+
export { onAssetTransactionStatusChanged, paymentDue2Processing, processing2inTransit };
|
|
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.paymentDue2Processing = exports.onAssetTransactionStatusChanged = void 0;
|
|
12
|
+
exports.processing2inTransit = exports.paymentDue2Processing = exports.onAssetTransactionStatusChanged = void 0;
|
|
13
13
|
const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
|
|
14
14
|
const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
|
|
15
15
|
const factory = require("../../factory");
|
|
16
|
+
// tslint:disable-next-line:max-func-body-length
|
|
16
17
|
function onAssetTransactionStatusChanged(params) {
|
|
17
18
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
var _a, _b, _c, _d, _e;
|
|
@@ -21,10 +22,10 @@ function onAssetTransactionStatusChanged(params) {
|
|
|
21
22
|
}
|
|
22
23
|
switch (params.object.status) {
|
|
23
24
|
case factory.transactionStatusType.Confirmed:
|
|
25
|
+
const orderNumber = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.orderNumber;
|
|
26
|
+
const confirmationNumber = (_b = params.purpose) === null || _b === void 0 ? void 0 : _b.confirmationNumber;
|
|
24
27
|
switch (params.object.typeOf) {
|
|
25
28
|
case factory.assetTransactionType.Pay:
|
|
26
|
-
const orderNumber = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.orderNumber;
|
|
27
|
-
const confirmationNumber = (_b = params.purpose) === null || _b === void 0 ? void 0 : _b.confirmationNumber;
|
|
28
29
|
// 確定時の決済方法区分指定(2023-08-29~)
|
|
29
30
|
const specifiedPaymentMethodIdentifire = (_e = (_d = (_c = params.object) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.paymentMethod) === null || _e === void 0 ? void 0 : _e.identifier;
|
|
30
31
|
if (typeof specifiedPaymentMethodIdentifire === 'string' && specifiedPaymentMethodIdentifire.length > 0) {
|
|
@@ -48,6 +49,34 @@ function onAssetTransactionStatusChanged(params) {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
break;
|
|
52
|
+
case 'COAReserveTransaction':
|
|
53
|
+
if (typeof orderNumber === 'string' && typeof confirmationNumber === 'string') {
|
|
54
|
+
// 基本的に1注文に1予約番号なのでdeliverable = true
|
|
55
|
+
const deliverable = true;
|
|
56
|
+
if (deliverable) {
|
|
57
|
+
yield processing2inTransit({
|
|
58
|
+
project: { id: params.project.id },
|
|
59
|
+
// confirmationNumber,
|
|
60
|
+
orderNumber,
|
|
61
|
+
useOnOrderStatusChanged: params.useOnOrderStatusChanged
|
|
62
|
+
})(repos);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case factory.assetTransactionType.Reserve:
|
|
67
|
+
if (typeof orderNumber === 'string' && typeof confirmationNumber === 'string') {
|
|
68
|
+
// ReserveTransactionのステータス検証
|
|
69
|
+
const deliverable = yield isDeliverable({ project: { id: params.project.id }, orderNumber })(repos);
|
|
70
|
+
if (deliverable) {
|
|
71
|
+
yield processing2inTransit({
|
|
72
|
+
project: { id: params.project.id },
|
|
73
|
+
// confirmationNumber,
|
|
74
|
+
orderNumber,
|
|
75
|
+
useOnOrderStatusChanged: params.useOnOrderStatusChanged
|
|
76
|
+
})(repos);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
51
80
|
default:
|
|
52
81
|
// no op
|
|
53
82
|
}
|
|
@@ -230,3 +259,80 @@ function cancelOrderIfExist(params) {
|
|
|
230
259
|
}
|
|
231
260
|
});
|
|
232
261
|
}
|
|
262
|
+
function isDeliverable(params) {
|
|
263
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
// 注文のreservationNumberを取得
|
|
265
|
+
const reservationNumbers = yield repos.acceptedOffer.distinctValues({ orderNumber: { $in: [params.orderNumber] } }, 'acceptedOffers.itemOffered.reservationNumber');
|
|
266
|
+
// ReserveTransactionのステータス検証
|
|
267
|
+
let allReserveTransactionConfirmed = false;
|
|
268
|
+
if (reservationNumbers.length > 0) {
|
|
269
|
+
// console.log('is deliverable?...', params.orderNumber, reservationNumbers);
|
|
270
|
+
const referencedReserveTransactions = yield repos.assetTransaction.search({
|
|
271
|
+
project: { id: { $eq: params.project.id } },
|
|
272
|
+
typeOf: factory.assetTransactionType.Reserve,
|
|
273
|
+
transactionNumber: { $in: reservationNumbers }
|
|
274
|
+
}, ['status']);
|
|
275
|
+
// console.log('referencedReserveTransactions:', referencedReserveTransactions);
|
|
276
|
+
allReserveTransactionConfirmed =
|
|
277
|
+
referencedReserveTransactions.length === reservationNumbers.length
|
|
278
|
+
&& referencedReserveTransactions.every(({ status }) => status === factory.transactionStatusType.Confirmed);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
allReserveTransactionConfirmed = true;
|
|
282
|
+
}
|
|
283
|
+
return allReserveTransactionConfirmed;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function processing2inTransit(params) {
|
|
287
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
288
|
+
// const placeOrderTransaction = await findPlaceOrderTransaction({
|
|
289
|
+
// project: { id: params.project.id },
|
|
290
|
+
// confirmationNumber: params.confirmationNumber,
|
|
291
|
+
// orderNumber: params.orderNumber
|
|
292
|
+
// })({ transaction: repos.transaction });
|
|
293
|
+
const order = yield repos.order.findByOrderNumber({
|
|
294
|
+
orderNumber: params.orderNumber,
|
|
295
|
+
project: { id: params.project.id },
|
|
296
|
+
inclusion: [],
|
|
297
|
+
exclusion: ['acceptedOffers']
|
|
298
|
+
});
|
|
299
|
+
try {
|
|
300
|
+
// console.log('OrderProcessing -> OrderInTransit');
|
|
301
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
302
|
+
// TODO OrderInTransitへの変更を保留
|
|
303
|
+
// order = await repos.order.changeStatus({
|
|
304
|
+
// project: { id: order.project.id },
|
|
305
|
+
// orderNumber: params.orderNumber,
|
|
306
|
+
// orderStatus: factory.orderStatus.OrderInTransit,
|
|
307
|
+
// previousOrderStatus: factory.orderStatus.OrderProcessing
|
|
308
|
+
// });
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
const throwsError = true;
|
|
312
|
+
// すでにステータスが煤でいた場合、OrderPaymentDue->OrderProcessingの処理自体は成功しているので、後処理を続行する
|
|
313
|
+
// order = await repos.order.findByOrderNumber({
|
|
314
|
+
// orderNumber: params.orderNumber,
|
|
315
|
+
// project: { id: params.project.id },
|
|
316
|
+
// inclusion: [],
|
|
317
|
+
// exclusion: ['acceptedOffers']
|
|
318
|
+
// });
|
|
319
|
+
// if (order.orderStatus === factory.orderStatus.OrderDelivered
|
|
320
|
+
// || order.orderStatus === factory.orderStatus.OrderReturned) {
|
|
321
|
+
// throwsError = false;
|
|
322
|
+
// }
|
|
323
|
+
if (throwsError) {
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (params.useOnOrderStatusChanged) {
|
|
328
|
+
yield (0, onOrderStatusChanged_1.onOrderInTransit)({
|
|
329
|
+
order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderProcessing // 強制的にOrderProcessingとして処理する
|
|
330
|
+
})
|
|
331
|
+
// placeOrderTransaction
|
|
332
|
+
})({
|
|
333
|
+
task: repos.task
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
exports.processing2inTransit = processing2inTransit;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as factory from '../../../../factory';
|
|
2
|
+
declare function createNextSendOrderTasks(params: {
|
|
3
|
+
order: Pick<factory.order.IOrder, 'confirmationNumber' | 'project' | 'typeOf' | 'seller' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'customer' | 'id'> & {
|
|
4
|
+
acceptedOffers: {
|
|
5
|
+
limit: number;
|
|
6
|
+
page: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
}): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
|
|
10
|
+
export { createNextSendOrderTasks };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNextSendOrderTasks = void 0;
|
|
4
|
+
const factory = require("../../../../factory");
|
|
5
|
+
const order_1 = require("../../../../factory/order");
|
|
6
|
+
function createNextSendOrderTasks(params) {
|
|
7
|
+
const now = new Date();
|
|
8
|
+
const taskAttributes = [];
|
|
9
|
+
const maskedCustomer = (0, order_1.createMaskedCustomer)({ customer: params.order.customer }, { noProfile: true });
|
|
10
|
+
const simpleOrder = {
|
|
11
|
+
typeOf: params.order.typeOf,
|
|
12
|
+
seller: {
|
|
13
|
+
id: params.order.seller.id,
|
|
14
|
+
typeOf: params.order.seller.typeOf,
|
|
15
|
+
name: params.order.seller.name
|
|
16
|
+
},
|
|
17
|
+
// mask
|
|
18
|
+
customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id },
|
|
19
|
+
orderNumber: params.order.orderNumber,
|
|
20
|
+
price: params.order.price,
|
|
21
|
+
priceCurrency: params.order.priceCurrency,
|
|
22
|
+
orderDate: params.order.orderDate
|
|
23
|
+
};
|
|
24
|
+
const sendOrderObject = Object.assign(Object.assign({}, simpleOrder), { acceptedOffers: {
|
|
25
|
+
limit: params.order.acceptedOffers.limit,
|
|
26
|
+
page: params.order.acceptedOffers.page + 1
|
|
27
|
+
} });
|
|
28
|
+
const sendOrderTaskData = {
|
|
29
|
+
project: params.order.project,
|
|
30
|
+
object: Object.assign(Object.assign({}, sendOrderObject), { confirmationNumber: params.order.confirmationNumber })
|
|
31
|
+
};
|
|
32
|
+
const sendOrderTask = {
|
|
33
|
+
project: params.order.project,
|
|
34
|
+
name: factory.taskName.SendOrder,
|
|
35
|
+
status: factory.taskStatus.Ready,
|
|
36
|
+
runsAt: now,
|
|
37
|
+
remainingNumberOfTries: 10,
|
|
38
|
+
numberOfTried: 0,
|
|
39
|
+
executionResults: [],
|
|
40
|
+
data: sendOrderTaskData
|
|
41
|
+
};
|
|
42
|
+
taskAttributes.push(sendOrderTask);
|
|
43
|
+
return taskAttributes;
|
|
44
|
+
}
|
|
45
|
+
exports.createNextSendOrderTasks = createNextSendOrderTasks;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
2
|
+
import * as factory from '../../../factory';
|
|
3
|
+
declare function onOrderDeliveredPartially(params: {
|
|
4
|
+
order: Pick<factory.order.IOrder, 'confirmationNumber' | 'project' | 'typeOf' | 'seller' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'customer' | 'id'> & {
|
|
5
|
+
acceptedOffers: {
|
|
6
|
+
limit: number;
|
|
7
|
+
page: number;
|
|
8
|
+
};
|
|
9
|
+
orderStatus: factory.orderStatus.OrderProcessing;
|
|
10
|
+
};
|
|
11
|
+
}): (repos: {
|
|
12
|
+
task: TaskRepo;
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
export { onOrderDeliveredPartially };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.onOrderDeliveredPartially = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* 注文ステータス変更時処理
|
|
15
|
+
*/
|
|
16
|
+
const createDebug = require("debug");
|
|
17
|
+
const factory = require("../../../factory");
|
|
18
|
+
const factory_1 = require("./onOrderDeliveredPartially/factory");
|
|
19
|
+
const debug = createDebug('chevre-domain:service:order');
|
|
20
|
+
// type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'project' | 'typeOf' | 'potentialActions'>;
|
|
21
|
+
function onOrderDeliveredPartially(params) {
|
|
22
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
|
|
24
|
+
let tasks = [];
|
|
25
|
+
switch (params.order.orderStatus) {
|
|
26
|
+
case factory.orderStatus.OrderProcessing:
|
|
27
|
+
// 次の配送タスクを作成
|
|
28
|
+
tasks = (0, factory_1.createNextSendOrderTasks)({ order: params.order });
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
throw new factory.errors.NotImplemented(`${params.order.orderStatus} not implemented`);
|
|
32
|
+
}
|
|
33
|
+
yield repos.task.saveMany(tasks, { emitImmediately: true });
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.onOrderDeliveredPartially = onOrderDeliveredPartially;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
2
|
+
import * as factory from '../../../factory';
|
|
3
|
+
declare function onOrderInTransit(params: {
|
|
4
|
+
order: Omit<factory.order.IOrder, 'orderStatus'> & {
|
|
5
|
+
orderStatus: factory.orderStatus.OrderProcessing;
|
|
6
|
+
};
|
|
7
|
+
}): (repos: {
|
|
8
|
+
task: TaskRepo;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
export { onOrderInTransit };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.onOrderInTransit = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* 注文処理時処理
|
|
15
|
+
*/
|
|
16
|
+
const createDebug = require("debug");
|
|
17
|
+
const factory = require("../../../factory");
|
|
18
|
+
const order_1 = require("../../../factory/order");
|
|
19
|
+
const settings_1 = require("../../../settings");
|
|
20
|
+
// import {
|
|
21
|
+
// IExternalOrder
|
|
22
|
+
// } from './onOrderProcessing/factory';
|
|
23
|
+
const debug = createDebug('chevre-domain:service:order');
|
|
24
|
+
// type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'typeOf' | 'potentialActions'>;
|
|
25
|
+
function onOrderInTransit(params) {
|
|
26
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
|
|
28
|
+
// let tasks: factory.task.IAttributes<factory.taskName>[] = [];
|
|
29
|
+
// await repos.task.saveMany(tasks, { emitImmediately: true });
|
|
30
|
+
switch (params.order.orderStatus) {
|
|
31
|
+
case factory.orderStatus.OrderProcessing:
|
|
32
|
+
// 冗長なsendOrderタスク作成を回避(2023-08-25~)
|
|
33
|
+
yield createSendOrderTransactionTaskIfNotExist({
|
|
34
|
+
order: params.order
|
|
35
|
+
// potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
|
|
36
|
+
})(repos);
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.onOrderInTransit = onOrderInTransit;
|
|
43
|
+
function createSendOrderTransactionTaskIfNotExist(params) {
|
|
44
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const now = new Date();
|
|
46
|
+
const maskedCustomer = (0, order_1.createMaskedCustomer)({ customer: params.order.customer }, { noProfile: true });
|
|
47
|
+
const simpleOrder = {
|
|
48
|
+
typeOf: params.order.typeOf,
|
|
49
|
+
seller: {
|
|
50
|
+
id: params.order.seller.id,
|
|
51
|
+
typeOf: params.order.seller.typeOf,
|
|
52
|
+
name: params.order.seller.name
|
|
53
|
+
},
|
|
54
|
+
// mask
|
|
55
|
+
customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id },
|
|
56
|
+
orderNumber: params.order.orderNumber,
|
|
57
|
+
price: params.order.price,
|
|
58
|
+
priceCurrency: params.order.priceCurrency,
|
|
59
|
+
orderDate: params.order.orderDate
|
|
60
|
+
};
|
|
61
|
+
const sendOrderObject = Object.assign(Object.assign({}, simpleOrder), { acceptedOffers: {
|
|
62
|
+
limit: settings_1.DELIVER_ORDER_LIMIT,
|
|
63
|
+
page: 1 // page1から配送
|
|
64
|
+
} });
|
|
65
|
+
const sendOrderTaskData = {
|
|
66
|
+
project: params.order.project,
|
|
67
|
+
object: Object.assign(Object.assign({}, sendOrderObject), { confirmationNumber: params.order.confirmationNumber })
|
|
68
|
+
};
|
|
69
|
+
const sendOrderTask = {
|
|
70
|
+
project: params.order.project,
|
|
71
|
+
name: factory.taskName.SendOrder,
|
|
72
|
+
status: factory.taskStatus.Ready,
|
|
73
|
+
runsAt: now,
|
|
74
|
+
remainingNumberOfTries: 10,
|
|
75
|
+
numberOfTried: 0,
|
|
76
|
+
executionResults: [],
|
|
77
|
+
data: sendOrderTaskData
|
|
78
|
+
};
|
|
79
|
+
debug('processing createSendOrderTaskIfNotExist...', sendOrderTask);
|
|
80
|
+
yield repos.task.createSendOrderTaskIfNotExist(sendOrderTask, { emitImmediately: true });
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { onOrderCancelled } from './onOrderStatusChanged/onOrderCancelled';
|
|
5
5
|
import { onOrderDelivered } from './onOrderStatusChanged/onOrderDelivered';
|
|
6
|
+
import { onOrderDeliveredPartially } from './onOrderStatusChanged/onOrderDeliveredPartially';
|
|
7
|
+
import { onOrderInTransit } from './onOrderStatusChanged/onOrderInTransit';
|
|
6
8
|
import { onOrderPaymentDue } from './onOrderStatusChanged/onOrderPaymentDue';
|
|
7
9
|
import { IExternalOrder, onOrderProcessing } from './onOrderStatusChanged/onOrderProcessing';
|
|
8
10
|
import { onOrderReturned } from './onOrderStatusChanged/onOrderReturned';
|
|
9
|
-
export { IExternalOrder, onOrderCancelled, onOrderDelivered, onOrderPaymentDue, onOrderProcessing, onOrderReturned };
|
|
11
|
+
export { IExternalOrder, onOrderCancelled, onOrderDelivered, onOrderDeliveredPartially, onOrderInTransit, onOrderPaymentDue, onOrderProcessing, onOrderReturned };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onOrderReturned = exports.onOrderProcessing = exports.onOrderPaymentDue = exports.onOrderDelivered = exports.onOrderCancelled = void 0;
|
|
3
|
+
exports.onOrderReturned = exports.onOrderProcessing = exports.onOrderPaymentDue = exports.onOrderInTransit = exports.onOrderDeliveredPartially = exports.onOrderDelivered = exports.onOrderCancelled = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文ステータス変更時処理
|
|
6
6
|
*/
|
|
@@ -8,6 +8,10 @@ const onOrderCancelled_1 = require("./onOrderStatusChanged/onOrderCancelled");
|
|
|
8
8
|
Object.defineProperty(exports, "onOrderCancelled", { enumerable: true, get: function () { return onOrderCancelled_1.onOrderCancelled; } });
|
|
9
9
|
const onOrderDelivered_1 = require("./onOrderStatusChanged/onOrderDelivered");
|
|
10
10
|
Object.defineProperty(exports, "onOrderDelivered", { enumerable: true, get: function () { return onOrderDelivered_1.onOrderDelivered; } });
|
|
11
|
+
const onOrderDeliveredPartially_1 = require("./onOrderStatusChanged/onOrderDeliveredPartially");
|
|
12
|
+
Object.defineProperty(exports, "onOrderDeliveredPartially", { enumerable: true, get: function () { return onOrderDeliveredPartially_1.onOrderDeliveredPartially; } });
|
|
13
|
+
const onOrderInTransit_1 = require("./onOrderStatusChanged/onOrderInTransit");
|
|
14
|
+
Object.defineProperty(exports, "onOrderInTransit", { enumerable: true, get: function () { return onOrderInTransit_1.onOrderInTransit; } });
|
|
11
15
|
const onOrderPaymentDue_1 = require("./onOrderStatusChanged/onOrderPaymentDue");
|
|
12
16
|
Object.defineProperty(exports, "onOrderPaymentDue", { enumerable: true, get: function () { return onOrderPaymentDue_1.onOrderPaymentDue; } });
|
|
13
17
|
const onOrderProcessing_1 = require("./onOrderStatusChanged/onOrderProcessing");
|
|
@@ -168,7 +168,6 @@ exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
|
|
|
168
168
|
/**
|
|
169
169
|
* 注文を作成する
|
|
170
170
|
*/
|
|
171
|
-
// tslint:disable-next-line:max-func-body-length
|
|
172
171
|
function placeOrder(params) {
|
|
173
172
|
// tslint:disable-next-line:max-func-body-length
|
|
174
173
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -182,6 +181,10 @@ function placeOrder(params) {
|
|
|
182
181
|
confirmationNumber: params.object.confirmationNumber,
|
|
183
182
|
orderNumber: params.object.orderNumber
|
|
184
183
|
})({ transaction: repos.transaction });
|
|
184
|
+
// USE_ORDER_PAYMENT_DUE_ON_PLACED設定を廃止したので、必ずOrderPaymentDueのはず(2024-01-10~)
|
|
185
|
+
if (order.orderStatus !== factory.orderStatus.OrderPaymentDue) {
|
|
186
|
+
throw new factory.errors.ServiceUnavailable(`orderStatus must be ${factory.orderStatus.OrderPaymentDue}`);
|
|
187
|
+
}
|
|
185
188
|
const maskedCustomer = (0, order_1.createMaskedCustomer)(order, { noProfile: true });
|
|
186
189
|
const simpleOrder = {
|
|
187
190
|
typeOf: order.typeOf,
|
|
@@ -259,27 +262,26 @@ function placeOrder(params) {
|
|
|
259
262
|
})({
|
|
260
263
|
task: repos.task
|
|
261
264
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
// OrderPaymentDue
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
});
|
|
265
|
+
// } else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
|
|
266
|
+
// // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
|
|
267
|
+
// // OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
|
|
268
|
+
// await onOrderPaymentDue({
|
|
269
|
+
// order: {
|
|
270
|
+
// paymentMethods: order.paymentMethods,
|
|
271
|
+
// project: order.project,
|
|
272
|
+
// orderNumber: order.orderNumber,
|
|
273
|
+
// confirmationNumber: order.confirmationNumber,
|
|
274
|
+
// customer: order.customer,
|
|
275
|
+
// orderDate: order.orderDate,
|
|
276
|
+
// seller: order.seller,
|
|
277
|
+
// typeOf: order.typeOf,
|
|
278
|
+
// price: order.price,
|
|
279
|
+
// priceCurrency: order.priceCurrency,
|
|
280
|
+
// orderStatus: factory.orderStatus.OrderPaymentDue
|
|
281
|
+
// }
|
|
282
|
+
// })({
|
|
283
|
+
// task: repos.task
|
|
284
|
+
// });
|
|
283
285
|
}
|
|
284
286
|
else {
|
|
285
287
|
throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
|
|
@@ -295,11 +297,6 @@ function placeOrder(params) {
|
|
|
295
297
|
})(repos);
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
|
-
// onOrderStatusChangedへ移行(2023-08-17~)
|
|
299
|
-
// await onPlaceOrder({
|
|
300
|
-
// object: order,
|
|
301
|
-
// potentialActions: params.potentialActions
|
|
302
|
-
// })(repos);
|
|
303
300
|
return { order };
|
|
304
301
|
});
|
|
305
302
|
}
|
|
@@ -10,21 +10,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sendOrder = void 0;
|
|
13
|
+
const createDebug = require("debug");
|
|
13
14
|
const order_1 = require("../../factory/order");
|
|
14
15
|
const factory_1 = require("../delivery/factory");
|
|
15
16
|
const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
|
|
16
17
|
const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
|
|
17
18
|
const factory = require("../../factory");
|
|
19
|
+
const debug = createDebug('chevre-domain:service:order');
|
|
18
20
|
/**
|
|
19
21
|
* 注文を配送する
|
|
20
22
|
*/
|
|
21
23
|
function sendOrder(params) {
|
|
22
24
|
// tslint:disable-next-line:max-func-body-length
|
|
23
25
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a;
|
|
26
|
+
var _a, _b, _c;
|
|
25
27
|
if (typeof params.useOnOrderStatusChanged !== 'boolean') {
|
|
26
28
|
throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
|
|
27
29
|
}
|
|
30
|
+
if (typeof ((_a = params.object.acceptedOffers) === null || _a === void 0 ? void 0 : _a.limit) !== 'number') {
|
|
31
|
+
throw new factory.errors.Argument('object.acceptedOffers.limit', 'must be number');
|
|
32
|
+
}
|
|
33
|
+
if (typeof ((_b = params.object.acceptedOffers) === null || _b === void 0 ? void 0 : _b.page) !== 'number') {
|
|
34
|
+
throw new factory.errors.Argument('object.acceptedOffers.page', 'must be number');
|
|
35
|
+
}
|
|
36
|
+
if (params.object.acceptedOffers.limit <= 0) {
|
|
37
|
+
throw new factory.errors.Argument('object.acceptedOffers.limit', 'must be greater than 1');
|
|
38
|
+
}
|
|
39
|
+
if (params.object.acceptedOffers.page <= 0) {
|
|
40
|
+
throw new factory.errors.Argument('object.acceptedOffers.page', 'must be greater than 1');
|
|
41
|
+
}
|
|
28
42
|
try {
|
|
29
43
|
const orderNumber = params.object.orderNumber;
|
|
30
44
|
const confirmationNumber = params.object.confirmationNumber;
|
|
@@ -62,9 +76,11 @@ function sendOrder(params) {
|
|
|
62
76
|
priceCurrency: order.priceCurrency,
|
|
63
77
|
orderDate: order.orderDate
|
|
64
78
|
};
|
|
79
|
+
const { limit, page } = params.object.acceptedOffers;
|
|
80
|
+
const sendOrderObject = Object.assign(Object.assign({}, simpleOrder), { acceptedOffers: { limit, page } });
|
|
65
81
|
const sendOrderActionAttributes = {
|
|
66
|
-
agent: (typeof ((
|
|
67
|
-
object:
|
|
82
|
+
agent: (typeof ((_c = params.agent) === null || _c === void 0 ? void 0 : _c.typeOf) === 'string') ? params.agent : order.project,
|
|
83
|
+
object: sendOrderObject,
|
|
68
84
|
potentialActions: {
|
|
69
85
|
// sendEmailMessage: undefined
|
|
70
86
|
},
|
|
@@ -74,23 +90,34 @@ function sendOrder(params) {
|
|
|
74
90
|
};
|
|
75
91
|
const action = yield repos.action.start(sendOrderActionAttributes);
|
|
76
92
|
let ownershipInfos;
|
|
93
|
+
let allOffersDelivered = false;
|
|
77
94
|
try {
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
// const acceptedOffers = await repos.acceptedOffer.searchAcceptedOffersByOrderNumber({
|
|
96
|
+
// orderNumber: { $eq: order.orderNumber },
|
|
97
|
+
// project: { id: { $eq: order.project.id } }
|
|
98
|
+
// });
|
|
99
|
+
const { acceptedOffers, numAcceptedOffers } = yield repos.acceptedOffer.searchSlicedAcceptedOffersByOrderNumber({
|
|
100
|
+
$slice: [limit * (page - 1), limit],
|
|
101
|
+
orderNumber: { $eq: order.orderNumber },
|
|
102
|
+
project: { id: { $eq: order.project.id } }
|
|
84
103
|
});
|
|
104
|
+
debug('delivering...', order.orderNumber, acceptedOffers.map((offer) => `${offer.itemOffered.id}`), params.object.acceptedOffers);
|
|
105
|
+
// 所有権作成
|
|
106
|
+
ownershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({ order: Object.assign(Object.assign({}, order), { acceptedOffers }) });
|
|
85
107
|
ownershipInfos = yield Promise.all(ownershipInfos.map((ownershipInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
86
108
|
return repos.ownershipInfo.createIfNotExistByIdentifier(ownershipInfo);
|
|
87
109
|
})));
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
const deliveredCount = limit * page;
|
|
111
|
+
debug(deliveredCount, 'delivered.', order.orderNumber, params.object.acceptedOffers);
|
|
112
|
+
if (deliveredCount >= numAcceptedOffers) {
|
|
113
|
+
order = yield repos.order.changeStatus({
|
|
114
|
+
project: { id: order.project.id },
|
|
115
|
+
orderNumber,
|
|
116
|
+
orderStatus: factory.orderStatus.OrderDelivered,
|
|
117
|
+
previousOrderStatus: factory.orderStatus.OrderProcessing
|
|
118
|
+
});
|
|
119
|
+
allOffersDelivered = true;
|
|
120
|
+
}
|
|
94
121
|
}
|
|
95
122
|
catch (error) {
|
|
96
123
|
try {
|
|
@@ -103,21 +130,32 @@ function sendOrder(params) {
|
|
|
103
130
|
}
|
|
104
131
|
const result = ownershipInfos;
|
|
105
132
|
yield repos.action.completeWithVoid({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
|
|
133
|
+
debug('allOffersDelivered?:', allOffersDelivered, order.orderNumber);
|
|
106
134
|
if (params.useOnOrderStatusChanged) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
135
|
+
if (allOffersDelivered) {
|
|
136
|
+
yield (0, onOrderStatusChanged_1.onOrderDelivered)({
|
|
137
|
+
order: {
|
|
138
|
+
id: order.id,
|
|
139
|
+
customer: order.customer,
|
|
140
|
+
orderDate: order.orderDate,
|
|
141
|
+
orderNumber: order.orderNumber,
|
|
142
|
+
project: order.project,
|
|
143
|
+
typeOf: order.typeOf,
|
|
144
|
+
orderStatus: factory.orderStatus.OrderDelivered
|
|
145
|
+
},
|
|
146
|
+
placeOrderTransaction
|
|
147
|
+
})({
|
|
148
|
+
task: repos.task
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
yield (0, onOrderStatusChanged_1.onOrderDeliveredPartially)({
|
|
153
|
+
order: Object.assign(Object.assign({}, order), { acceptedOffers: params.object.acceptedOffers, orderStatus: factory.orderStatus.OrderProcessing })
|
|
154
|
+
// placeOrderTransaction
|
|
155
|
+
})({
|
|
156
|
+
task: repos.task
|
|
157
|
+
});
|
|
158
|
+
}
|
|
121
159
|
}
|
|
122
160
|
}
|
|
123
161
|
catch (error) {
|
|
@@ -12,7 +12,10 @@ export declare function call(data: factory.task.IData<factory.taskName.ConfirmRe
|
|
|
12
12
|
/**
|
|
13
13
|
* 予約を確定する
|
|
14
14
|
*/
|
|
15
|
-
export declare function confirmReserveTransaction(params: factory.action.interact.confirm.reservation.IAttributes<factory.service.webAPI.Identifier
|
|
15
|
+
export declare function confirmReserveTransaction(params: factory.action.interact.confirm.reservation.IAttributes<factory.service.webAPI.Identifier>, options: {
|
|
16
|
+
sendOrder: boolean;
|
|
17
|
+
useOnOrderStatusChanged: boolean;
|
|
18
|
+
}): (repos: {
|
|
16
19
|
action: ActionRepo;
|
|
17
20
|
assetTransaction: AssetTransactionRepo;
|
|
18
21
|
order: OrderRepo;
|
|
@@ -28,7 +28,10 @@ const coaAuthClient = new COA.auth.RefreshToken({
|
|
|
28
28
|
*/
|
|
29
29
|
function call(data) {
|
|
30
30
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
yield confirmReserveTransaction(data
|
|
31
|
+
yield confirmReserveTransaction(data, {
|
|
32
|
+
sendOrder: true,
|
|
33
|
+
useOnOrderStatusChanged: true
|
|
34
|
+
})({
|
|
32
35
|
action: new action_1.MongoRepository(settings.connection),
|
|
33
36
|
assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
|
|
34
37
|
order: new order_1.MongoRepository(settings.connection),
|
|
@@ -41,7 +44,7 @@ exports.call = call;
|
|
|
41
44
|
/**
|
|
42
45
|
* 予約を確定する
|
|
43
46
|
*/
|
|
44
|
-
function confirmReserveTransaction(params) {
|
|
47
|
+
function confirmReserveTransaction(params, options) {
|
|
45
48
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
46
49
|
// アクション開始
|
|
47
50
|
const confirmActionAttributes = params;
|
|
@@ -89,6 +92,42 @@ function confirmReserveTransaction(params) {
|
|
|
89
92
|
// アクション完了
|
|
90
93
|
const result = {};
|
|
91
94
|
yield repos.action.completeWithVoid({ typeOf: confirmActionAttributes.typeOf, id: action.id, result: result });
|
|
95
|
+
// sendOrder連携(2024-01-11~)
|
|
96
|
+
yield onConfirmed(params, options)({
|
|
97
|
+
task: repos.task
|
|
98
|
+
});
|
|
92
99
|
});
|
|
93
100
|
}
|
|
94
101
|
exports.confirmReserveTransaction = confirmReserveTransaction;
|
|
102
|
+
function onConfirmed(params, options) {
|
|
103
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (options.sendOrder === true) {
|
|
105
|
+
// タスク冪等作成
|
|
106
|
+
const onAssetTransactionStatusChangedTaskData = {
|
|
107
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
108
|
+
object: {
|
|
109
|
+
typeOf: params.object.typeOf,
|
|
110
|
+
transactionNumber: params.object.transactionNumber,
|
|
111
|
+
status: factory.transactionStatusType.Confirmed
|
|
112
|
+
},
|
|
113
|
+
purpose: {
|
|
114
|
+
confirmationNumber: '',
|
|
115
|
+
orderNumber: params.purpose.orderNumber,
|
|
116
|
+
typeOf: factory.order.OrderType.Order
|
|
117
|
+
},
|
|
118
|
+
useOnOrderStatusChanged: options.useOnOrderStatusChanged === true
|
|
119
|
+
};
|
|
120
|
+
const onAssetTransactionStatusChangedTask = {
|
|
121
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
122
|
+
name: factory.taskName.OnAssetTransactionStatusChanged,
|
|
123
|
+
status: factory.taskStatus.Ready,
|
|
124
|
+
runsAt: new Date(),
|
|
125
|
+
remainingNumberOfTries: 10,
|
|
126
|
+
numberOfTried: 0,
|
|
127
|
+
executionResults: [],
|
|
128
|
+
data: onAssetTransactionStatusChangedTaskData
|
|
129
|
+
};
|
|
130
|
+
yield repos.task.createOnAssetTransactionStatusChangedTaskIfNotExist(onAssetTransactionStatusChangedTask, { emitImmediately: true });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -22,10 +22,11 @@ const OrderService = require("../order");
|
|
|
22
22
|
*/
|
|
23
23
|
function call(data) {
|
|
24
24
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
var _a;
|
|
26
|
+
yield OrderService.sendOrder(Object.assign(Object.assign({}, data), { object: Object.assign(Object.assign({}, data.object), { acceptedOffers: (typeof ((_a = data.object.acceptedOffers) === null || _a === void 0 ? void 0 : _a.limit) === 'number')
|
|
27
|
+
? data.object.acceptedOffers
|
|
28
|
+
: { limit: 50, page: 1 } // 互換性維持対応として指定がない場合に対応
|
|
29
|
+
}), useOnOrderStatusChanged: true }))({
|
|
29
30
|
acceptedOffer: new acceptedOffer_1.MongoRepository(settings.connection),
|
|
30
31
|
action: new action_1.MongoRepository(settings.connection),
|
|
31
32
|
order: new order_1.MongoRepository(settings.connection),
|
|
@@ -16,6 +16,7 @@ const registerService_1 = require("./potentialActions/registerService");
|
|
|
16
16
|
const sendEmailMessage_1 = require("./potentialActions/sendEmailMessage");
|
|
17
17
|
const factory = require("../../../factory");
|
|
18
18
|
const order_1 = require("../../../factory/order");
|
|
19
|
+
const settings_1 = require("../../../settings");
|
|
19
20
|
/**
|
|
20
21
|
* 取引のポストアクションを作成する
|
|
21
22
|
*/
|
|
@@ -43,11 +44,14 @@ function createPotentialActions(params) {
|
|
|
43
44
|
priceCurrency: params.order.priceCurrency,
|
|
44
45
|
orderDate: params.order.orderDate
|
|
45
46
|
};
|
|
47
|
+
const sendOrderObject = Object.assign(Object.assign({}, simpleOrder), { acceptedOffers: {
|
|
48
|
+
limit: settings_1.DELIVER_ORDER_LIMIT,
|
|
49
|
+
page: 1 // page1から配送
|
|
50
|
+
} });
|
|
46
51
|
const sendOrderActionAttributes = {
|
|
47
52
|
project: params.transaction.project,
|
|
48
53
|
typeOf: factory.actionType.SendAction,
|
|
49
|
-
|
|
50
|
-
object: simpleOrder,
|
|
54
|
+
object: sendOrderObject,
|
|
51
55
|
agent: params.transaction.project,
|
|
52
56
|
recipient: {
|
|
53
57
|
typeOf: params.order.customer.typeOf,
|
|
@@ -22,7 +22,6 @@ const validation_1 = require("./placeOrderInProgress/validation");
|
|
|
22
22
|
const validateSeller_1 = require("./placeOrderInProgress/validation/validateSeller");
|
|
23
23
|
const validation_2 = require("./validation");
|
|
24
24
|
const errorHandler_1 = require("../../errorHandler");
|
|
25
|
-
const settings_1 = require("../../settings");
|
|
26
25
|
exports.POINT_AWARD_IDENTIFIER_NAME = 'pointAwardIdentifiers';
|
|
27
26
|
/**
|
|
28
27
|
* 取引開始
|
|
@@ -220,7 +219,8 @@ function createResult(params) {
|
|
|
220
219
|
orderDate: params.result.order.orderDate,
|
|
221
220
|
// OrderPaymentDueオプションを追加(2023-08-25~)
|
|
222
221
|
// 注文作成時のステータスとなる
|
|
223
|
-
orderStatus: (
|
|
222
|
+
// orderStatus: (USE_ORDER_PAYMENT_DUE_ON_PLACED) ? factory.orderStatus.OrderPaymentDue : factory.orderStatus.OrderProcessing,
|
|
223
|
+
orderStatus: factory.orderStatus.OrderPaymentDue,
|
|
224
224
|
isGift: false,
|
|
225
225
|
authorizeActions: params.authorizeActions
|
|
226
226
|
});
|
package/lib/chevre/settings.d.ts
CHANGED
|
@@ -37,13 +37,13 @@ export declare const DEFAULT_TASKS_EXPORT_AGENT_NAME: string;
|
|
|
37
37
|
export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
|
38
38
|
export declare const USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT: boolean;
|
|
39
39
|
export declare const USE_DELETE_EVENT_BY_ORDER: boolean;
|
|
40
|
-
export declare const USE_ORDER_PAYMENT_DUE_ON_PLACED: boolean;
|
|
41
40
|
export declare const USE_OPTIMIZE_TICKET_OFFER: boolean;
|
|
42
41
|
export declare const USE_ORDER_PAYMENT_METHOD_TYPE_OF: boolean;
|
|
43
42
|
export declare const USE_FETCH_API: boolean;
|
|
44
43
|
export declare const MONGO_MAX_TIME_MS: number;
|
|
45
44
|
export declare const MONGO_READ_PREFERENCE: string;
|
|
46
45
|
export declare const MONGO_AUTO_INDEX: boolean;
|
|
46
|
+
export declare const DELIVER_ORDER_LIMIT: number;
|
|
47
47
|
/**
|
|
48
48
|
* グローバル設定
|
|
49
49
|
*/
|
package/lib/chevre/settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.settings = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = exports.USE_FETCH_API = exports.USE_ORDER_PAYMENT_METHOD_TYPE_OF = exports.USE_OPTIMIZE_TICKET_OFFER = exports.
|
|
3
|
+
exports.settings = exports.DELIVER_ORDER_LIMIT = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = exports.USE_FETCH_API = exports.USE_ORDER_PAYMENT_METHOD_TYPE_OF = exports.USE_OPTIMIZE_TICKET_OFFER = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.MAX_NUM_CREDIT_CARD_PAYMENT_METHOD = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
|
|
4
4
|
const factory = require("./factory");
|
|
5
5
|
const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
|
|
6
6
|
? process.env.INFORM_TRANSACTION_URL.split(' ')
|
|
@@ -61,7 +61,6 @@ exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = `${process.env.GAE_APPLICATION}:${proc
|
|
|
61
61
|
exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
|
|
62
62
|
exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = process.env.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT === '1';
|
|
63
63
|
exports.USE_DELETE_EVENT_BY_ORDER = process.env.USE_DELETE_EVENT_BY_ORDER === '1';
|
|
64
|
-
exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = process.env.USE_ORDER_PAYMENT_DUE_ON_PLACED === '1';
|
|
65
64
|
exports.USE_OPTIMIZE_TICKET_OFFER = process.env.USE_OPTIMIZE_TICKET_OFFER === '1';
|
|
66
65
|
exports.USE_ORDER_PAYMENT_METHOD_TYPE_OF = process.env.USE_ORDER_PAYMENT_METHOD_TYPE_OF === '1';
|
|
67
66
|
exports.USE_FETCH_API = process.env.USE_FETCH_API === '1';
|
|
@@ -73,6 +72,10 @@ exports.MONGO_READ_PREFERENCE = (typeof process.env.MONGO_READ_PREFERENCE === 's
|
|
|
73
72
|
? process.env.MONGO_READ_PREFERENCE
|
|
74
73
|
: 'primaryPreferred';
|
|
75
74
|
exports.MONGO_AUTO_INDEX = process.env.MONGO_AUTO_INDEX === '1';
|
|
75
|
+
exports.DELIVER_ORDER_LIMIT = (typeof process.env.DELIVER_ORDER_LIMIT === 'string')
|
|
76
|
+
? Number(process.env.DELIVER_ORDER_LIMIT)
|
|
77
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
78
|
+
: 50;
|
|
76
79
|
/**
|
|
77
80
|
* グローバル設定
|
|
78
81
|
*/
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/credential-providers": "3.433.0",
|
|
13
|
-
"@chevre/factory": "4.351.0-alpha.
|
|
13
|
+
"@chevre/factory": "4.351.0-alpha.7",
|
|
14
14
|
"@cinerino/sdk": "5.8.0-alpha.1",
|
|
15
15
|
"@motionpicture/coa-service": "9.2.0",
|
|
16
16
|
"@motionpicture/gmo-service": "5.3.0-alpha.0",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "21.20.0-alpha.
|
|
118
|
+
"version": "21.20.0-alpha.14"
|
|
119
119
|
}
|