@chevre/domain 21.2.0-alpha.62 → 21.2.0-alpha.64
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/deleteTasksByName.ts +1 -1
- package/example/src/chevre/searchReservationNumbersByOrderNumbers.ts +37 -1
- package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +1 -1
- package/lib/chevre/repo/order.d.ts +16 -1
- package/lib/chevre/repo/order.js +24 -4
- package/lib/chevre/service/transaction/returnOrder.js +52 -8
- package/package.json +2 -2
|
@@ -4,6 +4,7 @@ import * as mongoose from 'mongoose';
|
|
|
4
4
|
import { chevre } from '../../../lib/index';
|
|
5
5
|
|
|
6
6
|
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
const orderNumbers = ['TTT9-4703865-8892744', 'TTT9-4703865-8398074', 'SSK6-4815238-3010844'];
|
|
7
8
|
|
|
8
9
|
async function main() {
|
|
9
10
|
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
@@ -11,10 +12,45 @@ async function main() {
|
|
|
11
12
|
const orderRepo = new chevre.repository.Order(mongoose.connection);
|
|
12
13
|
|
|
13
14
|
const reservatioForIds = await orderRepo.searchReservationForIdsByOrderNumbers({
|
|
14
|
-
orderNumber: { $in:
|
|
15
|
+
orderNumber: { $in: orderNumbers }
|
|
15
16
|
});
|
|
16
17
|
console.log('reservatioForIds found', reservatioForIds);
|
|
17
18
|
console.log(reservatioForIds.length, 'reservatioForIds found');
|
|
19
|
+
|
|
20
|
+
const reservationNumbers = await orderRepo.searchReservationNumbersByOrderNumbers({
|
|
21
|
+
orderNumber: { $in: orderNumbers }
|
|
22
|
+
});
|
|
23
|
+
console.log('reservationNumbers found', reservationNumbers);
|
|
24
|
+
console.log(reservationNumbers.length, 'reservationNumbers found');
|
|
25
|
+
|
|
26
|
+
const offers = await orderRepo.searchAcceptedOffersByOrderNumbers({
|
|
27
|
+
orderNumber: { $in: orderNumbers }
|
|
28
|
+
});
|
|
29
|
+
console.log('offers found', offers);
|
|
30
|
+
console.log(offers.length, 'offers found');
|
|
31
|
+
|
|
32
|
+
const movieTickets: any[] = [];
|
|
33
|
+
offers.forEach((offer) => {
|
|
34
|
+
const movieTicketTypeChargeSpecExists = offer.priceSpecification.priceComponent.some((component) => {
|
|
35
|
+
return component.typeOf === chevre.factory.priceSpecificationType.MovieTicketTypeChargeSpecification;
|
|
36
|
+
});
|
|
37
|
+
if (movieTicketTypeChargeSpecExists) {
|
|
38
|
+
offer.priceSpecification.priceComponent.forEach((component) => {
|
|
39
|
+
if (component.typeOf === chevre.factory.priceSpecificationType.UnitPriceSpecification) {
|
|
40
|
+
if (Array.isArray(component.appliesToMovieTicket)) {
|
|
41
|
+
component.appliesToMovieTicket.forEach((appliesToMovieTicket) => {
|
|
42
|
+
movieTickets.push({
|
|
43
|
+
identifier: appliesToMovieTicket.identifier,
|
|
44
|
+
paymentMethodType: appliesToMovieTicket.serviceOutput.typeOf,
|
|
45
|
+
offerId: offer.id
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
console.log('movieTickets found', movieTickets);
|
|
18
54
|
}
|
|
19
55
|
|
|
20
56
|
main()
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import { Schema } from 'mongoose';
|
|
26
|
-
declare const modelName = "
|
|
26
|
+
declare const modelName = "OfferItemCondition";
|
|
27
27
|
/**
|
|
28
28
|
* アイテムコンディションスキーマ
|
|
29
29
|
*/
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.schema = exports.modelName = void 0;
|
|
4
4
|
const mongoose_1 = require("mongoose");
|
|
5
5
|
const writeConcern_1 = require("../writeConcern");
|
|
6
|
-
const modelName = '
|
|
6
|
+
const modelName = 'OfferItemCondition';
|
|
7
7
|
exports.modelName = modelName;
|
|
8
8
|
/**
|
|
9
9
|
* アイテムコンディションスキーマ
|
|
@@ -94,7 +94,11 @@ export declare class MongoRepository {
|
|
|
94
94
|
/**
|
|
95
95
|
* オファー展開の注文検索
|
|
96
96
|
*/
|
|
97
|
-
searchWithUnwoundAcceptedOffer(params: factory.order.ISearchConditions, projection?:
|
|
97
|
+
searchWithUnwoundAcceptedOffer(params: factory.order.ISearchConditions, projection?: {
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
}): Promise<Omit<factory.order.IOrder[], 'acceptedOffers'> & {
|
|
100
|
+
acceptedOffers?: factory.order.IAcceptedOffer<factory.order.IItemOffered> | factory.order.IAcceptedOffer<factory.order.IItemOffered>[];
|
|
101
|
+
}>;
|
|
98
102
|
/**
|
|
99
103
|
* 特典口座情報が未保管であれば保管する
|
|
100
104
|
*/
|
|
@@ -118,5 +122,16 @@ export declare class MongoRepository {
|
|
|
118
122
|
$in: string[];
|
|
119
123
|
};
|
|
120
124
|
}): Promise<string[]>;
|
|
125
|
+
/**
|
|
126
|
+
* 注文に含まれるacceptedOffersを検索する
|
|
127
|
+
*/
|
|
128
|
+
searchAcceptedOffersByOrderNumbers(params: {
|
|
129
|
+
orderNumber: {
|
|
130
|
+
$in: string[];
|
|
131
|
+
};
|
|
132
|
+
}): Promise<{
|
|
133
|
+
id: string;
|
|
134
|
+
priceSpecification: factory.order.ITicketPriceSpecification;
|
|
135
|
+
}[]>;
|
|
121
136
|
getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
|
|
122
137
|
}
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -1002,12 +1002,12 @@ class MongoRepository {
|
|
|
1002
1002
|
if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
1003
1003
|
return [];
|
|
1004
1004
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1005
|
+
return this.orderModel.distinct('acceptedOffers.itemOffered.reservationNumber', {
|
|
1006
|
+
'acceptedOffers.itemOffered.reservationNumber': { $exists: true },
|
|
1007
|
+
orderNumber: { $in: params.orderNumber.$in }
|
|
1007
1008
|
})
|
|
1008
1009
|
.setOptions({ maxTimeMS: 10000 })
|
|
1009
1010
|
.exec();
|
|
1010
|
-
return [...new Set(reservationNumbers)];
|
|
1011
1011
|
});
|
|
1012
1012
|
}
|
|
1013
1013
|
/**
|
|
@@ -1020,12 +1020,32 @@ class MongoRepository {
|
|
|
1020
1020
|
}
|
|
1021
1021
|
return this.orderModel.distinct('acceptedOffers.itemOffered.reservationFor.id', {
|
|
1022
1022
|
'acceptedOffers.itemOffered.reservationFor.id': { $exists: true },
|
|
1023
|
-
orderNumber: params.orderNumber.$in
|
|
1023
|
+
orderNumber: { $in: params.orderNumber.$in }
|
|
1024
1024
|
})
|
|
1025
1025
|
.setOptions({ maxTimeMS: 10000 })
|
|
1026
1026
|
.exec();
|
|
1027
1027
|
});
|
|
1028
1028
|
}
|
|
1029
|
+
/**
|
|
1030
|
+
* 注文に含まれるacceptedOffersを検索する
|
|
1031
|
+
*/
|
|
1032
|
+
searchAcceptedOffersByOrderNumbers(params) {
|
|
1033
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1034
|
+
if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
1035
|
+
return [];
|
|
1036
|
+
}
|
|
1037
|
+
const aggregate = this.orderModel.aggregate();
|
|
1038
|
+
aggregate.unwind('$acceptedOffers');
|
|
1039
|
+
aggregate.match({ orderNumber: { $in: params.orderNumber.$in } });
|
|
1040
|
+
aggregate.project({
|
|
1041
|
+
_id: 0,
|
|
1042
|
+
id: '$acceptedOffers.id',
|
|
1043
|
+
priceSpecification: '$acceptedOffers.priceSpecification'
|
|
1044
|
+
});
|
|
1045
|
+
return aggregate.option({ maxTimeMS: 10000 })
|
|
1046
|
+
.exec();
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1029
1049
|
getCursor(conditions, projection) {
|
|
1030
1050
|
return this.orderModel.find(conditions, projection)
|
|
1031
1051
|
.sort({ orderDate: factory.sortType.Descending })
|
|
@@ -25,7 +25,7 @@ function start(params) {
|
|
|
25
25
|
// tslint:disable-next-line:max-func-body-length
|
|
26
26
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
const now = new Date();
|
|
28
|
-
const { eventIds, offerIds, orders } = yield fixOrders(params)(repos);
|
|
28
|
+
const { acceptedOffers, eventIds, offerIds, orders } = yield fixOrders(params)(repos);
|
|
29
29
|
// sellerはorderから自動取得
|
|
30
30
|
const seller = yield repos.seller.findById({ id: String(orders[0].seller.id) }, { additionalProperty: 0, paymentAccepted: 0 });
|
|
31
31
|
yield validateOrder({ orders })(repos);
|
|
@@ -63,6 +63,7 @@ function start(params) {
|
|
|
63
63
|
}
|
|
64
64
|
const policiesByOffer = yield searchPoliciesByOffer({ offers })(repos);
|
|
65
65
|
const appliedReturnPolicy = findApplicableReturnPolicy({
|
|
66
|
+
acceptedOffers,
|
|
66
67
|
events,
|
|
67
68
|
offerItemConditions,
|
|
68
69
|
orders,
|
|
@@ -156,7 +157,10 @@ function fixOrders(params) {
|
|
|
156
157
|
const eventIds = yield repos.order.searchReservationForIdsByOrderNumbers({
|
|
157
158
|
orderNumber: { $in: [params.object.order[0].orderNumber] }
|
|
158
159
|
});
|
|
159
|
-
|
|
160
|
+
const acceptedOffers = yield repos.order.searchAcceptedOffersByOrderNumbers({
|
|
161
|
+
orderNumber: { $in: [params.object.order[0].orderNumber] }
|
|
162
|
+
});
|
|
163
|
+
return { acceptedOffers, eventIds, offerIds, orders };
|
|
160
164
|
});
|
|
161
165
|
}
|
|
162
166
|
function validateOrder(params) {
|
|
@@ -309,14 +313,21 @@ function findApplicableReturnPolicy(params) {
|
|
|
309
313
|
throw new factory.errors.Argument('Seller', 'has no applicable return policies');
|
|
310
314
|
}
|
|
311
315
|
// オファーの返品ポリシーから返品手数料タイプを決定する
|
|
312
|
-
const { returnFees } = validateOffersReturnPolicy({
|
|
316
|
+
const { returnFees, returnFeesMovieTicket } = validateOffersReturnPolicy({
|
|
317
|
+
acceptedOffers: params.acceptedOffers,
|
|
318
|
+
offers: params.offers,
|
|
319
|
+
policiesByOffer: params.policiesByOffer
|
|
320
|
+
});
|
|
313
321
|
// restockingFeeが最低のポリシーを自動選択
|
|
314
322
|
let appliedReturnPolicy = applicalbleReturnPolicies[0];
|
|
315
323
|
applicalbleReturnPolicies.forEach((returnPolicy) => {
|
|
316
|
-
|
|
317
|
-
|
|
324
|
+
var _a, _b;
|
|
325
|
+
const appliedReturnPolicyRestockingFeeValue = (_a = appliedReturnPolicy.restockingFee) === null || _a === void 0 ? void 0 : _a.value;
|
|
326
|
+
const restockingFeeValue = (_b = returnPolicy.restockingFee) === null || _b === void 0 ? void 0 : _b.value;
|
|
327
|
+
const appliedReturnPolicyRestockingFee = (typeof appliedReturnPolicyRestockingFeeValue === 'number')
|
|
328
|
+
? appliedReturnPolicyRestockingFeeValue
|
|
318
329
|
: 0;
|
|
319
|
-
const restockingFee = (typeof
|
|
330
|
+
const restockingFee = (typeof restockingFeeValue === 'number') ? restockingFeeValue : 0;
|
|
320
331
|
if (restockingFee < appliedReturnPolicyRestockingFee) {
|
|
321
332
|
appliedReturnPolicy = returnPolicy;
|
|
322
333
|
}
|
|
@@ -325,6 +336,7 @@ function findApplicableReturnPolicy(params) {
|
|
|
325
336
|
merchantReturnDays: appliedReturnPolicy.merchantReturnDays,
|
|
326
337
|
restockingFee: appliedReturnPolicy.restockingFee,
|
|
327
338
|
returnFees,
|
|
339
|
+
returnFeesMovieTicket,
|
|
328
340
|
typeOf: 'MerchantReturnPolicy'
|
|
329
341
|
};
|
|
330
342
|
}
|
|
@@ -365,8 +377,40 @@ function validateOffersReturnPolicy(params) {
|
|
|
365
377
|
else {
|
|
366
378
|
throw new factory.errors.NotImplemented('returnFees not defined');
|
|
367
379
|
}
|
|
368
|
-
//
|
|
369
|
-
|
|
380
|
+
// 決済カード取消ポリシーを確定(2023-05-23~)
|
|
381
|
+
const returnFeesMovieTicket = [];
|
|
382
|
+
params.acceptedOffers.forEach((acceptedOffer) => {
|
|
383
|
+
const unitPriceOffer = params.offers.find((offer) => offer.id === acceptedOffer.id);
|
|
384
|
+
if (unitPriceOffer === undefined) {
|
|
385
|
+
throw new factory.errors.NotFound(`UnitPriceOffer ${acceptedOffer.id}`);
|
|
386
|
+
}
|
|
387
|
+
if (!Array.isArray(unitPriceOffer.hasMerchantReturnPolicy) || unitPriceOffer.hasMerchantReturnPolicy.length === 0) {
|
|
388
|
+
throw new factory.errors.NotFound(`offer.hasMerchantReturnPolicy ${acceptedOffer.id}`);
|
|
389
|
+
}
|
|
390
|
+
const hasMerchantReturnPolicy = unitPriceOffer.hasMerchantReturnPolicy[0];
|
|
391
|
+
const policyByOffer = params.policiesByOffer.find((policy) => policy.id === hasMerchantReturnPolicy.id);
|
|
392
|
+
if (policyByOffer === undefined) {
|
|
393
|
+
throw new factory.errors.NotFound(`MerchantReturnPolicy acceptedOffer:${acceptedOffer.id}`);
|
|
394
|
+
}
|
|
395
|
+
const movieTicketTypeChargeSpecExists = acceptedOffer.priceSpecification.priceComponent.some((component) => {
|
|
396
|
+
return component.typeOf === factory.priceSpecificationType.MovieTicketTypeChargeSpecification;
|
|
397
|
+
});
|
|
398
|
+
if (movieTicketTypeChargeSpecExists) {
|
|
399
|
+
acceptedOffer.priceSpecification.priceComponent.forEach((component) => {
|
|
400
|
+
if (component.typeOf === factory.priceSpecificationType.UnitPriceSpecification) {
|
|
401
|
+
if (Array.isArray(component.appliesToMovieTicket)) {
|
|
402
|
+
component.appliesToMovieTicket.forEach((appliesToMovieTicket) => {
|
|
403
|
+
returnFeesMovieTicket.push({
|
|
404
|
+
identifier: String(appliesToMovieTicket.identifier),
|
|
405
|
+
returnFees: policyByOffer.customerRemorseReturnFeesMovieTicket
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
return { returnFees, returnFeesMovieTicket };
|
|
370
414
|
}
|
|
371
415
|
function validateAppliedReturnPolicy(params) {
|
|
372
416
|
var _a;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.313.0-alpha.
|
|
12
|
+
"@chevre/factory": "4.313.0-alpha.6",
|
|
13
13
|
"@cinerino/sdk": "3.156.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"postversion": "git push origin --tags",
|
|
118
118
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
119
119
|
},
|
|
120
|
-
"version": "21.2.0-alpha.
|
|
120
|
+
"version": "21.2.0-alpha.64"
|
|
121
121
|
}
|