@chevre/domain 21.8.0 → 21.9.0-alpha.1
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/searchAvaialbleAppliesToMovieTicketByOfferCatalogId.ts +44 -0
- package/lib/chevre/repo/offer.d.ts +20 -1
- package/lib/chevre/repo/offer.js +42 -0
- package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +29 -1
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +57 -1
- package/lib/chevre/service/offer/event.d.ts +2 -2
- package/lib/chevre/service/offer/event.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
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, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
10
|
+
const offerRepo = new chevre.repository.Offer(mongoose.connection);
|
|
11
|
+
const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
|
|
12
|
+
const productRepo = new chevre.repository.Product(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
let result = await offerRepo.searchAvaialbleAppliesToMovieTicketByOfferCatalogId({
|
|
15
|
+
limit: 10,
|
|
16
|
+
page: 1,
|
|
17
|
+
subOfferCatalog: {
|
|
18
|
+
id: '0001'
|
|
19
|
+
},
|
|
20
|
+
excludeAppliesToMovieTicket: false,
|
|
21
|
+
unacceptedPaymentMethod: []
|
|
22
|
+
});
|
|
23
|
+
console.log(result);
|
|
24
|
+
console.log(result.length);
|
|
25
|
+
|
|
26
|
+
result = await chevre.service.offer.event.searchOfferAppliesToMovieTicket({
|
|
27
|
+
event: { id: 'cllkq475p' },
|
|
28
|
+
onlyValid: true,
|
|
29
|
+
limit: 100,
|
|
30
|
+
page: 1
|
|
31
|
+
// ...(typeof availableAtId === 'string') ? { store: { id: availableAtId } } : undefined
|
|
32
|
+
})({
|
|
33
|
+
event: eventRepo,
|
|
34
|
+
offer: offerRepo,
|
|
35
|
+
offerCatalog: offerCatalogRepo,
|
|
36
|
+
product: productRepo
|
|
37
|
+
});
|
|
38
|
+
console.log(result);
|
|
39
|
+
console.log(result.length);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main()
|
|
43
|
+
.then(console.log)
|
|
44
|
+
.catch(console.error);
|
|
@@ -18,7 +18,7 @@ export declare class MongoRepository {
|
|
|
18
18
|
private readonly aggregateOfferModel;
|
|
19
19
|
private readonly offerCatalogModel;
|
|
20
20
|
constructor(connection: Connection);
|
|
21
|
-
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: factory.unitPriceOffer.ISearchConditions): IMatchStage[];
|
|
21
|
+
static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): IMatchStage[];
|
|
22
22
|
static CREATE_AGGREGATE_OFFERS_PROJECTION(params: IProjection): {
|
|
23
23
|
[field: string]: AnyExpression;
|
|
24
24
|
};
|
|
@@ -92,6 +92,25 @@ export declare class MongoRepository {
|
|
|
92
92
|
*/
|
|
93
93
|
sortedOfferIds: string[];
|
|
94
94
|
}>;
|
|
95
|
+
/**
|
|
96
|
+
* カタログに記載されたオファーにおいて利用可能な決済方法区分を検索する
|
|
97
|
+
*/
|
|
98
|
+
searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params: {
|
|
99
|
+
subOfferCatalog: {
|
|
100
|
+
/**
|
|
101
|
+
* サブカタログID
|
|
102
|
+
*/
|
|
103
|
+
id: string;
|
|
104
|
+
};
|
|
105
|
+
availableAtOrFrom?: {
|
|
106
|
+
id?: string;
|
|
107
|
+
};
|
|
108
|
+
unacceptedPaymentMethod?: string[];
|
|
109
|
+
excludeAppliesToMovieTicket: boolean;
|
|
110
|
+
onlyValid?: boolean;
|
|
111
|
+
limit?: number;
|
|
112
|
+
page?: number;
|
|
113
|
+
}): Promise<Pick<factory.priceSpecification.unitPrice.IAppliesToMovieTicket, 'serviceOutput'>[]>;
|
|
95
114
|
findAggregateOfferById(params: {
|
|
96
115
|
project: {
|
|
97
116
|
id: string;
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -535,6 +535,48 @@ class MongoRepository {
|
|
|
535
535
|
return { offers, sortedOfferIds };
|
|
536
536
|
});
|
|
537
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* カタログに記載されたオファーにおいて利用可能な決済方法区分を検索する
|
|
540
|
+
*/
|
|
541
|
+
searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params) {
|
|
542
|
+
var _a;
|
|
543
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
544
|
+
const searchOffersConditions = Object.assign(Object.assign({ includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
545
|
+
? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
|
|
546
|
+
: undefined), { priceSpecification: {
|
|
547
|
+
appliesToMovieTicket: Object.assign({
|
|
548
|
+
// 基本は適用決済カード区分有のみ検索
|
|
549
|
+
serviceType: { $exists: (!params.excludeAppliesToMovieTicket === true) } }, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
|
|
550
|
+
? { serviceOutput: { typeOf: { $nin: params.unacceptedPaymentMethod } } }
|
|
551
|
+
: undefined)
|
|
552
|
+
}, onlyValid: params.onlyValid === true });
|
|
553
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(searchOffersConditions);
|
|
554
|
+
const aggregate = this.aggregateOfferModel.aggregate([
|
|
555
|
+
{ $unwind: { path: '$offers' } },
|
|
556
|
+
{ $unwind: { path: '$offers.priceSpecification.appliesToMovieTicket' } },
|
|
557
|
+
...matchStages,
|
|
558
|
+
{
|
|
559
|
+
$group: {
|
|
560
|
+
_id: '$offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf',
|
|
561
|
+
appliesToMovieTicket: { $first: '$offers.priceSpecification.appliesToMovieTicket' }
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
{ $sort: { _id: factory.sortType.Ascending } },
|
|
565
|
+
{
|
|
566
|
+
$project: {
|
|
567
|
+
_id: 0,
|
|
568
|
+
serviceOutput: { typeOf: '$_id' }
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
]);
|
|
572
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
573
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
574
|
+
aggregate.limit(params.limit * page)
|
|
575
|
+
.skip(params.limit * (page - 1));
|
|
576
|
+
}
|
|
577
|
+
return aggregate.exec();
|
|
578
|
+
});
|
|
579
|
+
}
|
|
538
580
|
findAggregateOfferById(params) {
|
|
539
581
|
return __awaiter(this, void 0, void 0, function* () {
|
|
540
582
|
const doc = yield this.aggregateOfferModel.findOne({
|
|
@@ -54,4 +54,32 @@ declare function searchEventTicketOffers(params: {
|
|
|
54
54
|
ticketOffers: ITicketOfferWithSortIndex[];
|
|
55
55
|
unitPriceOffers: factory.unitPriceOffer.IUnitPriceOffer[];
|
|
56
56
|
}>;
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
|
+
* オファーで利用可能な適用決済カード条件を検索する
|
|
59
|
+
*/
|
|
60
|
+
declare function searchOfferAppliesToMovieTicket(params: {
|
|
61
|
+
event: {
|
|
62
|
+
/**
|
|
63
|
+
* イベントID
|
|
64
|
+
*/
|
|
65
|
+
id: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* どのアプリケーションに対して
|
|
69
|
+
*/
|
|
70
|
+
store?: {
|
|
71
|
+
id?: string;
|
|
72
|
+
};
|
|
73
|
+
limit?: number;
|
|
74
|
+
page?: number;
|
|
75
|
+
/**
|
|
76
|
+
* 有効なオファーのみ対象とするか
|
|
77
|
+
*/
|
|
78
|
+
onlyValid?: boolean;
|
|
79
|
+
}): (repos: {
|
|
80
|
+
event: EventRepo;
|
|
81
|
+
offer: OfferRepo;
|
|
82
|
+
offerCatalog: OfferCatalogRepo;
|
|
83
|
+
product: ProductRepo;
|
|
84
|
+
}) => Promise<Pick<factory.priceSpecification.unitPrice.IAppliesToMovieTicket, 'serviceOutput'>[]>;
|
|
85
|
+
export { searchEventTicketOffers, searchOfferAppliesToMovieTicket };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.searchEventTicketOffers = void 0;
|
|
12
|
+
exports.searchOfferAppliesToMovieTicket = exports.searchEventTicketOffers = void 0;
|
|
13
13
|
const moment = require("moment-timezone");
|
|
14
14
|
const factory = require("../../../factory");
|
|
15
15
|
const factory_1 = require("../factory");
|
|
@@ -288,3 +288,59 @@ function searchEventTicketOffers(params) {
|
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
exports.searchEventTicketOffers = searchEventTicketOffers;
|
|
291
|
+
/**
|
|
292
|
+
* オファーで利用可能な適用決済カード条件を検索する
|
|
293
|
+
*/
|
|
294
|
+
function searchOfferAppliesToMovieTicket(params) {
|
|
295
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
var _a, _b, _c;
|
|
297
|
+
const event = yield repos.event.findMinimizedIndividualEventById({ id: params.event.id });
|
|
298
|
+
// let soundFormatTypes: string[] = [];
|
|
299
|
+
let videoFormatTypes = [];
|
|
300
|
+
if (event.typeOf === factory.eventType.ScreeningEvent) {
|
|
301
|
+
const superEvents = yield repos.event.search({
|
|
302
|
+
limit: 1,
|
|
303
|
+
page: 1,
|
|
304
|
+
id: { $eq: event.superEvent.id },
|
|
305
|
+
typeOf: factory.eventType.ScreeningEventSeries
|
|
306
|
+
}, { soundFormat: 1, videoFormat: 1 });
|
|
307
|
+
const superEvent = superEvents.shift();
|
|
308
|
+
if (superEvent === undefined) {
|
|
309
|
+
throw new factory.errors.NotFound(factory.eventType.ScreeningEventSeries);
|
|
310
|
+
}
|
|
311
|
+
// soundFormatTypes = (Array.isArray(superEvent.soundFormat)) ? superEvent.soundFormat.map((f) => f.typeOf) : [];
|
|
312
|
+
videoFormatTypes = (Array.isArray(superEvent.videoFormat)) ? superEvent.videoFormat.map((f) => f.typeOf) : [];
|
|
313
|
+
}
|
|
314
|
+
const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event });
|
|
315
|
+
// 上映方式がなければMovieTicket除外
|
|
316
|
+
const excludeAppliesToMovieTicket = videoFormatTypes.length === 0;
|
|
317
|
+
// 興行設定があれば興行のカタログを参照する
|
|
318
|
+
const eventOffers = event.offers;
|
|
319
|
+
let catalogId;
|
|
320
|
+
if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
|
|
321
|
+
const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
|
|
322
|
+
if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
|
|
323
|
+
catalogId = eventService.hasOfferCatalog.id;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (typeof catalogId !== 'string') {
|
|
327
|
+
throw new factory.errors.NotFound('itemOffered.hasOfferCatalog');
|
|
328
|
+
}
|
|
329
|
+
// サブカタログIDを決定
|
|
330
|
+
let subOfferCatalogId = catalogId;
|
|
331
|
+
const offerCatalogFirstElement = yield repos.offerCatalog.findFirstItemListElementById({ id: catalogId });
|
|
332
|
+
if (offerCatalogFirstElement.typeOf === 'OfferCatalog') {
|
|
333
|
+
subOfferCatalogId = offerCatalogFirstElement.id;
|
|
334
|
+
}
|
|
335
|
+
return repos.offer.searchAvaialbleAppliesToMovieTicketByOfferCatalogId({
|
|
336
|
+
subOfferCatalog: { id: subOfferCatalogId },
|
|
337
|
+
availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
|
|
338
|
+
unacceptedPaymentMethod: unacceptedPaymentMethod,
|
|
339
|
+
excludeAppliesToMovieTicket: excludeAppliesToMovieTicket,
|
|
340
|
+
onlyValid: params.onlyValid === true,
|
|
341
|
+
limit: params.limit,
|
|
342
|
+
page: params.page
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
exports.searchOfferAppliesToMovieTicket = searchOfferAppliesToMovieTicket;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { authorize } from './event/authorize';
|
|
2
2
|
import { cancel } from './event/cancel';
|
|
3
3
|
import { importCategoryCodesFromCOA, importFromCOA } from './event/importFromCOA';
|
|
4
|
-
import { searchEventTicketOffers } from './event/searchEventTicketOffers';
|
|
4
|
+
import { searchEventTicketOffers, searchOfferAppliesToMovieTicket } from './event/searchEventTicketOffers';
|
|
5
5
|
import { voidTransaction } from './event/voidTransaction';
|
|
6
|
-
export { authorize, cancel, importCategoryCodesFromCOA, importFromCOA, voidTransaction, searchEventTicketOffers };
|
|
6
|
+
export { authorize, cancel, importCategoryCodesFromCOA, importFromCOA, voidTransaction, searchEventTicketOffers, searchOfferAppliesToMovieTicket };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchEventTicketOffers = exports.voidTransaction = exports.importFromCOA = exports.importCategoryCodesFromCOA = exports.cancel = exports.authorize = void 0;
|
|
3
|
+
exports.searchOfferAppliesToMovieTicket = exports.searchEventTicketOffers = exports.voidTransaction = exports.importFromCOA = exports.importCategoryCodesFromCOA = exports.cancel = exports.authorize = void 0;
|
|
4
4
|
const authorize_1 = require("./event/authorize");
|
|
5
5
|
Object.defineProperty(exports, "authorize", { enumerable: true, get: function () { return authorize_1.authorize; } });
|
|
6
6
|
const cancel_1 = require("./event/cancel");
|
|
@@ -10,5 +10,6 @@ Object.defineProperty(exports, "importCategoryCodesFromCOA", { enumerable: true,
|
|
|
10
10
|
Object.defineProperty(exports, "importFromCOA", { enumerable: true, get: function () { return importFromCOA_1.importFromCOA; } });
|
|
11
11
|
const searchEventTicketOffers_1 = require("./event/searchEventTicketOffers");
|
|
12
12
|
Object.defineProperty(exports, "searchEventTicketOffers", { enumerable: true, get: function () { return searchEventTicketOffers_1.searchEventTicketOffers; } });
|
|
13
|
+
Object.defineProperty(exports, "searchOfferAppliesToMovieTicket", { enumerable: true, get: function () { return searchEventTicketOffers_1.searchOfferAppliesToMovieTicket; } });
|
|
13
14
|
const voidTransaction_1 = require("./event/voidTransaction");
|
|
14
15
|
Object.defineProperty(exports, "voidTransaction", { enumerable: true, get: function () { return voidTransaction_1.voidTransaction; } });
|
package/package.json
CHANGED