@chevre/domain 21.6.0-alpha.8 → 21.6.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/example/src/chevre/migrateMovieAvailabilityStarts.ts +29 -16
- package/example/src/chevre/searchSellers.ts +28 -0
- package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +0 -9
- package/lib/chevre/repo/mongoose/schemas/creativeWork.js +3 -3
- package/lib/chevre/repo/mongoose/schemas/seller.js +12 -0
- package/lib/chevre/repo/seller.js +14 -2
- package/lib/chevre/service/assetTransaction/refund/factory.js +13 -4
- package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +7 -3
- package/lib/chevre/service/transaction/returnOrder.js +124 -95
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
2
|
+
import * as moment from 'moment-timezone';
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
4
|
|
|
5
5
|
import { chevre } from '../../../lib/index';
|
|
@@ -15,7 +15,7 @@ async function main() {
|
|
|
15
15
|
|
|
16
16
|
const cursor = creativeWorkRepo.getCursor(
|
|
17
17
|
{
|
|
18
|
-
'offers.availabilityEnds': { $exists: true }
|
|
18
|
+
// 'offers.availabilityEnds': { $exists: true }
|
|
19
19
|
},
|
|
20
20
|
{}
|
|
21
21
|
);
|
|
@@ -23,7 +23,8 @@ async function main() {
|
|
|
23
23
|
|
|
24
24
|
let i = 0;
|
|
25
25
|
let updateCount = 0;
|
|
26
|
-
let datePublishedUndefinedCount = 0;
|
|
26
|
+
// let datePublishedUndefinedCount = 0;
|
|
27
|
+
// let datePublishedIsAfterNowCount = 0;
|
|
27
28
|
await cursor.eachAsync(async (doc) => {
|
|
28
29
|
i += 1;
|
|
29
30
|
const movie: chevre.factory.creativeWork.movie.ICreativeWork = doc.toObject();
|
|
@@ -34,22 +35,32 @@ async function main() {
|
|
|
34
35
|
if (!(createdAt instanceof Date)) {
|
|
35
36
|
throw new Error('createdAt not Date');
|
|
36
37
|
}
|
|
37
|
-
const alreadyMigrated = availabilityStarts instanceof Date
|
|
38
|
+
const alreadyMigrated = availabilityStarts instanceof Date
|
|
39
|
+
&& moment(availabilityStarts)
|
|
40
|
+
.isSame(moment(createdAt)
|
|
41
|
+
.tz('Asia/Tokyo')
|
|
42
|
+
.startOf('day')
|
|
43
|
+
);
|
|
38
44
|
|
|
39
45
|
if (alreadyMigrated) {
|
|
40
|
-
console.log(
|
|
46
|
+
console.log(
|
|
47
|
+
'already exist...', movie.project.id, movie.id, movie.identifier, availabilityStarts, availabilityEnds, createdAt, i);
|
|
48
|
+
|
|
49
|
+
// if (moment(movie.datePublished)
|
|
50
|
+
// .isAfter(moment())) {
|
|
51
|
+
// datePublishedIsAfterNowCount += 1;
|
|
52
|
+
// }
|
|
41
53
|
} else {
|
|
42
|
-
if (movie.datePublished === undefined) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
54
|
+
// if (movie.datePublished === undefined) {
|
|
55
|
+
// console.error('movie.datePublished undefined', movie.project.id, movie.id, movie.identifier, i);
|
|
56
|
+
// // throw new Error('movie.datePublished undefined');
|
|
57
|
+
// datePublishedUndefinedCount += 1;
|
|
58
|
+
// }
|
|
47
59
|
|
|
48
|
-
availabilityStarts = (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.toDate();
|
|
60
|
+
availabilityStarts = moment(createdAt)
|
|
61
|
+
.tz('Asia/Tokyo')
|
|
62
|
+
.startOf('day')
|
|
63
|
+
.toDate();
|
|
53
64
|
console.log('updating movie...', movie.project.id, movie.id, movie.identifier, availabilityStarts, availabilityEnds, i);
|
|
54
65
|
await creativeWorkRepo.saveMovie(<any>{
|
|
55
66
|
id: String(movie.id),
|
|
@@ -62,7 +73,9 @@ async function main() {
|
|
|
62
73
|
|
|
63
74
|
console.log(i, 'creativeWorks checked');
|
|
64
75
|
console.log(updateCount, 'creativeWorks updated');
|
|
65
|
-
console.log(datePublishedUndefinedCount, 'datePublishedUndefinedCount');
|
|
76
|
+
// console.log(datePublishedUndefinedCount, 'datePublishedUndefinedCount');
|
|
77
|
+
// console.log(datePublishedIsAfterNowCount, 'datePublishedIsAfterNowCount');
|
|
78
|
+
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
main()
|
|
@@ -0,0 +1,28 @@
|
|
|
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, { autoIndex: true });
|
|
10
|
+
|
|
11
|
+
const sellerRepo = new chevre.repository.Seller(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const sellers = await sellerRepo.search(
|
|
14
|
+
{
|
|
15
|
+
project: { id: { $eq: project.id } },
|
|
16
|
+
paymentAccepted: { paymentMethodType: { $eq: 'Cash' } },
|
|
17
|
+
hasMerchantReturnPolicy: { applicablePaymentMethod: {} }
|
|
18
|
+
},
|
|
19
|
+
['name'],
|
|
20
|
+
[]
|
|
21
|
+
);
|
|
22
|
+
console.log('sellers found', sellers);
|
|
23
|
+
console.log(sellers.length, 'sellers found');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
main()
|
|
27
|
+
.then()
|
|
28
|
+
.catch(console.error);
|
|
@@ -55,18 +55,15 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
55
55
|
typeOf: string;
|
|
56
56
|
name?: any;
|
|
57
57
|
project?: any;
|
|
58
|
-
alternateName?: string | undefined;
|
|
59
58
|
description?: string | undefined;
|
|
60
59
|
additionalProperty?: any;
|
|
61
60
|
identifier?: string | undefined;
|
|
62
61
|
duration?: string | undefined;
|
|
63
62
|
alternativeHeadline?: string | undefined;
|
|
64
|
-
copyrightHolder?: any;
|
|
65
63
|
copyrightYear?: number | undefined;
|
|
66
64
|
datePublished?: Date | undefined;
|
|
67
65
|
distributor?: any;
|
|
68
66
|
headline?: string | undefined;
|
|
69
|
-
license?: string | undefined;
|
|
70
67
|
thumbnailUrl?: string | undefined;
|
|
71
68
|
contentRating?: string | undefined;
|
|
72
69
|
offers?: any;
|
|
@@ -74,18 +71,15 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
74
71
|
typeOf: string;
|
|
75
72
|
name?: any;
|
|
76
73
|
project?: any;
|
|
77
|
-
alternateName?: string | undefined;
|
|
78
74
|
description?: string | undefined;
|
|
79
75
|
additionalProperty?: any;
|
|
80
76
|
identifier?: string | undefined;
|
|
81
77
|
duration?: string | undefined;
|
|
82
78
|
alternativeHeadline?: string | undefined;
|
|
83
|
-
copyrightHolder?: any;
|
|
84
79
|
copyrightYear?: number | undefined;
|
|
85
80
|
datePublished?: Date | undefined;
|
|
86
81
|
distributor?: any;
|
|
87
82
|
headline?: string | undefined;
|
|
88
|
-
license?: string | undefined;
|
|
89
83
|
thumbnailUrl?: string | undefined;
|
|
90
84
|
contentRating?: string | undefined;
|
|
91
85
|
offers?: any;
|
|
@@ -93,18 +87,15 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
93
87
|
typeOf: string;
|
|
94
88
|
name?: any;
|
|
95
89
|
project?: any;
|
|
96
|
-
alternateName?: string | undefined;
|
|
97
90
|
description?: string | undefined;
|
|
98
91
|
additionalProperty?: any;
|
|
99
92
|
identifier?: string | undefined;
|
|
100
93
|
duration?: string | undefined;
|
|
101
94
|
alternativeHeadline?: string | undefined;
|
|
102
|
-
copyrightHolder?: any;
|
|
103
95
|
copyrightYear?: number | undefined;
|
|
104
96
|
datePublished?: Date | undefined;
|
|
105
97
|
distributor?: any;
|
|
106
98
|
headline?: string | undefined;
|
|
107
|
-
license?: string | undefined;
|
|
108
99
|
thumbnailUrl?: string | undefined;
|
|
109
100
|
contentRating?: string | undefined;
|
|
110
101
|
offers?: any;
|
|
@@ -16,15 +16,15 @@ const schema = new mongoose_1.Schema({
|
|
|
16
16
|
},
|
|
17
17
|
identifier: String,
|
|
18
18
|
name: mongoose_1.SchemaTypes.Mixed,
|
|
19
|
-
alternateName: String,
|
|
19
|
+
// alternateName: String,
|
|
20
20
|
alternativeHeadline: String,
|
|
21
21
|
description: String,
|
|
22
|
-
copyrightHolder:
|
|
22
|
+
// copyrightHolder: SchemaTypes.Mixed,
|
|
23
23
|
copyrightYear: Number,
|
|
24
24
|
datePublished: Date,
|
|
25
25
|
distributor: mongoose_1.SchemaTypes.Mixed,
|
|
26
26
|
headline: String,
|
|
27
|
-
license: String,
|
|
27
|
+
// license: String,
|
|
28
28
|
thumbnailUrl: String,
|
|
29
29
|
duration: String,
|
|
30
30
|
contentRating: String,
|
|
@@ -75,6 +75,18 @@ schema.index({ additionalProperty: 1, branchCode: 1 }, {
|
|
|
75
75
|
additionalProperty: { $exists: true }
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
schema.index({ 'paymentAccepted.paymentMethodType': 1, branchCode: 1 }, {
|
|
79
|
+
name: 'searchByPaymentAccepted',
|
|
80
|
+
partialFilterExpression: {
|
|
81
|
+
'paymentAccepted.paymentMethodType': { $exists: true }
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
schema.index({ 'hasMerchantReturnPolicy.applicablePaymentMethod': 1, branchCode: 1 }, {
|
|
85
|
+
name: 'searchByHasMerchantReturnPolicyApplicablePaymentMethod',
|
|
86
|
+
partialFilterExpression: {
|
|
87
|
+
'hasMerchantReturnPolicy.applicablePaymentMethod': { $exists: true }
|
|
88
|
+
}
|
|
89
|
+
});
|
|
78
90
|
schema.index({ 'hasMerchantReturnPolicy.itemCondition.id': 1, branchCode: 1 }, {
|
|
79
91
|
name: 'searchByHasMerchantReturnPolicyItemConditionId',
|
|
80
92
|
partialFilterExpression: {
|
|
@@ -34,7 +34,7 @@ class MongoRepository {
|
|
|
34
34
|
}
|
|
35
35
|
// tslint:disable-next-line:max-func-body-length
|
|
36
36
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
37
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
38
38
|
// MongoDB検索条件
|
|
39
39
|
const andConditions = [];
|
|
40
40
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
@@ -120,7 +120,19 @@ class MongoRepository {
|
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
const
|
|
123
|
+
const paymentAcceptedEq = (_p = (_o = params.paymentAccepted) === null || _o === void 0 ? void 0 : _o.paymentMethodType) === null || _p === void 0 ? void 0 : _p.$eq;
|
|
124
|
+
if (typeof paymentAcceptedEq === 'string') {
|
|
125
|
+
andConditions.push({
|
|
126
|
+
'paymentAccepted.paymentMethodType': { $exists: true, $eq: paymentAcceptedEq }
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const hasMerchantReturnApplicablePaymentMethodEq = (_r = (_q = params.hasMerchantReturnPolicy) === null || _q === void 0 ? void 0 : _q.applicablePaymentMethod) === null || _r === void 0 ? void 0 : _r.$eq;
|
|
130
|
+
if (typeof hasMerchantReturnApplicablePaymentMethodEq === 'string') {
|
|
131
|
+
andConditions.push({
|
|
132
|
+
'hasMerchantReturnPolicy.applicablePaymentMethod': { $exists: true, $eq: hasMerchantReturnApplicablePaymentMethodEq }
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const hasMerchantReturnPolicyItemConditionIdEq = (_u = (_t = (_s = params.hasMerchantReturnPolicy) === null || _s === void 0 ? void 0 : _s.itemCondition) === null || _t === void 0 ? void 0 : _t.id) === null || _u === void 0 ? void 0 : _u.$eq;
|
|
124
136
|
if (typeof hasMerchantReturnPolicyItemConditionIdEq === 'string') {
|
|
125
137
|
andConditions.push({
|
|
126
138
|
'hasMerchantReturnPolicy.itemCondition.id': {
|
|
@@ -6,7 +6,7 @@ exports.createStartParams = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
const factory = require("../../../factory");
|
|
8
8
|
function createStartParams(params) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f;
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
10
10
|
const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.typeOf;
|
|
11
11
|
if (typeof paymentMethodType !== 'string') {
|
|
12
12
|
throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
|
|
@@ -19,6 +19,17 @@ function createStartParams(params) {
|
|
|
19
19
|
const name = (_d = params.object.paymentMethod) === null || _d === void 0 ? void 0 : _d.name;
|
|
20
20
|
const informPaymentParams = createInformPaymentParams({ paymentService: params.paymentService });
|
|
21
21
|
const accountId = (_f = (_e = params.payAction.object[0]) === null || _e === void 0 ? void 0 : _e.paymentMethod) === null || _f === void 0 ? void 0 : _f.accountId;
|
|
22
|
+
// 手数料は、CreditCardIFかつカード通貨区分が存在しない場合のみ設定すればよい
|
|
23
|
+
let refundFee;
|
|
24
|
+
if (((_g = params.paymentService) === null || _g === void 0 ? void 0 : _g.typeOf) === factory.service.paymentService.PaymentServiceType.CreditCard) {
|
|
25
|
+
// カード通貨区分の存在する決済サービスを考慮(2023-08-09~)
|
|
26
|
+
const paymentServiceOutputAmountCurrency = (_j = (_h = params.paymentService.serviceOutput) === null || _h === void 0 ? void 0 : _h.amount) === null || _j === void 0 ? void 0 : _j.currency;
|
|
27
|
+
if (typeof paymentServiceOutputAmountCurrency !== 'string') {
|
|
28
|
+
if (typeof params.object.refundFee === 'number') {
|
|
29
|
+
refundFee = params.object.refundFee;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
return {
|
|
23
34
|
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
24
35
|
transactionNumber: params.transactionNumber,
|
|
@@ -29,9 +40,7 @@ function createStartParams(params) {
|
|
|
29
40
|
? params.payAction.object[0].id
|
|
30
41
|
: '', onPaymentStatusChanged: { informPayment: informPaymentParams }, paymentMethod: Object.assign({ additionalProperty: (Array.isArray(additionalProperty)) ? additionalProperty : [], name: (typeof name === 'string') ? name : paymentMethodType, paymentMethodId: paymentMethodId, typeOf: paymentMethodType }, (Array.isArray(params.payAction.object) && params.payAction.object.length > 0)
|
|
31
42
|
? { totalPaymentDue: params.payAction.object[0].paymentMethod.totalPaymentDue }
|
|
32
|
-
: undefined) }, (typeof
|
|
33
|
-
? { refundFee: params.object.refundFee }
|
|
34
|
-
: undefined),
|
|
43
|
+
: undefined) }, (typeof refundFee === 'number') ? { refundFee } : undefined),
|
|
35
44
|
expires: params.expires
|
|
36
45
|
};
|
|
37
46
|
}
|
|
@@ -211,11 +211,15 @@ function validateNumItems(params) {
|
|
|
211
211
|
}
|
|
212
212
|
exports.validateNumItems = validateNumItems;
|
|
213
213
|
function validatePaymentMethods(params) {
|
|
214
|
-
debug('processing validatePaymentMethods...maxNumCreditCardPaymentMethod:', settings_1.settings.maxNumCreditCardPaymentMethod);
|
|
215
214
|
if (typeof settings_1.settings.maxNumCreditCardPaymentMethod === 'number') {
|
|
216
215
|
// CreditCard IFの決済方法の最大値検証
|
|
217
|
-
const creditCardPaymentMethodCount = params.order.paymentMethods.filter((p) =>
|
|
218
|
-
|
|
216
|
+
const creditCardPaymentMethodCount = params.order.paymentMethods.filter((p) => {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
// カード通貨区分の存在する決済サービスを考慮(2023-08-09~)
|
|
219
|
+
const serviceOutputAmountCurrency = (_b = (_a = p.issuedThrough.serviceOutput) === null || _a === void 0 ? void 0 : _a.amount) === null || _b === void 0 ? void 0 : _b.currency;
|
|
220
|
+
return p.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.CreditCard
|
|
221
|
+
&& typeof serviceOutputAmountCurrency !== 'string';
|
|
222
|
+
}).length;
|
|
219
223
|
if (creditCardPaymentMethodCount > settings_1.settings.maxNumCreditCardPaymentMethod) {
|
|
220
224
|
throw new factory.errors.Argument('Transaction', (0, util_1.format)(`Number of paymentMethods issued through ${factory.service.paymentService.PaymentServiceType.CreditCard} payment service must be less than equal to %s`, settings_1.settings.maxNumCreditCardPaymentMethod));
|
|
221
225
|
}
|
|
@@ -155,8 +155,8 @@ function fixOrders(params) {
|
|
|
155
155
|
// 不要な属性は参照しない
|
|
156
156
|
acceptedOffers: 0,
|
|
157
157
|
customer: 0,
|
|
158
|
-
orderedItem: 0
|
|
159
|
-
paymentMethods: 0
|
|
158
|
+
orderedItem: 0
|
|
159
|
+
// paymentMethods: 0 // 適用決済方法検証に必要
|
|
160
160
|
});
|
|
161
161
|
if (orders.length !== params.object.order.length) {
|
|
162
162
|
throw new factory.errors.NotFound('Order');
|
|
@@ -268,104 +268,20 @@ function findApplicableReturnPolicy(params) {
|
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
270
|
const returnPolicies = params.returnPolicies;
|
|
271
|
-
const returningDate = moment(params.returningDate);
|
|
271
|
+
// const returningDate = moment(params.returningDate);
|
|
272
272
|
let applicalbleReturnPolicies = [];
|
|
273
273
|
if (params.reason === factory.transaction.returnOrder.Reason.Customer) {
|
|
274
274
|
// 適用可能なポリシーにフィルター
|
|
275
275
|
// tslint:disable-next-line:max-func-body-length
|
|
276
276
|
applicalbleReturnPolicies = returnPolicies.filter((returnPolicy) => {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const merchantReturnDays = returnPolicy.merchantReturnDays;
|
|
288
|
-
if (typeof merchantReturnDays === 'number') {
|
|
289
|
-
// 返品適用日数を確認する
|
|
290
|
-
const everyOrderApplicable = params.orders.every((order) => {
|
|
291
|
-
const mustBeReturnedUntil = moment(order.orderDate)
|
|
292
|
-
.add(merchantReturnDays, 'days');
|
|
293
|
-
return mustBeReturnedUntil.isSameOrAfter(returningDate);
|
|
294
|
-
});
|
|
295
|
-
// 全注文について日数の確認ができれば適用
|
|
296
|
-
if (everyOrderApplicable) {
|
|
297
|
-
satisfyMerchantReturnDays = true;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
// 日数制限なし
|
|
302
|
-
satisfyMerchantReturnDays = true;
|
|
303
|
-
}
|
|
304
|
-
// イベント開始猶予を検証する(2023-05-22~)
|
|
305
|
-
let satisfyItemCondition = true;
|
|
306
|
-
if (offerItemCondition !== undefined) {
|
|
307
|
-
let satisfyGracePeriodMaxValue = true;
|
|
308
|
-
let satisfyGracePeriodMinValue = true;
|
|
309
|
-
// 全イベントについて猶予の確認ができれば適用
|
|
310
|
-
const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
|
|
311
|
-
const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
|
|
312
|
-
if (typeof gracePeriodMaxValue === 'number') {
|
|
313
|
-
satisfyGracePeriodMaxValue = params.events.every((event) => {
|
|
314
|
-
return moment(event.startDate)
|
|
315
|
-
.isSameOrBefore(moment(params.returningDate)
|
|
316
|
-
.add(gracePeriodMaxValue, 'seconds'));
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
if (typeof gracePeriodMinValue === 'number') {
|
|
320
|
-
satisfyGracePeriodMinValue = params.events.every((event) => {
|
|
321
|
-
return moment(event.startDate)
|
|
322
|
-
.isAfter(moment(params.returningDate)
|
|
323
|
-
.add(gracePeriodMinValue, 'seconds'));
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
let satisfyGracePeriodInDaysMax = true;
|
|
327
|
-
let satisfyGracePeriodInDaysMin = true;
|
|
328
|
-
const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
|
|
329
|
-
if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
|
|
330
|
-
&& typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
|
|
331
|
-
satisfyGracePeriodInDaysMax = params.events.every((event) => {
|
|
332
|
-
const maxDate = moment(event.startDate)
|
|
333
|
-
.tz(gracePeriodBeforeStartInDaysMax.timezone)
|
|
334
|
-
.startOf('days')
|
|
335
|
-
.subtract(gracePeriodBeforeStartInDaysMax.period.value, 'days')
|
|
336
|
-
.format('YYYY-MM-DD');
|
|
337
|
-
const returnMinDate = moment.tz(`${maxDate}T${gracePeriodBeforeStartInDaysMax.time}`, gracePeriodBeforeStartInDaysMax.timezone);
|
|
338
|
-
debug('returnMinDate:', returnMinDate, 'returningDate:', returningDate);
|
|
339
|
-
return returnMinDate.isSameOrBefore(moment(returningDate));
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
debug('gracePeriodBeforeStartInDaysMax:', gracePeriodBeforeStartInDaysMax);
|
|
343
|
-
const gracePeriodBeforeStartInDaysMin = (_j = (_h = offerItemCondition.itemOffered.serviceOutput) === null || _h === void 0 ? void 0 : _h.reservationFor.gracePeriodBeforeStartInDays) === null || _j === void 0 ? void 0 : _j.min;
|
|
344
|
-
if (typeof (gracePeriodBeforeStartInDaysMin === null || gracePeriodBeforeStartInDaysMin === void 0 ? void 0 : gracePeriodBeforeStartInDaysMin.period.value) === 'number'
|
|
345
|
-
&& typeof gracePeriodBeforeStartInDaysMin.time === 'string') {
|
|
346
|
-
satisfyGracePeriodInDaysMin = params.events.every((event) => {
|
|
347
|
-
const minDate = moment(event.startDate)
|
|
348
|
-
.tz(gracePeriodBeforeStartInDaysMin.timezone)
|
|
349
|
-
.startOf('days')
|
|
350
|
-
.subtract(gracePeriodBeforeStartInDaysMin.period.value, 'days')
|
|
351
|
-
.format('YYYY-MM-DD');
|
|
352
|
-
const returnMaxDate = moment.tz(`${minDate}T${gracePeriodBeforeStartInDaysMin.time}`, gracePeriodBeforeStartInDaysMin.timezone);
|
|
353
|
-
debug('returnMaxDate:', returnMaxDate, 'returningDate:', returningDate);
|
|
354
|
-
return returnMaxDate.isAfter(moment(returningDate));
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
|
|
358
|
-
let satisfyOnlyUnused = true;
|
|
359
|
-
if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
|
|
360
|
-
if (params.usedReservationExists) {
|
|
361
|
-
satisfyOnlyUnused = false;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
|
|
365
|
-
satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
|
|
366
|
-
&& satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
|
|
367
|
-
}
|
|
368
|
-
return satisfyMerchantReturnDays && satisfyItemCondition;
|
|
277
|
+
return isSellerReturnPolicyApplicable({
|
|
278
|
+
returnPolicy,
|
|
279
|
+
events: params.events,
|
|
280
|
+
offerItemConditions: params.offerItemConditions,
|
|
281
|
+
orders: params.orders,
|
|
282
|
+
returningDate: params.returningDate,
|
|
283
|
+
usedReservationExists: params.usedReservationExists
|
|
284
|
+
});
|
|
369
285
|
});
|
|
370
286
|
}
|
|
371
287
|
// 販売者にポリシーが存在しなければ返品不可
|
|
@@ -403,6 +319,119 @@ function findApplicableReturnPolicy(params) {
|
|
|
403
319
|
return Object.assign({ merchantReturnDays: appliedReturnPolicy.merchantReturnDays, restockingFee: appliedReturnPolicy.restockingFee, returnFees,
|
|
404
320
|
returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
|
|
405
321
|
}
|
|
322
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
323
|
+
function isSellerReturnPolicyApplicable(params) {
|
|
324
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
325
|
+
const returnPolicy = params.returnPolicy;
|
|
326
|
+
const returningDate = moment(params.returningDate);
|
|
327
|
+
let satisfyMerchantReturnDays = false;
|
|
328
|
+
let satisfyApplicablePaymentMethod = false;
|
|
329
|
+
let offerItemCondition;
|
|
330
|
+
const itemConditionId = (_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
|
|
331
|
+
if (typeof itemConditionId === 'string') {
|
|
332
|
+
offerItemCondition = params.offerItemConditions.find((o) => o.id === itemConditionId);
|
|
333
|
+
if (offerItemCondition === undefined) {
|
|
334
|
+
throw new factory.errors.NotFound('OfferItemCondition');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const merchantReturnDays = returnPolicy.merchantReturnDays;
|
|
338
|
+
if (typeof merchantReturnDays === 'number') {
|
|
339
|
+
// 返品適用日数を確認する
|
|
340
|
+
const everyOrderApplicable = params.orders.every((order) => {
|
|
341
|
+
const mustBeReturnedUntil = moment(order.orderDate)
|
|
342
|
+
.add(merchantReturnDays, 'days');
|
|
343
|
+
return mustBeReturnedUntil.isSameOrAfter(returningDate);
|
|
344
|
+
});
|
|
345
|
+
// 全注文について日数の確認ができれば適用
|
|
346
|
+
if (everyOrderApplicable) {
|
|
347
|
+
satisfyMerchantReturnDays = true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
// 日数制限なし
|
|
352
|
+
satisfyMerchantReturnDays = true;
|
|
353
|
+
}
|
|
354
|
+
// 適用決済方法検証(2023-08-08~)
|
|
355
|
+
const applicablePaymentMethod = returnPolicy.applicablePaymentMethod;
|
|
356
|
+
if (Array.isArray(applicablePaymentMethod)) {
|
|
357
|
+
const everyOrderApplicable = params.orders.every((order) => {
|
|
358
|
+
// 全決済方法区分がapplicablePaymentMethodに含まれれば適用
|
|
359
|
+
return order.paymentMethods.every((paymentMethod) => applicablePaymentMethod.includes(paymentMethod.typeOf));
|
|
360
|
+
});
|
|
361
|
+
// 全注文について確認ができれば適用
|
|
362
|
+
if (everyOrderApplicable) {
|
|
363
|
+
satisfyApplicablePaymentMethod = true;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
satisfyApplicablePaymentMethod = true;
|
|
368
|
+
}
|
|
369
|
+
// イベント開始猶予を検証する(2023-05-22~)
|
|
370
|
+
let satisfyItemCondition = true;
|
|
371
|
+
if (offerItemCondition !== undefined) {
|
|
372
|
+
let satisfyGracePeriodMaxValue = true;
|
|
373
|
+
let satisfyGracePeriodMinValue = true;
|
|
374
|
+
// 全イベントについて猶予の確認ができれば適用
|
|
375
|
+
const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
|
|
376
|
+
const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
|
|
377
|
+
if (typeof gracePeriodMaxValue === 'number') {
|
|
378
|
+
satisfyGracePeriodMaxValue = params.events.every((event) => {
|
|
379
|
+
return moment(event.startDate)
|
|
380
|
+
.isSameOrBefore(moment(params.returningDate)
|
|
381
|
+
.add(gracePeriodMaxValue, 'seconds'));
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
if (typeof gracePeriodMinValue === 'number') {
|
|
385
|
+
satisfyGracePeriodMinValue = params.events.every((event) => {
|
|
386
|
+
return moment(event.startDate)
|
|
387
|
+
.isAfter(moment(params.returningDate)
|
|
388
|
+
.add(gracePeriodMinValue, 'seconds'));
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
let satisfyGracePeriodInDaysMax = true;
|
|
392
|
+
let satisfyGracePeriodInDaysMin = true;
|
|
393
|
+
const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
|
|
394
|
+
if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
|
|
395
|
+
&& typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
|
|
396
|
+
satisfyGracePeriodInDaysMax = params.events.every((event) => {
|
|
397
|
+
const maxDate = moment(event.startDate)
|
|
398
|
+
.tz(gracePeriodBeforeStartInDaysMax.timezone)
|
|
399
|
+
.startOf('days')
|
|
400
|
+
.subtract(gracePeriodBeforeStartInDaysMax.period.value, 'days')
|
|
401
|
+
.format('YYYY-MM-DD');
|
|
402
|
+
const returnMinDate = moment.tz(`${maxDate}T${gracePeriodBeforeStartInDaysMax.time}`, gracePeriodBeforeStartInDaysMax.timezone);
|
|
403
|
+
debug('returnMinDate:', returnMinDate, 'returningDate:', returningDate);
|
|
404
|
+
return returnMinDate.isSameOrBefore(moment(returningDate));
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
debug('gracePeriodBeforeStartInDaysMax:', gracePeriodBeforeStartInDaysMax);
|
|
408
|
+
const gracePeriodBeforeStartInDaysMin = (_j = (_h = offerItemCondition.itemOffered.serviceOutput) === null || _h === void 0 ? void 0 : _h.reservationFor.gracePeriodBeforeStartInDays) === null || _j === void 0 ? void 0 : _j.min;
|
|
409
|
+
if (typeof (gracePeriodBeforeStartInDaysMin === null || gracePeriodBeforeStartInDaysMin === void 0 ? void 0 : gracePeriodBeforeStartInDaysMin.period.value) === 'number'
|
|
410
|
+
&& typeof gracePeriodBeforeStartInDaysMin.time === 'string') {
|
|
411
|
+
satisfyGracePeriodInDaysMin = params.events.every((event) => {
|
|
412
|
+
const minDate = moment(event.startDate)
|
|
413
|
+
.tz(gracePeriodBeforeStartInDaysMin.timezone)
|
|
414
|
+
.startOf('days')
|
|
415
|
+
.subtract(gracePeriodBeforeStartInDaysMin.period.value, 'days')
|
|
416
|
+
.format('YYYY-MM-DD');
|
|
417
|
+
const returnMaxDate = moment.tz(`${minDate}T${gracePeriodBeforeStartInDaysMin.time}`, gracePeriodBeforeStartInDaysMin.timezone);
|
|
418
|
+
debug('returnMaxDate:', returnMaxDate, 'returningDate:', returningDate);
|
|
419
|
+
return returnMaxDate.isAfter(moment(returningDate));
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
|
|
423
|
+
let satisfyOnlyUnused = true;
|
|
424
|
+
if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
|
|
425
|
+
if (params.usedReservationExists) {
|
|
426
|
+
satisfyOnlyUnused = false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
|
|
430
|
+
satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
|
|
431
|
+
&& satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
|
|
432
|
+
}
|
|
433
|
+
return satisfyMerchantReturnDays && satisfyApplicablePaymentMethod && satisfyItemCondition;
|
|
434
|
+
}
|
|
406
435
|
/**
|
|
407
436
|
* 注文中のオファーの返品ポリシーを検証
|
|
408
437
|
*/
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.324.0
|
|
13
|
-
"@cinerino/sdk": "3.
|
|
12
|
+
"@chevre/factory": "4.324.0",
|
|
13
|
+
"@cinerino/sdk": "3.163.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.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.6.0
|
|
120
|
+
"version": "21.6.0"
|
|
121
121
|
}
|