@chevre/domain 21.15.0-alpha.13 → 21.15.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.
|
@@ -28,6 +28,7 @@ async function main() {
|
|
|
28
28
|
offer: await chevre.repository.Offer.createInstance(mongoose.connection),
|
|
29
29
|
offerItemCondition: await chevre.repository.OfferItemCondition.createInstance(mongoose.connection),
|
|
30
30
|
order: await chevre.repository.Order.createInstance(mongoose.connection),
|
|
31
|
+
project: await chevre.repository.Project.createInstance(mongoose.connection),
|
|
31
32
|
reservation: await chevre.repository.Reservation.createInstance(mongoose.connection),
|
|
32
33
|
seller: await chevre.repository.Seller.createInstance(mongoose.connection),
|
|
33
34
|
transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
|
|
@@ -5,6 +5,7 @@ import type { MongoRepository as MerchantReturnPolicyRepo } from '../../repo/mer
|
|
|
5
5
|
import type { MongoRepository as OfferRepo } from '../../repo/offer';
|
|
6
6
|
import type { MongoRepository as OfferItemConditionRepo } from '../../repo/offerItemCondition';
|
|
7
7
|
import type { MongoRepository as OrderRepo } from '../../repo/order';
|
|
8
|
+
import type { MongoRepository as ProjectRepo } from '../../repo/project';
|
|
8
9
|
import type { MongoRepository as ReservationRepo } from '../../repo/reservation';
|
|
9
10
|
import type { MongoRepository as SellerRepo } from '../../repo/seller';
|
|
10
11
|
import type { MongoRepository as TaskRepo } from '../../repo/task';
|
|
@@ -15,6 +16,7 @@ export interface IStartOperationRepos {
|
|
|
15
16
|
offer: OfferRepo;
|
|
16
17
|
offerItemCondition: OfferItemConditionRepo;
|
|
17
18
|
order: OrderRepo;
|
|
19
|
+
project: ProjectRepo;
|
|
18
20
|
reservation: ReservationRepo;
|
|
19
21
|
seller: SellerRepo;
|
|
20
22
|
transaction: TransactionRepo;
|
|
@@ -8,14 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
23
|
exports.exportTasksById = exports.confirm = exports.start = void 0;
|
|
13
24
|
/**
|
|
14
25
|
* 返品取引サービス
|
|
15
26
|
*/
|
|
16
27
|
const createDebug = require("debug");
|
|
28
|
+
const http_status_1 = require("http-status");
|
|
17
29
|
const moment = require("moment-timezone");
|
|
30
|
+
const request = require("request");
|
|
18
31
|
const factory = require("../../factory");
|
|
32
|
+
const settings_1 = require("../../settings");
|
|
19
33
|
const factory_1 = require("./returnOrder/exportTasks/factory");
|
|
20
34
|
const potentialActions_1 = require("./returnOrder/potentialActions");
|
|
21
35
|
const errorHandler_1 = require("../../errorHandler");
|
|
@@ -75,7 +89,12 @@ function start(params) {
|
|
|
75
89
|
}
|
|
76
90
|
const policiesByOffer = yield searchPoliciesByOffer({ offers })(repos);
|
|
77
91
|
const { usedReservationExists } = yield checkUsedReservationExists({ orders })(repos);
|
|
78
|
-
const
|
|
92
|
+
const { hasMerchantReturnPolicy } = yield repos.project.findById({
|
|
93
|
+
id: seller.project.id,
|
|
94
|
+
inclusion: ['hasMerchantReturnPolicy'],
|
|
95
|
+
exclusion: []
|
|
96
|
+
});
|
|
97
|
+
const appliedReturnPolicy = yield findApplicableReturnPolicy({
|
|
79
98
|
acceptedOffers,
|
|
80
99
|
events,
|
|
81
100
|
offerItemConditions,
|
|
@@ -83,6 +102,7 @@ function start(params) {
|
|
|
83
102
|
returningDate: now,
|
|
84
103
|
reason: params.object.reason,
|
|
85
104
|
returnPolicies,
|
|
105
|
+
returnPolicySettingsByProject: hasMerchantReturnPolicy,
|
|
86
106
|
offers,
|
|
87
107
|
policiesByOffer,
|
|
88
108
|
usedReservationExists
|
|
@@ -154,8 +174,7 @@ function fixOrders(params) {
|
|
|
154
174
|
confirmationNumbers: [params.object.order[0].confirmationNumber],
|
|
155
175
|
orderNumbers: [params.object.order[0].orderNumber]
|
|
156
176
|
}, {
|
|
157
|
-
//
|
|
158
|
-
acceptedOffers: 0,
|
|
177
|
+
// acceptedOffers: 0, // カスタム返品ポリシーに必要
|
|
159
178
|
customer: 0,
|
|
160
179
|
orderedItem: 0
|
|
161
180
|
// paymentMethods: 0 // 適用決済方法検証に必要
|
|
@@ -256,70 +275,171 @@ function searchPoliciesByOffer(params) {
|
|
|
256
275
|
return policiesByOffer;
|
|
257
276
|
});
|
|
258
277
|
}
|
|
278
|
+
function getReturnPolicyByProject(params) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
return new Promise((resolve, reject) => {
|
|
281
|
+
var _a;
|
|
282
|
+
request.post({
|
|
283
|
+
url: params.sameAs,
|
|
284
|
+
body: {
|
|
285
|
+
order: {
|
|
286
|
+
orderDate: params.order.orderDate,
|
|
287
|
+
price: params.order.price,
|
|
288
|
+
acceptedOffers: (Array.isArray(params.order.acceptedOffers))
|
|
289
|
+
? params.order.acceptedOffers.map((o) => {
|
|
290
|
+
var _a;
|
|
291
|
+
if (o.itemOffered.typeOf === factory.reservationType.EventReservation) {
|
|
292
|
+
const reservation = o.itemOffered;
|
|
293
|
+
const priceComponent = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.priceComponent;
|
|
294
|
+
return {
|
|
295
|
+
itemOffered: {
|
|
296
|
+
additionalProperty: reservation.additionalProperty,
|
|
297
|
+
reservationFor: {
|
|
298
|
+
doorTime: reservation.reservationFor.doorTime,
|
|
299
|
+
endDate: reservation.reservationFor.endDate,
|
|
300
|
+
startDate: reservation.reservationFor.startDate
|
|
301
|
+
// superEvent: reservation.reservationFor.superEvent
|
|
302
|
+
},
|
|
303
|
+
reservedTicket: {
|
|
304
|
+
ticketedSeat: reservation.reservedTicket.ticketedSeat
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
priceSpecification: {
|
|
308
|
+
priceComponent: (Array.isArray(priceComponent))
|
|
309
|
+
? priceComponent.map((component) => {
|
|
310
|
+
const { accounting, name, priceCurrency, valueAddedTaxIncluded } = component, postingComponent = __rest(component, ["accounting", "name", "priceCurrency", "valueAddedTaxIncluded"]);
|
|
311
|
+
return postingComponent;
|
|
312
|
+
})
|
|
313
|
+
: []
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
return {
|
|
319
|
+
priceSpecification: o.priceSpecification
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
: []
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
json: true,
|
|
327
|
+
timeout: (_a = settings_1.settings.webhook) === null || _a === void 0 ? void 0 : _a.timeout
|
|
328
|
+
}, (error, response, body) => {
|
|
329
|
+
var _a;
|
|
330
|
+
if (error instanceof Error) {
|
|
331
|
+
reject(error);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
switch (response.statusCode) {
|
|
335
|
+
case http_status_1.OK:
|
|
336
|
+
case http_status_1.CREATED:
|
|
337
|
+
case http_status_1.ACCEPTED:
|
|
338
|
+
case http_status_1.NO_CONTENT:
|
|
339
|
+
if (typeof ((_a = body.restockingFee) === null || _a === void 0 ? void 0 : _a.value) !== 'number') {
|
|
340
|
+
reject(new Error('invalid return policy'));
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
resolve({
|
|
344
|
+
typeOf: 'MerchantReturnPolicy',
|
|
345
|
+
restockingFee: {
|
|
346
|
+
currency: factory.priceCurrency.JPY,
|
|
347
|
+
typeOf: 'MonetaryAmount',
|
|
348
|
+
value: body.restockingFee.value
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
case http_status_1.NOT_FOUND:
|
|
354
|
+
reject(new factory.errors.Argument('Seller', 'has no applicable return policies'));
|
|
355
|
+
break;
|
|
356
|
+
default:
|
|
357
|
+
reject({
|
|
358
|
+
statusCode: response.statusCode,
|
|
359
|
+
body: body
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
}
|
|
259
367
|
/**
|
|
260
368
|
* 販売者の返品ポリシーを確認する
|
|
261
369
|
*/
|
|
262
370
|
// tslint:disable-next-line:max-func-body-length
|
|
263
371
|
function findApplicableReturnPolicy(params) {
|
|
264
|
-
var _a;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
372
|
+
var _a, _b;
|
|
373
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
374
|
+
if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
|
|
375
|
+
// 販売者都合の場合、手数料なしの返金返品ポリシーを適用
|
|
376
|
+
return {
|
|
377
|
+
typeOf: 'MerchantReturnPolicy',
|
|
378
|
+
returnFees: factory.merchantReturnPolicy.ReturnFeesEnumeration.FreeReturn
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const returnPolicies = params.returnPolicies;
|
|
382
|
+
let applicalbleReturnPolicies = [];
|
|
383
|
+
if (params.reason === factory.transaction.returnOrder.Reason.Customer) {
|
|
384
|
+
// プロジェクトの返品ポリシー設定を考慮(2023-11-14~)
|
|
385
|
+
const returnPolicySameAsByPoject = (_a = params.returnPolicySettingsByProject) === null || _a === void 0 ? void 0 : _a.sameAs;
|
|
386
|
+
if (typeof returnPolicySameAsByPoject === 'string' && returnPolicySameAsByPoject.length > 0) {
|
|
387
|
+
const returnPolicyByProject = yield getReturnPolicyByProject({
|
|
388
|
+
sameAs: returnPolicySameAsByPoject,
|
|
389
|
+
order: params.orders[0] // 同時返品可能な注文数をは1
|
|
390
|
+
});
|
|
391
|
+
applicalbleReturnPolicies.push(returnPolicyByProject);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
// 適用可能なポリシーにフィルター
|
|
395
|
+
// tslint:disable-next-line:max-func-body-length
|
|
396
|
+
applicalbleReturnPolicies = returnPolicies.filter((returnPolicy) => {
|
|
397
|
+
return isSellerReturnPolicyApplicable({
|
|
398
|
+
returnPolicy,
|
|
399
|
+
events: params.events,
|
|
400
|
+
offerItemConditions: params.offerItemConditions,
|
|
401
|
+
orders: params.orders,
|
|
402
|
+
returningDate: params.returningDate,
|
|
403
|
+
usedReservationExists: params.usedReservationExists
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
// 販売者にポリシーが存在しなければ返品不可
|
|
409
|
+
if (applicalbleReturnPolicies.length === 0) {
|
|
410
|
+
throw new factory.errors.Argument('Seller', 'has no applicable return policies');
|
|
411
|
+
}
|
|
412
|
+
// オファーの返品ポリシーから返品手数料タイプを決定する
|
|
413
|
+
const { returnFees, returnFeesMovieTicket } = validateOffersReturnPolicy({
|
|
414
|
+
acceptedOffers: params.acceptedOffers,
|
|
415
|
+
offers: params.offers,
|
|
416
|
+
policiesByOffer: params.policiesByOffer
|
|
287
417
|
});
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (restockingFee < appliedReturnPolicyRestockingFee) {
|
|
310
|
-
appliedReturnPolicy = returnPolicy;
|
|
418
|
+
// restockingFeeが最低のポリシーを自動選択
|
|
419
|
+
let appliedReturnPolicy = applicalbleReturnPolicies[0];
|
|
420
|
+
applicalbleReturnPolicies.forEach((returnPolicy) => {
|
|
421
|
+
var _a, _b;
|
|
422
|
+
const appliedReturnPolicyRestockingFeeValue = (_a = appliedReturnPolicy.restockingFee) === null || _a === void 0 ? void 0 : _a.value;
|
|
423
|
+
const restockingFeeValue = (_b = returnPolicy.restockingFee) === null || _b === void 0 ? void 0 : _b.value;
|
|
424
|
+
const appliedReturnPolicyRestockingFee = (typeof appliedReturnPolicyRestockingFeeValue === 'number')
|
|
425
|
+
? appliedReturnPolicyRestockingFeeValue
|
|
426
|
+
: 0;
|
|
427
|
+
const restockingFee = (typeof restockingFeeValue === 'number') ? restockingFeeValue : 0;
|
|
428
|
+
if (restockingFee < appliedReturnPolicyRestockingFee) {
|
|
429
|
+
appliedReturnPolicy = returnPolicy;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
let appliedItemCondition;
|
|
433
|
+
const appliedItemConditionId = (_b = appliedReturnPolicy.itemCondition) === null || _b === void 0 ? void 0 : _b.id;
|
|
434
|
+
if (typeof appliedItemConditionId === 'string') {
|
|
435
|
+
appliedItemCondition = params.offerItemConditions.find((o) => o.id === appliedItemConditionId);
|
|
436
|
+
if (appliedItemCondition === undefined) {
|
|
437
|
+
throw new factory.errors.NotFound('OfferItemCondition');
|
|
438
|
+
}
|
|
311
439
|
}
|
|
440
|
+
return Object.assign({ merchantReturnDays: appliedReturnPolicy.merchantReturnDays, restockingFee: appliedReturnPolicy.restockingFee, returnFees,
|
|
441
|
+
returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
|
|
312
442
|
});
|
|
313
|
-
let appliedItemCondition;
|
|
314
|
-
const appliedItemConditionId = (_a = appliedReturnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
|
|
315
|
-
if (typeof appliedItemConditionId === 'string') {
|
|
316
|
-
appliedItemCondition = params.offerItemConditions.find((o) => o.id === appliedItemConditionId);
|
|
317
|
-
if (appliedItemCondition === undefined) {
|
|
318
|
-
throw new factory.errors.NotFound('OfferItemCondition');
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
return Object.assign({ merchantReturnDays: appliedReturnPolicy.merchantReturnDays, restockingFee: appliedReturnPolicy.restockingFee, returnFees,
|
|
322
|
-
returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
|
|
323
443
|
}
|
|
324
444
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
325
445
|
function isSellerReturnPolicyApplicable(params) {
|
package/package.json
CHANGED