@chevre/domain 21.18.0-alpha.39 → 21.18.0-alpha.40

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.
@@ -24,7 +24,25 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import type { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
- export type IProduct = factory.product.IProduct | factory.service.paymentService.IService;
27
+ type IKeyOfProjection4product = keyof factory.product.IProduct | '_id';
28
+ /**
29
+ * プロダクト検索条件
30
+ */
31
+ type ISearchConditions4product = factory.product.ISearchConditions & {
32
+ typeOf?: {
33
+ $eq?: factory.product.ProductType;
34
+ $in?: factory.product.ProductType[];
35
+ };
36
+ };
37
+ /**
38
+ * 決済サービス検索条件
39
+ */
40
+ type ISearchConditions4paymentService = factory.product.ISearchConditions & {
41
+ typeOf?: {
42
+ $eq?: factory.service.paymentService.PaymentServiceType;
43
+ $in?: factory.service.paymentService.PaymentServiceType[];
44
+ };
45
+ };
28
46
  export type IPaymentServiceByProvider = Pick<factory.service.paymentService.IService, 'name' | 'description' | 'typeOf' | 'id' | 'productID' | 'serviceType' | 'serviceOutput' | 'additionalProperty'> & {
29
47
  provider?: Pick<factory.service.paymentService.IProvider, 'credentials'>;
30
48
  };
@@ -38,8 +56,15 @@ export declare class MongoRepository {
38
56
  static CREATE_MONGO_CONDITIONS(params: factory.product.ISearchConditions): any[];
39
57
  findById(conditions: {
40
58
  id: string;
41
- }, inclusion: string[], exclusion: string[]): Promise<IProduct>;
42
- search(conditions: factory.product.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<IProduct[]>;
59
+ }, inclusion: string[], exclusion: string[]): Promise<factory.product.IProduct | factory.service.paymentService.IService>;
60
+ /**
61
+ * プロダクトを検索する
62
+ */
63
+ searchProducts(conditions: ISearchConditions4product, inclusion: IKeyOfProjection4product[], exclusion: IKeyOfProjection4product[]): Promise<factory.product.IProduct[]>;
64
+ /**
65
+ * 決済サービスを検索する
66
+ */
67
+ searchPaymentServices(conditions: ISearchConditions4paymentService, inclusion: string[], exclusion: string[]): Promise<factory.service.paymentService.IService[]>;
43
68
  deleteById(params: {
44
69
  id: string;
45
70
  }): Promise<void>;
@@ -53,7 +78,7 @@ export declare class MongoRepository {
53
78
  typeOf: factory.service.paymentService.PaymentServiceType;
54
79
  id: string;
55
80
  }): Promise<factory.product.IAvailableChannel>;
56
- searchPaymentServicesByProvider(params: Pick<factory.product.ISearchConditions, 'limit' | 'page' | 'sort' | 'project' | 'provider' | 'typeOf'>): Promise<IPaymentServiceByProvider[]>;
81
+ searchPaymentServicesByProvider(params: Pick<ISearchConditions4paymentService, 'limit' | 'page' | 'sort' | 'project' | 'provider' | 'typeOf'>): Promise<IPaymentServiceByProvider[]>;
57
82
  /**
58
83
  * プロダクトを保管する
59
84
  */
@@ -151,10 +151,7 @@ class MongoRepository {
151
151
  }
152
152
  return andConditions;
153
153
  }
154
- findById(conditions,
155
- // inclusion化(2023-07-20~)
156
- // projection?: { [key: string]: number }
157
- inclusion, exclusion) {
154
+ findById(conditions, inclusion, exclusion) {
158
155
  return __awaiter(this, void 0, void 0, function* () {
159
156
  let projection = {};
160
157
  if (Array.isArray(inclusion) && inclusion.length > 0) {
@@ -182,9 +179,51 @@ class MongoRepository {
182
179
  return doc.toObject();
183
180
  });
184
181
  }
185
- search(conditions,
186
- // projection?: { [key: string]: number }
187
- inclusion, exclusion) {
182
+ /**
183
+ * プロダクトを検索する
184
+ */
185
+ searchProducts(conditions, inclusion, exclusion) {
186
+ var _a;
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ const andConditions = MongoRepository.CREATE_MONGO_CONDITIONS(conditions);
189
+ let projection = {};
190
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
191
+ inclusion.forEach((field) => {
192
+ projection[field] = 1;
193
+ });
194
+ }
195
+ else {
196
+ projection = {
197
+ __v: 0,
198
+ createdAt: 0,
199
+ updatedAt: 0
200
+ };
201
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
202
+ exclusion.forEach((field) => {
203
+ projection[field] = 0;
204
+ });
205
+ }
206
+ }
207
+ const query = this.productModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
208
+ if (typeof conditions.limit === 'number' && conditions.limit > 0) {
209
+ const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
210
+ query.limit(conditions.limit)
211
+ .skip(conditions.limit * (page - 1));
212
+ }
213
+ // tslint:disable-next-line:no-single-line-block-comment
214
+ /* istanbul ignore else */
215
+ if (((_a = conditions.sort) === null || _a === void 0 ? void 0 : _a.productID) !== undefined) {
216
+ query.sort({ productID: conditions.sort.productID });
217
+ }
218
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
219
+ .exec()
220
+ .then((docs) => docs.map((doc) => doc.toObject()));
221
+ });
222
+ }
223
+ /**
224
+ * 決済サービスを検索する
225
+ */
226
+ searchPaymentServices(conditions, inclusion, exclusion) {
188
227
  var _a;
189
228
  return __awaiter(this, void 0, void 0, function* () {
190
229
  const andConditions = MongoRepository.CREATE_MONGO_CONDITIONS(conditions);
@@ -233,7 +272,7 @@ class MongoRepository {
233
272
  */
234
273
  findAvailableChannel(params) {
235
274
  return __awaiter(this, void 0, void 0, function* () {
236
- const paymentServices = yield this.search({
275
+ const paymentServices = yield this.searchPaymentServices({
237
276
  limit: 1,
238
277
  page: 1,
239
278
  project: { id: { $eq: params.project.id } },
@@ -186,7 +186,16 @@ function calculateOfferCount(params) {
186
186
  try {
187
187
  const eventOffers = params.event.offers;
188
188
  if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
189
- const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
189
+ // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
190
+ // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
191
+ const eventService = (yield repos.product.searchProducts({
192
+ limit: 1,
193
+ page: 1,
194
+ id: { $eq: eventOffers.itemOffered.id }
195
+ }, ['hasOfferCatalog'], [])).shift();
196
+ if (eventService === undefined) {
197
+ throw new factory.errors.NotFound(factory.product.ProductType.EventService);
198
+ }
190
199
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
191
200
  const catalogs = yield repos.offerCatalog.search({
192
201
  limit: 1,
@@ -23,7 +23,16 @@ function findEventOffers(params) {
23
23
  // 興行設定があれば興行のカタログを参照する
24
24
  const eventOffers = params.event.offers;
25
25
  if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
26
- const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
26
+ // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
27
+ // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
28
+ const eventService = (yield repos.product.searchProducts({
29
+ limit: 1,
30
+ page: 1,
31
+ id: { $eq: eventOffers.itemOffered.id }
32
+ }, ['hasOfferCatalog'], [])).shift();
33
+ if (eventService === undefined) {
34
+ throw new factory.errors.NotFound(factory.product.ProductType.EventService);
35
+ }
27
36
  const offerCatalogId = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id;
28
37
  if (typeof offerCatalogId === 'string') {
29
38
  // サブカタログIDを決定
@@ -28,7 +28,7 @@ function start(params) {
28
28
  var _a;
29
29
  const issuedThroughId = fixIssuedThroughId(params);
30
30
  // location.issuedThroughIdからプロダクトをfixする
31
- const products = yield repos.product.search({
31
+ const products = yield repos.product.searchProducts({
32
32
  limit: 1,
33
33
  page: 1,
34
34
  project: { id: { $eq: params.project.id } },
@@ -186,7 +186,7 @@ function fixPaymentService(params) {
186
186
  break;
187
187
  default:
188
188
  const paymentServiceId = yield getPaymentServiceId(params)();
189
- const paymentServices = yield repos.product.search({
189
+ const paymentServices = yield repos.product.searchPaymentServices({
190
190
  limit: 1,
191
191
  page: 1,
192
192
  project: { id: { $eq: params.project.id } },
@@ -85,7 +85,7 @@ function fixPaymentService(params) {
85
85
  // FaceToFaceの場合プロダクトは存在しない
86
86
  break;
87
87
  default:
88
- const paymentServices = yield repos.product.search({
88
+ const paymentServices = yield repos.product.searchPaymentServices({
89
89
  limit: 1,
90
90
  page: 1,
91
91
  project: { id: { $eq: params.payAction.project.id } },
@@ -44,7 +44,15 @@ function start(params) {
44
44
  throw new factory.errors.ArgumentNull('object.itemOffered.id');
45
45
  }
46
46
  // プロダクト確認
47
- const product = yield repos.product.findById({ id: productId }, [], []);
47
+ // const product = await repos.product.findProductById({ id: productId }, [], []);
48
+ const product = (yield repos.product.searchProducts({
49
+ limit: 1,
50
+ page: 1,
51
+ id: { $eq: productId }
52
+ }, [], [])).shift();
53
+ if (product === undefined) {
54
+ throw new factory.errors.NotFound('Product');
55
+ }
48
56
  const transactionNumber = params.transactionNumber;
49
57
  if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) {
50
58
  throw new factory.errors.ArgumentNull('transactionNumber');
@@ -130,7 +138,15 @@ function createTransactionObject(params) {
130
138
  function createPermitService(params) {
131
139
  return (repos) => __awaiter(this, void 0, void 0, function* () {
132
140
  var _a, _b, _c, _d, _e, _f, _g;
133
- const product = yield repos.product.findById({ id: params.issuedThrough.id }, [], []);
141
+ // const product = await repos.product.findProductById({ id: params.issuedThrough.id }, [], []);
142
+ const product = (yield repos.product.searchProducts({
143
+ limit: 1,
144
+ page: 1,
145
+ id: { $eq: params.issuedThrough.id }
146
+ }, [], [])).shift();
147
+ if (product === undefined) {
148
+ throw new factory.errors.NotFound('Product');
149
+ }
134
150
  const permitServiceEndpoint = (_a = product.availableChannel) === null || _a === void 0 ? void 0 : _a.serviceUrl;
135
151
  const permitServiceAuthorizeServerDomain = (_c = (_b = product.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials) === null || _c === void 0 ? void 0 : _c.authorizeServerDomain;
136
152
  const permitServiceClientId = (_e = (_d = product.availableChannel) === null || _d === void 0 ? void 0 : _d.credentials) === null || _e === void 0 ? void 0 : _e.clientId;
@@ -558,6 +558,7 @@ function validateAdvanceBookingRequirement(params) {
558
558
  }
559
559
  }
560
560
  function validateProgramMembershipUsed(params) {
561
+ // tslint:disable-next-line:max-func-body-length
561
562
  return (repos) => __awaiter(this, void 0, void 0, function* () {
562
563
  var _a, _b, _c;
563
564
  const now = new Date();
@@ -572,7 +573,27 @@ function validateProgramMembershipUsed(params) {
572
573
  if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
573
574
  throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed.issuedThrough.id');
574
575
  }
575
- const permitIssuedThrough = yield repos.product.findById({ id: issuedThroughId }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], []);
576
+ let permitIssuedThrough;
577
+ // まずメンバーシップを検索して、存在しなければCreditCardを検索(どちらが発行元サービスか不明なので)
578
+ permitIssuedThrough = (yield repos.product.searchProducts({
579
+ limit: 1,
580
+ page: 1,
581
+ id: { $eq: issuedThroughId },
582
+ typeOf: { $eq: factory.product.ProductType.MembershipService }
583
+ }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
584
+ if (permitIssuedThrough === undefined) {
585
+ permitIssuedThrough = (yield repos.product.searchPaymentServices({
586
+ limit: 1,
587
+ page: 1,
588
+ id: { $eq: issuedThroughId },
589
+ typeOf: { $eq: factory.service.paymentService.PaymentServiceType.CreditCard }
590
+ }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
591
+ }
592
+ if (typeof (permitIssuedThrough === null || permitIssuedThrough === void 0 ? void 0 : permitIssuedThrough.typeOf) !== 'string') {
593
+ throw new factory.errors.NotFound(`Permit issuer service [${issuedThroughId}]`);
594
+ }
595
+ // permitIssuedThrough =
596
+ // await repos.product.findById({ id: issuedThroughId }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], []);
576
597
  switch (permitIssuedThrough.typeOf) {
577
598
  // 発行サービスがCreditCardのケースに対応(2023-09-01~)
578
599
  case factory.service.paymentService.PaymentServiceType.CreditCard:
@@ -637,7 +658,16 @@ function validateProgramMembershipUsed(params) {
637
658
  function createPermitService(params) {
638
659
  return (repos) => __awaiter(this, void 0, void 0, function* () {
639
660
  var _a, _b, _c, _d, _e, _f, _g;
640
- const product = yield repos.product.findById({ id: params.issuedThrough.id }, ['availableChannel'], []);
661
+ // const product = <Pick<factory.product.IProduct, 'availableChannel'>>
662
+ // await repos.product.findProductById({ id: params.issuedThrough.id }, ['availableChannel'], []);
663
+ const product = (yield repos.product.searchProducts({
664
+ limit: 1,
665
+ page: 1,
666
+ id: { $eq: params.issuedThrough.id }
667
+ }, ['availableChannel'], [])).shift();
668
+ if (product === undefined) {
669
+ throw new factory.errors.NotFound('Product');
670
+ }
641
671
  const permitServiceEndpoint = (_a = product.availableChannel) === null || _a === void 0 ? void 0 : _a.serviceUrl;
642
672
  const permitServiceAuthorizeServerDomain = (_c = (_b = product.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials) === null || _c === void 0 ? void 0 : _c.authorizeServerDomain;
643
673
  const permitServiceClientId = (_e = (_d = product.availableChannel) === null || _d === void 0 ? void 0 : _d.credentials) === null || _e === void 0 ? void 0 : _e.clientId;
@@ -326,7 +326,17 @@ function getIssuedThroughIdByAction(params) {
326
326
  function createPermitServiceCredentials(params) {
327
327
  return (repos) => __awaiter(this, void 0, void 0, function* () {
328
328
  var _a, _b, _c, _d, _e, _f, _g;
329
- const paymentCardService = yield repos.product.findById({ id: params.issuedThrough.id }, ['availableChannel'], []);
329
+ // const paymentCardService = <Pick<factory.product.IProduct, 'availableChannel'>>
330
+ // await repos.product.findProductById({ id: params.issuedThrough.id }, ['availableChannel'], []);
331
+ const paymentCardService = (yield repos.product.searchProducts({
332
+ limit: 1,
333
+ page: 1,
334
+ id: { $eq: params.issuedThrough.id },
335
+ typeOf: { $eq: factory.product.ProductType.PaymentCard }
336
+ }, ['availableChannel'], [])).shift();
337
+ if (paymentCardService === undefined) {
338
+ throw new factory.errors.NotFound(factory.product.ProductType.PaymentCard);
339
+ }
330
340
  const permitServiceEndpoint = (_a = paymentCardService.availableChannel) === null || _a === void 0 ? void 0 : _a.serviceUrl;
331
341
  const permitServiceAuthorizeServerDomain = (_c = (_b = paymentCardService.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials) === null || _c === void 0 ? void 0 : _c.authorizeServerDomain;
332
342
  const permitServiceClientId = (_e = (_d = paymentCardService.availableChannel) === null || _d === void 0 ? void 0 : _d.credentials) === null || _e === void 0 ? void 0 : _e.clientId;
@@ -18,9 +18,17 @@ function searchTicketOffersByItemOffered(params) {
18
18
  // tslint:disable-next-line:max-func-body-length
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a, _b, _c, _d, _e, _f, _g;
21
- let eventService;
21
+ // let eventService: Pick<factory.product.IProduct, 'hasOfferCatalog' | 'project'> | undefined;
22
22
  let catalogId;
23
- eventService = yield repos.product.findById({ id: (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.id }, ['hasOfferCatalog', 'project'], []);
23
+ // const eventService = await repos.product.findProductById({ id: params.itemOffered?.id }, ['hasOfferCatalog', 'project'], []);
24
+ const eventService = (yield repos.product.searchProducts({
25
+ limit: 1,
26
+ page: 1,
27
+ id: { $eq: String((_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.id) }
28
+ }, ['hasOfferCatalog', 'project'], [])).shift();
29
+ if (eventService === undefined) {
30
+ throw new factory.errors.NotFound(factory.product.ProductType.EventService);
31
+ }
24
32
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
25
33
  catalogId = eventService.hasOfferCatalog.id;
26
34
  }
@@ -370,7 +378,16 @@ function searchOfferAppliesToMovieTicket(params) {
370
378
  const eventOffers = event.offers;
371
379
  let catalogId;
372
380
  if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
373
- const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
381
+ // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
382
+ // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
383
+ const eventService = (yield repos.product.searchProducts({
384
+ limit: 1,
385
+ page: 1,
386
+ id: { $eq: eventOffers.itemOffered.id }
387
+ }, ['hasOfferCatalog'], [])).shift();
388
+ if (eventService === undefined) {
389
+ throw new factory.errors.NotFound(factory.product.ProductType.EventService);
390
+ }
374
391
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
375
392
  catalogId = eventService.hasOfferCatalog.id;
376
393
  }
@@ -417,7 +434,16 @@ function searchOfferCatalogItems(params) {
417
434
  const eventOffers = event.offers;
418
435
  let catalogId;
419
436
  if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
420
- const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
437
+ // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
438
+ // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
439
+ const eventService = (yield repos.product.searchProducts({
440
+ limit: 1,
441
+ page: 1,
442
+ id: { $eq: eventOffers.itemOffered.id }
443
+ }, ['hasOfferCatalog'], [])).shift();
444
+ if (eventService === undefined) {
445
+ throw new factory.errors.NotFound(factory.product.ProductType.EventService);
446
+ }
421
447
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
422
448
  catalogId = eventService.hasOfferCatalog.id;
423
449
  }
@@ -477,7 +503,16 @@ function searchOfferCatalogItemAvailability(params) {
477
503
  const eventOffers = event.offers;
478
504
  let catalogId;
479
505
  if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
480
- const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
506
+ // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
507
+ // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
508
+ const eventService = (yield repos.product.searchProducts({
509
+ limit: 1,
510
+ page: 1,
511
+ id: { $eq: eventOffers.itemOffered.id }
512
+ }, ['hasOfferCatalog'], [])).shift();
513
+ if (eventService === undefined) {
514
+ throw new factory.errors.NotFound(factory.product.ProductType.EventService);
515
+ }
481
516
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
482
517
  catalogId = eventService.hasOfferCatalog.id;
483
518
  }
@@ -20,7 +20,16 @@ function searchProductOffers(params) {
20
20
  return (repos) => __awaiter(this, void 0, void 0, function* () {
21
21
  var _a, _b;
22
22
  // プロダクト検索
23
- const productWithOffers = yield repos.product.findById({ id: params.itemOffered.id }, ['hasOfferCatalog', 'project'], []);
23
+ // const productWithOffers = <Pick<factory.product.IProduct, 'hasOfferCatalog' | 'project'>>
24
+ // await repos.product.findProductById({ id: params.itemOffered.id }, ['hasOfferCatalog', 'project'], []);
25
+ const productWithOffers = (yield repos.product.searchProducts({
26
+ limit: 1,
27
+ page: 1,
28
+ id: { $eq: params.itemOffered.id }
29
+ }, ['hasOfferCatalog', 'project'], [])).shift();
30
+ if (productWithOffers === undefined) {
31
+ throw new factory.errors.NotFound('Product');
32
+ }
24
33
  const offerCatalogId = (_a = productWithOffers.hasOfferCatalog) === null || _a === void 0 ? void 0 : _a.id;
25
34
  if (typeof offerCatalogId !== 'string') {
26
35
  return [];
@@ -26,7 +26,7 @@ function search(params) {
26
26
  return (repos) => __awaiter(this, void 0, void 0, function* () {
27
27
  var _a;
28
28
  const now = moment();
29
- const searchProductsResult = yield repos.product.search({
29
+ const searchProductsResult = yield repos.product.searchProducts({
30
30
  limit: 1,
31
31
  page: 1,
32
32
  project: { id: { $eq: params.project.id } },
@@ -178,7 +178,7 @@ function fixProductAndOffers(params) {
178
178
  return (repos) => __awaiter(this, void 0, void 0, function* () {
179
179
  var _a, _b, _c;
180
180
  const productId = String((_b = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.id);
181
- const searchProductsResult = yield repos.product.search({
181
+ const searchProductsResult = yield repos.product.searchProducts({
182
182
  limit: 1,
183
183
  page: 1,
184
184
  project: { id: { $eq: params.project.id } },
@@ -15,12 +15,11 @@ function getCredentials(params) {
15
15
  return (repos) => __awaiter(this, void 0, void 0, function* () {
16
16
  var _a, _b, _c;
17
17
  // 決済サービスからcredentialsを取得する
18
- const paymentServices = yield repos.product.search({
18
+ const paymentServices = yield repos.product.searchPaymentServices({
19
19
  limit: 1,
20
20
  page: 1,
21
21
  project: { id: { $eq: params.seller.project.id } },
22
22
  typeOf: { $eq: factory.service.paymentService.PaymentServiceType.MovieTicket },
23
- // serviceType: { codeValue: { $eq: params.paymentMethodType } },
24
23
  id: { $eq: params.paymentServiceId }
25
24
  }, [], []);
26
25
  const paymentService = paymentServices.shift();
@@ -79,8 +79,15 @@ function validatePaymentMethod(params, paymentServiceId) {
79
79
  throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
80
80
  }
81
81
  // プロダクトから通貨区分を取得
82
- const paymentCatdProduct = yield repos.product.findById({ id: paymentServiceId }, ['serviceOutput'], []);
83
- const currency = (_e = (_d = paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
82
+ // const paymentCatdProduct = <Pick<factory.product.IProduct, 'serviceOutput'>>
83
+ // await repos.product.findProductById({ id: paymentServiceId }, ['serviceOutput'], []);
84
+ const paymentCatdProduct = (yield repos.product.searchProducts({
85
+ limit: 1,
86
+ page: 1,
87
+ id: { $eq: paymentServiceId },
88
+ typeOf: { $eq: factory.product.ProductType.PaymentCard }
89
+ }, ['serviceOutput'], [])).shift();
90
+ const currency = (_e = (_d = paymentCatdProduct === null || paymentCatdProduct === void 0 ? void 0 : paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
84
91
  if (typeof currency !== 'string') {
85
92
  throw new factory.errors.NotFound('product.serviceOutput.amount.currency');
86
93
  }
@@ -337,7 +337,7 @@ function deleteResourcesByOfferCatalog(params) {
337
337
  const action = yield repos.action.start(deleteActionAttributes);
338
338
  try {
339
339
  // カタログからプロダクト検索
340
- const productsWithCatalog = yield repos.product.search({
340
+ const productsWithCatalog = yield repos.product.searchProducts({
341
341
  project: { id: { $eq: params.project.id } },
342
342
  hasOfferCatalog: { id: { $eq: catalogId } }
343
343
  }, ['_id'], []);
@@ -187,7 +187,7 @@ function createInformMovieTasks(params) {
187
187
  }
188
188
  function createInformProductTasks(params) {
189
189
  return (repos) => __awaiter(this, void 0, void 0, function* () {
190
- const products4inform = yield repos.product.search({
190
+ const products4inform = yield repos.product.searchProducts({
191
191
  typeOf: { $eq: params.typeOf },
192
192
  id: { $in: params.ids }
193
193
  }, ['additionalProperty', 'description', 'name', 'productID', 'project', 'typeOf', 'serviceType'], []);
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.18.0-alpha.39"
118
+ "version": "21.18.0-alpha.40"
119
119
  }
@@ -1,29 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../../lib/index';
5
-
6
- import { findPaymentCardPermit } from '../../../../lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit';
7
-
8
- const project = { id: String(process.env.PROJECT_ID) };
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const ownershipInfoRepo = await chevre.repository.OwnershipInfo.createInstance(mongoose.connection);
13
- const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
14
-
15
- const result = await findPaymentCardPermit({
16
- project: { id: project.id },
17
- customer: { id: 'a7909268-a584-425e-8212-d7d10f344093' },
18
- now: new Date(),
19
- accountType: 'Point'
20
- })({
21
- product: productRepo,
22
- ownershipInfo: ownershipInfoRepo
23
- });
24
- console.log(result);
25
- }
26
-
27
- main()
28
- .then(console.log)
29
- .catch(console.error);
@@ -1,26 +0,0 @@
1
- /**
2
- * findPaymentCardPermit
3
- */
4
- import type { MongoRepository as OwnershipInfoRepo } from '../../../repo/ownershipInfo';
5
- import type { MongoRepository as ProductRepo } from '../../../repo/product';
6
- import * as factory from '../../../factory';
7
- /**
8
- * 所有ペイメントカードを検索
9
- * 指定した通貨の所有ペイメントカードを検索する
10
- */
11
- export declare function findPaymentCardPermit(params: {
12
- customer: {
13
- id: string;
14
- };
15
- project: {
16
- id: string;
17
- };
18
- now: Date;
19
- /**
20
- * 通貨区分
21
- */
22
- accountType: string;
23
- }): (repos: {
24
- ownershipInfo: OwnershipInfoRepo;
25
- product: ProductRepo;
26
- }) => Promise<factory.ownershipInfo.IPermitAsGood>;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.findPaymentCardPermit = void 0;
13
- const factory = require("../../../factory");
14
- /**
15
- * 所有ペイメントカードを検索
16
- * 指定した通貨の所有ペイメントカードを検索する
17
- */
18
- function findPaymentCardPermit(params) {
19
- return (repos) => __awaiter(this, void 0, void 0, function* () {
20
- const searchProductsResult = yield repos.product.search({
21
- limit: 1,
22
- page: 1,
23
- project: { id: { $eq: params.project.id } },
24
- typeOf: { $eq: factory.product.ProductType.PaymentCard }
25
- }, [], []);
26
- const accountProduct = searchProductsResult
27
- .find((p) => { var _a, _b; return ((_b = (_a = p.serviceOutput) === null || _a === void 0 ? void 0 : _a.amount) === null || _b === void 0 ? void 0 : _b.currency) === params.accountType; });
28
- if (accountProduct === undefined) {
29
- throw new factory.errors.NotFound(`${params.accountType} PaymentCard Product`);
30
- }
31
- let accountOwnershipInfos = [];
32
- try {
33
- // 口座所有権を検索
34
- const searchOwnershipInfosResult = yield repos.ownershipInfo.search({
35
- // 最も古い所有ペイメントカードをデフォルトペイメントカードとして扱う使用なので、ソート条件は以下の通り
36
- sort: { ownedFrom: factory.sortType.Ascending },
37
- limit: 1,
38
- page: 1,
39
- // 詳細取得できていないが、必要ない
40
- typeOfGood: {
41
- issuedThrough: {
42
- id: { $eq: String(accountProduct.id) },
43
- typeOf: { $eq: factory.product.ProductType.PaymentCard }
44
- }
45
- },
46
- ownedFrom: params.now,
47
- ownedThrough: params.now,
48
- ownedBy: { id: params.customer.id }
49
- });
50
- accountOwnershipInfos = searchOwnershipInfosResult;
51
- }
52
- catch (error) {
53
- throw error;
54
- }
55
- // Openedしか存在しなくなったので、この処理は不要です
56
- // accountOwnershipInfos = accountOwnershipInfos.filter(
57
- // (o) => o.typeOfGood.paymentAccount?.status === factory.accountStatusType.Opened
58
- // );
59
- if (accountOwnershipInfos.length === 0) {
60
- throw new factory.errors.NotFound('OwnershipInfos of PaymentCard');
61
- }
62
- return accountOwnershipInfos[0].typeOfGood;
63
- });
64
- }
65
- exports.findPaymentCardPermit = findPaymentCardPermit;