@chevre/domain 22.2.0-alpha.3 → 22.2.0-alpha.5

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.
@@ -8,12 +8,12 @@ import { chevre } from '../../../lib/index';
8
8
  async function main() {
9
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
10
 
11
- const reservationRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
12
- const result = await reservationRepo.projectFieldsById(
11
+ const ownershipInfoRepo = await chevre.repository.OwnershipInfo.createInstance(mongoose.connection);
12
+ const result = await ownershipInfoRepo.projectFieldsById(
13
13
  {
14
- id: '948926445022844-0',
15
- inclusion: ['reservationStatus', 'reservationFor.id']
14
+ id: 'd9080760-1bdb-49cf-86eb-50f98fab0010'
16
15
  }
16
+ // ['id', 'typeOfGood']
17
17
  );
18
18
  // tslint:disable-next-line:no-null-keyword
19
19
  console.dir(result, { depth: null });
@@ -35,10 +35,12 @@ export declare class OwnershipInfoRepo {
35
35
  /**
36
36
  * なければ作成する
37
37
  */
38
- createIfNotExistByIdentifier(ownershipInfo: IOwnershipInfo): Promise<IOwnershipInfo>;
39
- findById(params: {
38
+ createIfNotExistByIdentifier(ownershipInfo: IOwnershipInfo): Promise<{
40
39
  id: string;
41
- }, projection?: any): Promise<IOwnershipInfo>;
40
+ }>;
41
+ projectFieldsById(params: {
42
+ id: string;
43
+ }, inclusion?: (keyof IOwnershipInfo)[]): Promise<IOwnershipInfo>;
42
44
  /**
43
45
  * 所有権を検索する
44
46
  */
@@ -233,11 +233,14 @@ class OwnershipInfoRepo {
233
233
  new: true,
234
234
  upsert: true,
235
235
  projection: {
236
- __v: 0,
237
- createdAt: 0,
238
- updatedAt: 0
236
+ _id: 0,
237
+ id: { $toString: '$_id' }
238
+ // __v: 0,
239
+ // createdAt: 0,
240
+ // updatedAt: 0
239
241
  }
240
242
  })
243
+ .lean()
241
244
  .exec();
242
245
  }
243
246
  catch (error) {
@@ -254,26 +257,50 @@ class OwnershipInfoRepo {
254
257
  if (duplicate) {
255
258
  // 重複の場合、再度取得
256
259
  doc = yield this.ownershipInfoModel.findOne({ identifier: { $eq: ownershipInfo.identifier } }, {
257
- __v: 0,
258
- createdAt: 0,
259
- updatedAt: 0
260
+ _id: 0,
261
+ id: { $toString: '$_id' }
262
+ // __v: 0,
263
+ // createdAt: 0,
264
+ // updatedAt: 0
260
265
  })
266
+ .lean()
261
267
  .exec();
262
268
  }
263
269
  if (doc === undefined || doc === null) {
264
270
  throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
265
271
  }
266
- return doc.toObject();
272
+ return { id: doc.id };
273
+ // return <IOwnershipInfo>doc.toObject();
267
274
  });
268
275
  }
269
- findById(params, projection) {
276
+ projectFieldsById(params, inclusion) {
270
277
  return __awaiter(this, void 0, void 0, function* () {
271
- const doc = yield this.ownershipInfoModel.findById(params.id, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
278
+ let projection = {
279
+ _id: 0,
280
+ id: { $toString: '$_id' },
281
+ project: 1,
282
+ typeOf: 1,
283
+ identifier: 1,
284
+ ownedBy: 1,
285
+ acquiredFrom: 1,
286
+ ownedFrom: 1,
287
+ ownedThrough: 1,
288
+ typeOfGood: 1
289
+ };
290
+ const positiveProjectionFields = (Array.isArray(inclusion))
291
+ ? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
292
+ : undefined;
293
+ if (Array.isArray(positiveProjectionFields)) {
294
+ projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
295
+ }
296
+ const doc = yield this.ownershipInfoModel.findOne({ _id: { $eq: params.id } }, projection)
297
+ .lean() // lean(2024-08-15~)
272
298
  .exec();
273
299
  if (doc === null) {
274
300
  throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
275
301
  }
276
- return doc.toObject();
302
+ return doc;
303
+ // return doc.toObject();
277
304
  });
278
305
  }
279
306
  /**
@@ -137,15 +137,31 @@ function acceptedOffers2amount(params) {
137
137
  return amount;
138
138
  }
139
139
  exports.acceptedOffers2amount = acceptedOffers2amount;
140
+ function acceptedOffers2programMembershipUsed(params) {
141
+ const programMembershipUsed = [];
142
+ const permitIdentifiers = [];
143
+ params.acceptedOffers.forEach(({ itemOffered }) => {
144
+ var _a;
145
+ if (((_a = itemOffered.programMembershipUsed) === null || _a === void 0 ? void 0 : _a.typeOf) === factory.permit.PermitType.Permit) {
146
+ // メンバーシップコードに対してユニークに集計
147
+ if (!permitIdentifiers.includes(itemOffered.programMembershipUsed.identifier)) {
148
+ permitIdentifiers.push(itemOffered.programMembershipUsed.identifier);
149
+ programMembershipUsed.push(itemOffered.programMembershipUsed);
150
+ }
151
+ }
152
+ });
153
+ return programMembershipUsed;
154
+ }
140
155
  function acceptedOffers2authorizeResult(params) {
141
156
  const { acceptedOffers, acceptedOffers4result, noOfferSpecified, ticketOffers } = params;
142
- // const priceCurrency = acceptedOffers[0]?.priceSpecification?.priceCurrency;
143
157
  const priceCurrency = factory.priceCurrency.JPY; // fix(2024-07-03~)
144
158
  // redefine as typeOf: AggregateOffer(2024-06-18~)
145
159
  let offers;
146
160
  let price;
161
+ let programMembershipUsed = [];
147
162
  if (!noOfferSpecified) {
148
163
  price = acceptedOffers2amount({ acceptedOffers: acceptedOffers4result }); // オファー指定の場合のみ金額計算(2023-11-27~)
164
+ programMembershipUsed = acceptedOffers2programMembershipUsed({ acceptedOffers: acceptedOffers4result });
149
165
  // オファーIDごとに集計
150
166
  const offerIds = [...new Set(acceptedOffers.map((o) => o.id))];
151
167
  offers = offerIds.map((offerId) => {
@@ -153,10 +169,6 @@ function acceptedOffers2authorizeResult(params) {
153
169
  if (acceptedOffer === undefined) {
154
170
  throw new factory.errors.Internal(`acceptedOffer not found [id:${offerId}]`);
155
171
  }
156
- // const acceptedOffer = acceptedOffers.find(({ id }) => id === offerId);
157
- // if (acceptedOffer === undefined) {
158
- // throw new factory.errors.Internal(`acceptedOffer not found [id:${offerId}]`);
159
- // }
160
172
  const amountOfThisGood = acceptedOffers.filter(({ id }) => id === offerId).length;
161
173
  const { acceptedPaymentMethod, priceSpecification } = acceptedOffer;
162
174
  const unitPriceSpec = priceSpecification.priceComponent.find((spec) => spec.typeOf === factory.priceSpecificationType.UnitPriceSpecification
@@ -169,7 +181,9 @@ function acceptedOffers2authorizeResult(params) {
169
181
  return Object.assign({ id: offerId, includesObject: { amountOfThisGood }, typeOf: factory.offerType.Offer, priceSpecification: Object.assign(Object.assign({}, (eligibleQuantity !== undefined) ? { eligibleQuantity } : undefined), (eligibleTransactionVolume !== undefined) ? { eligibleTransactionVolume } : undefined) }, (acceptedPaymentMethod !== undefined) ? { acceptedPaymentMethod } : undefined);
170
182
  });
171
183
  }
172
- return Object.assign(Object.assign({ typeOf: factory.offerType.AggregateOffer, priceCurrency, amount: [] }, (typeof price === 'number') ? { price } : undefined), (Array.isArray(offers)) ? { offers } : undefined);
184
+ return Object.assign(Object.assign({ typeOf: factory.offerType.AggregateOffer, priceCurrency, amount: [], itemOffered: {
185
+ serviceOutput: { programMembershipUsed } // add programMembershipUsed required(2024-08-15~)
186
+ } }, (typeof price === 'number') ? { price } : undefined), (Array.isArray(offers)) ? { offers } : undefined);
173
187
  }
174
188
  exports.acceptedOffers2authorizeResult = acceptedOffers2authorizeResult;
175
189
  function responseBody2acceptedOffers4result(params) {
@@ -86,7 +86,8 @@ function sendOrder(params) {
86
86
  typeOf: factory.actionType.SendAction
87
87
  };
88
88
  const action = yield repos.action.start(sendOrderActionAttributes);
89
- let ownershipInfos = [];
89
+ let creatingOwnershipInfos = [];
90
+ let createdOwnershipInfos = [];
90
91
  let allOffersDelivered = false;
91
92
  let acceptedOffers;
92
93
  // 所有権生成を最小化(2024-03-01~)
@@ -111,12 +112,15 @@ function sendOrder(params) {
111
112
  debug('delivering...', order.orderNumber, acceptedOffers.map((offer) => `${offer.itemOffered.id}`), params.object.acceptedOffers, 'offerIndexBase:', offerIndexBase);
112
113
  // 所有権作成
113
114
  if (createOwnerships) {
114
- ownershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({
115
+ creatingOwnershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({
115
116
  order: Object.assign(Object.assign({}, order), { acceptedOffers }),
116
117
  offerIndexBase
117
118
  });
118
- ownershipInfos = yield Promise.all(ownershipInfos.map((ownershipInfo) => __awaiter(this, void 0, void 0, function* () {
119
- return repos.ownershipInfo.createIfNotExistByIdentifier(ownershipInfo);
119
+ createdOwnershipInfos = yield Promise.all(creatingOwnershipInfos.map((creatingOwnershipInfo) => __awaiter(this, void 0, void 0, function* () {
120
+ const { id } = yield repos.ownershipInfo.createIfNotExistByIdentifier(creatingOwnershipInfo);
121
+ return Object.assign({ id }, (typeof creatingOwnershipInfo.identifier === 'string')
122
+ ? { identifier: creatingOwnershipInfo.identifier }
123
+ : undefined);
120
124
  })));
121
125
  }
122
126
  // const deliveredCount = limit * page;
@@ -140,7 +144,7 @@ function sendOrder(params) {
140
144
  }
141
145
  throw error;
142
146
  }
143
- const result = ownershipInfos;
147
+ const result = createdOwnershipInfos;
144
148
  yield repos.action.completeWithVoid({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
145
149
  debug('allOffersDelivered?:', allOffersDelivered, order.orderNumber);
146
150
  if (params.useOnOrderStatusChanged) {
@@ -70,7 +70,7 @@ function onAuthorizationCreated(params) {
70
70
  // 所有権検索
71
71
  const ownershipInfoId = authorization.object.id;
72
72
  if (typeof ownershipInfoId === 'string' && ownershipInfoId.length > 0) {
73
- const ownershipInfo = yield repos.ownershipInfo.findById({ id: ownershipInfoId });
73
+ const ownershipInfo = yield repos.ownershipInfo.projectFieldsById({ id: ownershipInfoId }, ['typeOfGood']);
74
74
  // 座席予約に対する所有権であれば発券
75
75
  if (ownershipInfo.typeOfGood.typeOf === factory.reservationType.EventReservation
76
76
  || ownershipInfo.typeOfGood.typeOf === factory.reservationType.BusReservation) {
@@ -41,7 +41,7 @@ export declare function validatePaymentMethods(params: {
41
41
  * 興行オファー適用条件確認
42
42
  */
43
43
  export declare function validateEventOffers(params: {
44
- order: factory.transaction.placeOrder.IOrderAsResult;
44
+ order: Pick<factory.transaction.placeOrder.IOrderAsResult, 'price'>;
45
45
  paymentMethods: factory.order.IReferencedInvoice[];
46
46
  authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'instrument' | 'object' | 'result'>[];
47
47
  }): void;
@@ -350,11 +350,12 @@ exports.validatePaymentMethods = validatePaymentMethods;
350
350
  // tslint:disable-next-line:max-func-body-length
351
351
  function validateEventOffers(params) {
352
352
  var _a, _b;
353
- const firstCreditCardPaymentMethodIdentifier = (_b = (_a = params.paymentMethods.find((referenceInvoice) => {
353
+ const { paymentMethods } = params;
354
+ const firstCreditCardPaymentMethodIdentifier = (_b = (_a = paymentMethods.find((referenceInvoice) => {
354
355
  return referenceInvoice.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.CreditCard
355
356
  || referenceInvoice.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.FaceToFace;
356
357
  })) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier;
357
- const numCreditCardOrFaceToFacePaymentMethod = params.paymentMethods.filter((referenceInvoice) => {
358
+ const numCreditCardOrFaceToFacePaymentMethod = paymentMethods.filter((referenceInvoice) => {
358
359
  return referenceInvoice.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.CreditCard
359
360
  || referenceInvoice.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.FaceToFace;
360
361
  }).length;
@@ -411,5 +412,38 @@ function validateEventOffers(params) {
411
412
  });
412
413
  }
413
414
  });
415
+ // check programMembershipUsed(2024-08-15~)
416
+ const programMembershipRequired = params.authorizeEventServiceOfferActions.reduce((a, b) => {
417
+ var _a, _b;
418
+ const programMembershipUsedfromResult = (_b = (_a = b.result) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.serviceOutput.programMembershipUsed;
419
+ if (Array.isArray(programMembershipUsedfromResult)) {
420
+ a.push(...programMembershipUsedfromResult);
421
+ }
422
+ return a;
423
+ }, []);
424
+ const satisfyProgramMembershipRequirement = programMembershipRequired.every(({ identifier, issuedThrough }) => {
425
+ let satisfyThisRequirement = false;
426
+ switch (issuedThrough.typeOf) {
427
+ case factory.product.ProductType.MembershipService:
428
+ // 検証の必要なし
429
+ satisfyThisRequirement = true;
430
+ break;
431
+ case factory.service.paymentService.PaymentServiceType.CreditCard:
432
+ satisfyThisRequirement = paymentMethods.some((paymentMethod) => paymentMethod.paymentMethodId === identifier
433
+ && paymentMethod.issuedThrough.id === issuedThrough.id
434
+ && paymentMethod.issuedThrough.typeOf === issuedThrough.typeOf);
435
+ break;
436
+ case factory.service.paymentService.PaymentServiceType.FaceToFace:
437
+ satisfyThisRequirement = paymentMethods.some((paymentMethod) => paymentMethod.paymentMethodId === identifier
438
+ && paymentMethod.issuedThrough.typeOf === issuedThrough.typeOf);
439
+ break;
440
+ default:
441
+ // no op
442
+ }
443
+ return satisfyThisRequirement;
444
+ });
445
+ if (!satisfyProgramMembershipRequirement) {
446
+ throw new factory.errors.Argument('Transaction', `programMembershipUsed requirement not satisfied`);
447
+ }
414
448
  }
415
449
  exports.validateEventOffers = validateEventOffers;
@@ -293,7 +293,7 @@ function createResult(params, options) {
293
293
  price
294
294
  });
295
295
  (0, validation_1.validateEventOffers)({
296
- order: orderAsResult,
296
+ order: { price },
297
297
  paymentMethods,
298
298
  authorizeEventServiceOfferActions: params.authorizeEventServiceOfferActions
299
299
  });
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.381.0-alpha.3",
13
- "@cinerino/sdk": "10.5.0-alpha.0",
12
+ "@chevre/factory": "4.381.0-alpha.5",
13
+ "@cinerino/sdk": "10.5.0-alpha.1",
14
14
  "@motionpicture/coa-service": "9.4.0",
15
15
  "@motionpicture/gmo-service": "5.3.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "22.2.0-alpha.3"
113
+ "version": "22.2.0-alpha.5"
114
114
  }