@chevre/domain 21.2.0-alpha.67 → 21.2.0-alpha.69
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.
|
@@ -23,7 +23,9 @@ export declare class MongoRepository {
|
|
|
23
23
|
/**
|
|
24
24
|
* 予約検索
|
|
25
25
|
*/
|
|
26
|
-
search<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>, projection?:
|
|
26
|
+
search<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>, projection?: {
|
|
27
|
+
[key: string]: 0 | 1;
|
|
28
|
+
}): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]>;
|
|
27
29
|
findById<T extends factory.reservationType>(params: {
|
|
28
30
|
id: string;
|
|
29
31
|
inclusion?: string[];
|
|
@@ -64,6 +64,7 @@ function start(params) {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
const policiesByOffer = yield searchPoliciesByOffer({ offers })(repos);
|
|
67
|
+
const { usedReservationExists } = yield checkUsedReservationExists({ orders })(repos);
|
|
67
68
|
const appliedReturnPolicy = findApplicableReturnPolicy({
|
|
68
69
|
acceptedOffers,
|
|
69
70
|
events,
|
|
@@ -73,7 +74,8 @@ function start(params) {
|
|
|
73
74
|
reason: params.object.reason,
|
|
74
75
|
returnPolicies,
|
|
75
76
|
offers,
|
|
76
|
-
policiesByOffer
|
|
77
|
+
policiesByOffer,
|
|
78
|
+
usedReservationExists
|
|
77
79
|
});
|
|
78
80
|
validateAppliedReturnPolicy({ merchantReturnPolicy: appliedReturnPolicy });
|
|
79
81
|
// アイテム検証
|
|
@@ -174,12 +176,9 @@ function validateOrder(params) {
|
|
|
174
176
|
}
|
|
175
177
|
});
|
|
176
178
|
}
|
|
177
|
-
function
|
|
179
|
+
function checkUsedReservationExists(params) {
|
|
178
180
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
|
|
180
|
-
// 販売者都合の場合、特に検証しない
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
181
|
+
let usedReservationExists = false;
|
|
183
182
|
// 注文に含まれる予約の状態検証
|
|
184
183
|
const reservationNumbers = yield repos.order.searchReservationNumbersByOrderNumbers({
|
|
185
184
|
orderNumber: { $in: params.orders.map((order) => order.orderNumber) }
|
|
@@ -192,11 +191,38 @@ function validateItems(params) {
|
|
|
192
191
|
typeOf: factory.reservationType.EventReservation,
|
|
193
192
|
reservationNumber: { $in: reservationNumbers },
|
|
194
193
|
attended: true
|
|
195
|
-
});
|
|
194
|
+
}, { _id: 1 });
|
|
196
195
|
if (existingUsedReservations.length > 0) {
|
|
197
|
-
|
|
196
|
+
usedReservationExists = true;
|
|
198
197
|
}
|
|
199
198
|
}
|
|
199
|
+
return { usedReservationExists };
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function validateItems(params) {
|
|
203
|
+
return (__) => __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
|
|
205
|
+
// 販売者都合の場合、特に検証しない
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// アイテムコンディション検証へ移行
|
|
209
|
+
// 注文に含まれる予約の状態検証
|
|
210
|
+
// const reservationNumbers = await repos.order.searchReservationNumbersByOrderNumbers({
|
|
211
|
+
// orderNumber: { $in: params.orders.map((order) => order.orderNumber) }
|
|
212
|
+
// });
|
|
213
|
+
// if (reservationNumbers.length > 0) {
|
|
214
|
+
// // 使用済の予約がひとつでもあれば不可
|
|
215
|
+
// const existingUsedReservations = await repos.reservation.search({
|
|
216
|
+
// limit: 1,
|
|
217
|
+
// page: 1,
|
|
218
|
+
// typeOf: factory.reservationType.EventReservation,
|
|
219
|
+
// reservationNumber: { $in: reservationNumbers },
|
|
220
|
+
// attended: true
|
|
221
|
+
// });
|
|
222
|
+
// if (existingUsedReservations.length > 0) {
|
|
223
|
+
// throw new factory.errors.Argument('orderNumber', 'some reservations already used');
|
|
224
|
+
// }
|
|
225
|
+
// }
|
|
200
226
|
});
|
|
201
227
|
}
|
|
202
228
|
function searchPoliciesByOffer(params) {
|
|
@@ -225,6 +251,7 @@ function searchPoliciesByOffer(params) {
|
|
|
225
251
|
*/
|
|
226
252
|
// tslint:disable-next-line:max-func-body-length
|
|
227
253
|
function findApplicableReturnPolicy(params) {
|
|
254
|
+
var _a;
|
|
228
255
|
if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
|
|
229
256
|
// 販売者都合の場合、手数料なしの返金返品ポリシーを適用
|
|
230
257
|
return {
|
|
@@ -237,8 +264,9 @@ function findApplicableReturnPolicy(params) {
|
|
|
237
264
|
let applicalbleReturnPolicies = [];
|
|
238
265
|
if (params.reason === factory.transaction.returnOrder.Reason.Customer) {
|
|
239
266
|
// 適用可能なポリシーにフィルター
|
|
267
|
+
// tslint:disable-next-line:max-func-body-length
|
|
240
268
|
applicalbleReturnPolicies = returnPolicies.filter((returnPolicy) => {
|
|
241
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
269
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
242
270
|
let satisfyMerchantReturnDays = false;
|
|
243
271
|
let offerItemCondition;
|
|
244
272
|
const itemConditionId = (_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
|
|
@@ -270,8 +298,6 @@ function findApplicableReturnPolicy(params) {
|
|
|
270
298
|
if (offerItemCondition !== undefined) {
|
|
271
299
|
let satisfyGracePeriodMaxValue = true;
|
|
272
300
|
let satisfyGracePeriodMinValue = true;
|
|
273
|
-
let satisfyGracePeriodInDaysMax = true;
|
|
274
|
-
let satisfyGracePeriodInDaysMin = true;
|
|
275
301
|
// 全イベントについて猶予の確認ができれば適用
|
|
276
302
|
const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
|
|
277
303
|
const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
|
|
@@ -285,24 +311,27 @@ function findApplicableReturnPolicy(params) {
|
|
|
285
311
|
if (typeof gracePeriodMinValue === 'number') {
|
|
286
312
|
satisfyGracePeriodMinValue = params.events.every((event) => {
|
|
287
313
|
return moment(event.startDate)
|
|
288
|
-
.
|
|
314
|
+
.isAfter(moment(params.returningDate)
|
|
289
315
|
.add(gracePeriodMinValue, 'seconds'));
|
|
290
316
|
});
|
|
291
317
|
}
|
|
318
|
+
let satisfyGracePeriodInDaysMax = true;
|
|
319
|
+
let satisfyGracePeriodInDaysMin = true;
|
|
292
320
|
const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
|
|
293
321
|
if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
|
|
294
322
|
&& typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
|
|
295
323
|
satisfyGracePeriodInDaysMax = params.events.every((event) => {
|
|
296
|
-
const
|
|
324
|
+
const maxDate = moment(event.startDate)
|
|
297
325
|
.tz(gracePeriodBeforeStartInDaysMax.timezone)
|
|
298
326
|
.startOf('days')
|
|
299
327
|
.subtract(gracePeriodBeforeStartInDaysMax.period.value, 'days')
|
|
300
328
|
.format('YYYY-MM-DD');
|
|
301
|
-
const returnMinDate = moment(`${
|
|
302
|
-
|
|
329
|
+
const returnMinDate = moment.tz(`${maxDate}T${gracePeriodBeforeStartInDaysMax.time}`, gracePeriodBeforeStartInDaysMax.timezone);
|
|
330
|
+
debug('returnMinDate:', returnMinDate, 'returningDate:', returningDate);
|
|
303
331
|
return returnMinDate.isSameOrBefore(moment(returningDate));
|
|
304
332
|
});
|
|
305
333
|
}
|
|
334
|
+
debug('gracePeriodBeforeStartInDaysMax:', gracePeriodBeforeStartInDaysMax);
|
|
306
335
|
const gracePeriodBeforeStartInDaysMin = (_j = (_h = offerItemCondition.itemOffered.serviceOutput) === null || _h === void 0 ? void 0 : _h.reservationFor.gracePeriodBeforeStartInDays) === null || _j === void 0 ? void 0 : _j.min;
|
|
307
336
|
if (typeof (gracePeriodBeforeStartInDaysMin === null || gracePeriodBeforeStartInDaysMin === void 0 ? void 0 : gracePeriodBeforeStartInDaysMin.period.value) === 'number'
|
|
308
337
|
&& typeof gracePeriodBeforeStartInDaysMin.time === 'string') {
|
|
@@ -314,33 +343,22 @@ function findApplicableReturnPolicy(params) {
|
|
|
314
343
|
.format('YYYY-MM-DD');
|
|
315
344
|
const returnMaxDate = moment.tz(`${minDate}T${gracePeriodBeforeStartInDaysMin.time}`, gracePeriodBeforeStartInDaysMin.timezone);
|
|
316
345
|
debug('returnMaxDate:', returnMaxDate, 'returningDate:', returningDate);
|
|
317
|
-
return returnMaxDate.
|
|
346
|
+
return returnMaxDate.isAfter(moment(returningDate));
|
|
318
347
|
});
|
|
319
348
|
}
|
|
320
349
|
debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
|
|
350
|
+
let satisfyOnlyUnused = true;
|
|
351
|
+
if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
|
|
352
|
+
if (params.usedReservationExists) {
|
|
353
|
+
satisfyOnlyUnused = false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
|
|
321
357
|
satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
|
|
322
|
-
&& satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin;
|
|
358
|
+
&& satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
|
|
323
359
|
}
|
|
324
360
|
return satisfyMerchantReturnDays && satisfyItemCondition;
|
|
325
361
|
});
|
|
326
|
-
// returnPolicies.forEach((returnPolicy) => {
|
|
327
|
-
// const merchantReturnDays = returnPolicy.merchantReturnDays;
|
|
328
|
-
// if (typeof merchantReturnDays === 'number') {
|
|
329
|
-
// // 返品適用日数を確認する
|
|
330
|
-
// const everyOrderApplicable = params.orders.every((order) => {
|
|
331
|
-
// const mustBeReturnedUntil = moment(order.orderDate)
|
|
332
|
-
// .add(merchantReturnDays, 'days');
|
|
333
|
-
// return mustBeReturnedUntil.isSameOrAfter(returningDate);
|
|
334
|
-
// });
|
|
335
|
-
// // 全注文について日数の確認ができれば適用
|
|
336
|
-
// if (everyOrderApplicable) {
|
|
337
|
-
// applicalbleReturnPolicies.push(returnPolicy);
|
|
338
|
-
// }
|
|
339
|
-
// } else {
|
|
340
|
-
// // 日数制限なし
|
|
341
|
-
// applicalbleReturnPolicies.push(returnPolicy);
|
|
342
|
-
// }
|
|
343
|
-
// });
|
|
344
362
|
}
|
|
345
363
|
// 販売者にポリシーが存在しなければ返品不可
|
|
346
364
|
if (applicalbleReturnPolicies.length === 0) {
|
|
@@ -366,13 +384,16 @@ function findApplicableReturnPolicy(params) {
|
|
|
366
384
|
appliedReturnPolicy = returnPolicy;
|
|
367
385
|
}
|
|
368
386
|
});
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
387
|
+
let appliedItemCondition;
|
|
388
|
+
const appliedItemConditionId = (_a = appliedReturnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
|
|
389
|
+
if (typeof appliedItemConditionId === 'string') {
|
|
390
|
+
appliedItemCondition = params.offerItemConditions.find((o) => o.id === appliedItemConditionId);
|
|
391
|
+
if (appliedItemCondition === undefined) {
|
|
392
|
+
throw new factory.errors.NotFound('OfferItemCondition');
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return Object.assign({ merchantReturnDays: appliedReturnPolicy.merchantReturnDays, restockingFee: appliedReturnPolicy.restockingFee, returnFees,
|
|
396
|
+
returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
|
|
376
397
|
}
|
|
377
398
|
/**
|
|
378
399
|
* 注文中のオファーの返品ポリシーを検証
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.313.0-alpha.
|
|
13
|
-
"@cinerino/sdk": "3.157.0-alpha.
|
|
12
|
+
"@chevre/factory": "4.313.0-alpha.11",
|
|
13
|
+
"@cinerino/sdk": "3.157.0-alpha.1",
|
|
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.2.0-alpha.
|
|
120
|
+
"version": "21.2.0-alpha.69"
|
|
121
121
|
}
|