@chevre/domain 22.2.0-alpha.2 → 22.2.0-alpha.21

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.
Files changed (86) hide show
  1. package/example/src/chevre/findValidAuthorization.ts +1 -2
  2. package/example/src/chevre/playAroundTicket.ts +3 -2
  3. package/example/src/chevre/{projectReservationFields.ts → projectFields.ts} +10 -8
  4. package/example/src/chevre/{projectReservationFieldsById.ts → projectOwnershipInfoFieldsById.ts} +4 -4
  5. package/example/src/chevre/searchProjects.ts +9 -4
  6. package/example/src/chevre/searchSellersByAggregate.ts +3 -3
  7. package/example/src/chevre/unsetUnnecessaryFields.ts +4 -30
  8. package/lib/chevre/repo/authorization.d.ts +3 -1
  9. package/lib/chevre/repo/authorization.js +21 -10
  10. package/lib/chevre/repo/categoryCode.d.ts +14 -2
  11. package/lib/chevre/repo/categoryCode.js +41 -19
  12. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +1 -1
  13. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +21 -23
  14. package/lib/chevre/repo/mongoose/schemas/paymentService.js +12 -3
  15. package/lib/chevre/repo/mongoose/schemas/product.js +5 -12
  16. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +1 -1
  17. package/lib/chevre/repo/mongoose/schemas/seller.js +21 -23
  18. package/lib/chevre/repo/ownershipInfo.d.ts +10 -6
  19. package/lib/chevre/repo/ownershipInfo.js +75 -19
  20. package/lib/chevre/repo/paymentService.d.ts +2 -2
  21. package/lib/chevre/repo/paymentService.js +108 -58
  22. package/lib/chevre/repo/paymentServiceProvider.d.ts +1 -10
  23. package/lib/chevre/repo/product.d.ts +2 -2
  24. package/lib/chevre/repo/product.js +67 -33
  25. package/lib/chevre/repo/project.d.ts +4 -4
  26. package/lib/chevre/repo/project.js +69 -28
  27. package/lib/chevre/repo/seller.d.ts +10 -12
  28. package/lib/chevre/repo/seller.js +61 -27
  29. package/lib/chevre/repo/ticket.d.ts +3 -2
  30. package/lib/chevre/repo/ticket.js +23 -10
  31. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +1 -1
  32. package/lib/chevre/service/aggregation/event/findEventOffers.js +1 -1
  33. package/lib/chevre/service/aggregation/project.js +1 -1
  34. package/lib/chevre/service/assetTransaction/cancelReservation.js +2 -2
  35. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  36. package/lib/chevre/service/assetTransaction/pay/factory.d.ts +1 -1
  37. package/lib/chevre/service/assetTransaction/pay/factory.js +1 -1
  38. package/lib/chevre/service/assetTransaction/pay.js +3 -3
  39. package/lib/chevre/service/assetTransaction/refund/factory.d.ts +1 -1
  40. package/lib/chevre/service/assetTransaction/refund/factory.js +1 -1
  41. package/lib/chevre/service/assetTransaction/refund.js +3 -3
  42. package/lib/chevre/service/assetTransaction/registerService.js +4 -6
  43. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +26 -23
  44. package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.js +4 -1
  45. package/lib/chevre/service/assetTransaction/reserve/start.js +1 -3
  46. package/lib/chevre/service/code.d.ts +0 -4
  47. package/lib/chevre/service/code.js +21 -17
  48. package/lib/chevre/service/event.js +3 -3
  49. package/lib/chevre/service/moneyTransfer.js +2 -4
  50. package/lib/chevre/service/notification.js +1 -1
  51. package/lib/chevre/service/offer/event/authorize/factory.js +34 -6
  52. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.d.ts +0 -2
  53. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +22 -22
  54. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +0 -2
  55. package/lib/chevre/service/offer/event/authorize.d.ts +0 -2
  56. package/lib/chevre/service/offer/event/importFromCOA/factory.d.ts +3 -1
  57. package/lib/chevre/service/offer/event/importFromCOA.js +2 -2
  58. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +4 -12
  59. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -3
  60. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +3 -3
  61. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -3
  62. package/lib/chevre/service/offer/product.d.ts +1 -1
  63. package/lib/chevre/service/offer/product.js +4 -6
  64. package/lib/chevre/service/order/sendOrder.js +9 -5
  65. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.d.ts +1 -6
  66. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +26 -34
  67. package/lib/chevre/service/payment/any.d.ts +3 -3
  68. package/lib/chevre/service/payment/any.js +15 -7
  69. package/lib/chevre/service/payment/paymentCard.js +1 -3
  70. package/lib/chevre/service/report/ownershipInfo.d.ts +3 -1
  71. package/lib/chevre/service/task/authorizePayment.js +0 -2
  72. package/lib/chevre/service/task/onAuthorizationCreated.js +20 -16
  73. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +2 -2
  74. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +1 -1
  75. package/lib/chevre/service/task/onResourceUpdated.js +2 -2
  76. package/lib/chevre/service/task/publishPaymentUrl.js +4 -0
  77. package/lib/chevre/service/transaction/moneyTransfer.js +1 -1
  78. package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +1 -1
  79. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +36 -2
  80. package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
  81. package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.d.ts +2 -2
  82. package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +1 -1
  83. package/lib/chevre/service/transaction/returnOrder/preStart.d.ts +2 -2
  84. package/lib/chevre/service/transaction/returnOrder/preStart.js +1 -1
  85. package/package.json +3 -3
  86. package/example/src/chevre/searchProducts.ts +0 -28
@@ -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,36 +257,76 @@ 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 };
267
273
  });
268
274
  }
269
- findById(params, projection) {
275
+ projectFieldsById(params, inclusion) {
270
276
  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))
277
+ let projection = {
278
+ _id: 0,
279
+ id: { $toString: '$_id' },
280
+ project: 1,
281
+ typeOf: 1,
282
+ identifier: 1,
283
+ ownedBy: 1,
284
+ acquiredFrom: 1,
285
+ ownedFrom: 1,
286
+ ownedThrough: 1,
287
+ typeOfGood: 1
288
+ };
289
+ const positiveProjectionFields = (Array.isArray(inclusion))
290
+ ? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
291
+ : undefined;
292
+ if (Array.isArray(positiveProjectionFields)) {
293
+ projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
294
+ }
295
+ const doc = yield this.ownershipInfoModel.findOne({ _id: { $eq: params.id } }, projection)
296
+ .lean() // lean(2024-08-15~)
272
297
  .exec();
273
298
  if (doc === null) {
274
299
  throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
275
300
  }
276
- return doc.toObject();
301
+ return doc;
277
302
  });
278
303
  }
279
304
  /**
280
305
  * 所有権を検索する
281
306
  */
282
- search(params, projection) {
307
+ projectFields(params, inclusion) {
283
308
  var _a;
284
309
  return __awaiter(this, void 0, void 0, function* () {
285
310
  const conditions = OwnershipInfoRepo.CREATE_MONGO_CONDITIONS(params);
286
- const query = this.ownershipInfoModel.find((conditions.length > 0) ? { $and: conditions } : {}, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
311
+ let projection = {
312
+ _id: 0,
313
+ id: { $toString: '$_id' },
314
+ project: 1,
315
+ typeOf: 1,
316
+ identifier: 1,
317
+ ownedBy: 1,
318
+ acquiredFrom: 1,
319
+ ownedFrom: 1,
320
+ ownedThrough: 1,
321
+ typeOfGood: 1
322
+ };
323
+ const positiveProjectionFields = (Array.isArray(inclusion))
324
+ ? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
325
+ : undefined;
326
+ if (Array.isArray(positiveProjectionFields)) {
327
+ projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
328
+ }
329
+ const query = this.ownershipInfoModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
287
330
  if (typeof params.limit === 'number' && params.limit > 0) {
288
331
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
289
332
  query.limit(params.limit)
@@ -295,8 +338,8 @@ class OwnershipInfoRepo {
295
338
  query.sort({ ownedFrom: params.sort.ownedFrom });
296
339
  }
297
340
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
298
- .exec()
299
- .then((docs) => docs.map((doc) => doc.toObject()));
341
+ .lean() // lean(2024-08-19~)
342
+ .exec();
300
343
  });
301
344
  }
302
345
  /**
@@ -308,8 +351,15 @@ class OwnershipInfoRepo {
308
351
  return this.ownershipInfoModel.findOneAndUpdate({
309
352
  'project.id': { $eq: params.project.id },
310
353
  identifier: { $eq: String(params.identifier) }
311
- }, { ownedThrough: params.ownedThrough }, { new: true })
312
- .select({ __v: 0, createdAt: 0, updatedAt: 0 })
354
+ }, { ownedThrough: params.ownedThrough }, {
355
+ new: true,
356
+ projection: {
357
+ _id: 0,
358
+ id: { $toString: '$_id' },
359
+ identifier: 1
360
+ }
361
+ })
362
+ .lean()
313
363
  .exec()
314
364
  .then((doc) => {
315
365
  // 存在しない場合も正常にハンドルする
@@ -317,7 +367,7 @@ class OwnershipInfoRepo {
317
367
  return;
318
368
  }
319
369
  else {
320
- return doc.toObject();
370
+ return doc;
321
371
  }
322
372
  });
323
373
  });
@@ -404,7 +454,10 @@ class OwnershipInfoRepo {
404
454
  };
405
455
  }
406
456
  if (newOwner !== undefined) {
407
- const doc = yield this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $addToSet: { ownedBy: newOwner } }, { new: true })
457
+ const doc = yield this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $addToSet: { ownedBy: newOwner } }, {
458
+ new: true,
459
+ projection: { _id: 1 }
460
+ })
408
461
  .exec();
409
462
  if (doc === null) {
410
463
  throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
@@ -420,7 +473,10 @@ class OwnershipInfoRepo {
420
473
  if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
421
474
  throw new factory.errors.ArgumentNull('ownedBy.id');
422
475
  }
423
- const doc = yield this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $pull: { ownedBy: { id: params.ownedBy.id } } }, { new: true })
476
+ const doc = yield this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $pull: { ownedBy: { id: params.ownedBy.id } } }, {
477
+ new: true,
478
+ projection: { _id: 1 }
479
+ })
424
480
  .exec();
425
481
  if (doc === null) {
426
482
  throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
@@ -1,7 +1,7 @@
1
1
  import type { Connection, FilterQuery } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  type IUnsetKey = keyof Pick<factory.service.paymentService.IService, 'additionalProperty' | 'availableChannel' | 'serviceOutput' | 'serviceType'>;
4
- type IKeyOfProjection4paymentService = keyof factory.service.paymentService.IService | '_id';
4
+ type IKeyOfProjection4paymentService = keyof factory.service.paymentService.IService;
5
5
  /**
6
6
  * 決済サービス検索条件
7
7
  */
@@ -37,7 +37,7 @@ export declare class PaymentServiceRepo {
37
37
  /**
38
38
  * 決済サービスを検索する
39
39
  */
40
- searchPaymentServices(conditions: ISearchConditions4paymentService, inclusion: IKeyOfProjection4paymentService[], exclusion: IKeyOfProjection4paymentService[]): Promise<(factory.service.paymentService.IService & {
40
+ projectFields(conditions: ISearchConditions4paymentService, inclusion: IKeyOfProjection4paymentService[], exclusion: IKeyOfProjection4paymentService[]): Promise<(factory.service.paymentService.IService & {
41
41
  id: string;
42
42
  })[]>;
43
43
  deletePaymentServiceById(params: {
@@ -24,6 +24,17 @@ exports.PaymentServiceRepo = void 0;
24
24
  const factory = require("../factory");
25
25
  const settings_1 = require("../settings");
26
26
  const paymentService_1 = require("./mongoose/schemas/paymentService");
27
+ const AVAILABLE_PROJECT_FIELDS = [
28
+ 'project',
29
+ 'typeOf',
30
+ 'additionalProperty',
31
+ 'availableChannel',
32
+ 'description',
33
+ 'name',
34
+ 'productID',
35
+ 'serviceOutput',
36
+ 'serviceType'
37
+ ];
27
38
  /**
28
39
  * 決済サービスリポジトリ
29
40
  */
@@ -33,7 +44,7 @@ class PaymentServiceRepo {
33
44
  }
34
45
  // tslint:disable-next-line:max-func-body-length
35
46
  static CREATE_MONGO_CONDITIONS(params) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
47
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
37
48
  // MongoDB検索条件
38
49
  const andConditions = [];
39
50
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -54,68 +65,80 @@ class PaymentServiceRepo {
54
65
  typeOf: { $in: typeOfIn }
55
66
  });
56
67
  }
57
- const hasOfferCatalogIdEq = (_f = (_e = params.hasOfferCatalog) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
58
- if (typeof hasOfferCatalogIdEq === 'string') {
59
- andConditions.push({
60
- 'hasOfferCatalog.id': {
61
- $exists: true,
62
- $eq: hasOfferCatalogIdEq
63
- }
64
- });
65
- }
66
- const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
68
+ // discontinue(2024-08-20~)
69
+ // const hasOfferCatalogIdEq = params.hasOfferCatalog?.id?.$eq;
70
+ // if (typeof hasOfferCatalogIdEq === 'string') {
71
+ // andConditions.push({
72
+ // 'hasOfferCatalog.id': {
73
+ // $exists: true,
74
+ // $eq: hasOfferCatalogIdEq
75
+ // }
76
+ // });
77
+ // }
78
+ const idEq = (_e = params.id) === null || _e === void 0 ? void 0 : _e.$eq;
67
79
  if (typeof idEq === 'string') {
68
80
  andConditions.push({ _id: { $eq: idEq } });
69
81
  }
70
- const idIn = (_h = params.id) === null || _h === void 0 ? void 0 : _h.$in;
82
+ const idIn = (_f = params.id) === null || _f === void 0 ? void 0 : _f.$in;
71
83
  if (Array.isArray(idIn)) {
72
84
  andConditions.push({ _id: { $in: idIn } });
73
85
  }
74
- const productIDEq = (_j = params.productID) === null || _j === void 0 ? void 0 : _j.$eq;
86
+ const productIDEq = (_g = params.productID) === null || _g === void 0 ? void 0 : _g.$eq;
75
87
  if (typeof productIDEq === 'string') {
76
88
  andConditions.push({
77
89
  productID: { $eq: productIDEq }
78
90
  });
79
91
  }
80
- const productIDIn = (_k = params.productID) === null || _k === void 0 ? void 0 : _k.$in;
92
+ const productIDIn = (_h = params.productID) === null || _h === void 0 ? void 0 : _h.$in;
81
93
  if (Array.isArray(productIDIn)) {
82
94
  andConditions.push({
83
95
  productID: { $in: productIDIn }
84
96
  });
85
97
  }
86
- const productIDRegex = (_l = params.productID) === null || _l === void 0 ? void 0 : _l.$regex;
98
+ const productIDRegex = (_j = params.productID) === null || _j === void 0 ? void 0 : _j.$regex;
87
99
  if (typeof productIDRegex === 'string' && productIDRegex.length > 0) {
88
100
  andConditions.push({
89
101
  productID: { $regex: new RegExp(productIDRegex) }
90
102
  });
91
103
  }
92
- const offersElemMatch = (_m = params.offers) === null || _m === void 0 ? void 0 : _m.$elemMatch;
93
- if (offersElemMatch !== undefined && offersElemMatch !== null) {
104
+ // discontinue(2024-08-20~)
105
+ // const offersElemMatch = params.offers?.$elemMatch;
106
+ // if (offersElemMatch !== undefined && offersElemMatch !== null) {
107
+ // andConditions.push({
108
+ // offers: {
109
+ // $elemMatch: offersElemMatch
110
+ // }
111
+ // });
112
+ // }
113
+ const serviceOutputTypeOfEq = (_l = (_k = params.serviceOutput) === null || _k === void 0 ? void 0 : _k.typeOf) === null || _l === void 0 ? void 0 : _l.$eq;
114
+ if (typeof serviceOutputTypeOfEq === 'string') {
94
115
  andConditions.push({
95
- offers: {
96
- $elemMatch: offersElemMatch
116
+ 'serviceOutput.typeOf': {
117
+ $exists: true,
118
+ $eq: serviceOutputTypeOfEq
97
119
  }
98
120
  });
99
121
  }
100
- const serviceOutputTypeOfEq = (_p = (_o = params.serviceOutput) === null || _o === void 0 ? void 0 : _o.typeOf) === null || _p === void 0 ? void 0 : _p.$eq;
101
- if (typeof serviceOutputTypeOfEq === 'string') {
122
+ const serviceOutputPaymentMethodAmountCurrencyEq = (_q = (_p = (_o = (_m = params.serviceOutput) === null || _m === void 0 ? void 0 : _m.paymentMethod) === null || _o === void 0 ? void 0 : _o.amount) === null || _p === void 0 ? void 0 : _p.currency) === null || _q === void 0 ? void 0 : _q.$eq;
123
+ if (typeof serviceOutputPaymentMethodAmountCurrencyEq === 'string') {
102
124
  andConditions.push({
103
- 'serviceOutput.typeOf': {
125
+ 'serviceOutput.paymentMethod.amount.currency': {
104
126
  $exists: true,
105
- $eq: serviceOutputTypeOfEq
127
+ $eq: serviceOutputPaymentMethodAmountCurrencyEq
106
128
  }
107
129
  });
108
130
  }
109
- const serviceOutputAmountCurrencyEq = (_s = (_r = (_q = params.serviceOutput) === null || _q === void 0 ? void 0 : _q.amount) === null || _r === void 0 ? void 0 : _r.currency) === null || _s === void 0 ? void 0 : _s.$eq;
110
- if (typeof serviceOutputAmountCurrencyEq === 'string') {
131
+ // extend(2024-08-20~)
132
+ const serviceOutputIssuedThroughServiceTypeCodeValueEq = (_u = (_t = (_s = (_r = params.serviceOutput) === null || _r === void 0 ? void 0 : _r.issuedThrough) === null || _s === void 0 ? void 0 : _s.serviceType) === null || _t === void 0 ? void 0 : _t.codeValue) === null || _u === void 0 ? void 0 : _u.$eq;
133
+ if (typeof serviceOutputIssuedThroughServiceTypeCodeValueEq === 'string') {
111
134
  andConditions.push({
112
- 'serviceOutput.amount.currency': {
135
+ 'serviceOutput.issuedThrough.serviceType.codeValue': {
113
136
  $exists: true,
114
- $eq: serviceOutputAmountCurrencyEq
137
+ $eq: serviceOutputIssuedThroughServiceTypeCodeValueEq
115
138
  }
116
139
  });
117
140
  }
118
- const serviceTypeCodeValueEq = (_u = (_t = params.serviceType) === null || _t === void 0 ? void 0 : _t.codeValue) === null || _u === void 0 ? void 0 : _u.$eq;
141
+ const serviceTypeCodeValueEq = (_w = (_v = params.serviceType) === null || _v === void 0 ? void 0 : _v.codeValue) === null || _w === void 0 ? void 0 : _w.$eq;
119
142
  if (typeof serviceTypeCodeValueEq === 'string') {
120
143
  andConditions.push({
121
144
  'serviceType.codeValue': {
@@ -124,7 +147,7 @@ class PaymentServiceRepo {
124
147
  }
125
148
  });
126
149
  }
127
- const nameRegex = (_v = params.name) === null || _v === void 0 ? void 0 : _v.$regex;
150
+ const nameRegex = (_x = params.name) === null || _x === void 0 ? void 0 : _x.$regex;
128
151
  if (typeof nameRegex === 'string' && nameRegex.length > 0) {
129
152
  const nameRegexExp = new RegExp(nameRegex);
130
153
  andConditions.push({
@@ -145,7 +168,7 @@ class PaymentServiceRepo {
145
168
  });
146
169
  }
147
170
  // プロバイダー条件を追加(2023-06-21~)
148
- const providerIdEq = (_x = (_w = params.provider) === null || _w === void 0 ? void 0 : _w.id) === null || _x === void 0 ? void 0 : _x.$eq;
171
+ const providerIdEq = (_z = (_y = params.provider) === null || _y === void 0 ? void 0 : _y.id) === null || _z === void 0 ? void 0 : _z.$eq;
149
172
  if (typeof providerIdEq === 'string') {
150
173
  andConditions.push({ 'provider.id': { $exists: true, $eq: providerIdEq } });
151
174
  }
@@ -155,70 +178,97 @@ class PaymentServiceRepo {
155
178
  * 決済サービスを保管する
156
179
  */
157
180
  savePaymentService(params) {
181
+ var _a, _b;
158
182
  return __awaiter(this, void 0, void 0, function* () {
159
183
  let doc;
184
+ let savedId;
160
185
  if (typeof params.id === 'string') {
161
186
  // 上書き禁止属性を除外
162
- const _a = params.$set, { id, productID, project, typeOf, provider } = _a, setFields = __rest(_a, ["id", "productID", "project", "typeOf", "provider"]);
187
+ const _c = params.$set, { id, productID, project, typeOf, provider } = _c, setFields = __rest(_c, ["id", "productID", "project", "typeOf", "provider"]);
163
188
  switch (typeOf) {
164
189
  case factory.service.paymentService.PaymentServiceType.CreditCard:
165
190
  case factory.service.paymentService.PaymentServiceType.MovieTicket:
166
191
  doc = yield this.paymentServiceModel.findOneAndUpdate({
167
192
  _id: { $eq: params.id },
168
193
  typeOf: { $eq: typeOf }
169
- }, { $set: setFields }, { upsert: false, new: true, projection: { _id: 1 } })
194
+ }, {
195
+ $set: setFields,
196
+ $unset: params.$unset
197
+ }, { upsert: false, new: true, projection: { _id: 1, id: { $toString: '$_id' } } })
198
+ .lean()
170
199
  .exec();
200
+ if (doc === null) {
201
+ throw new factory.errors.NotFound(this.paymentServiceModel.modelName);
202
+ }
171
203
  break;
172
204
  default:
173
205
  throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
174
206
  }
207
+ savedId = params.id;
175
208
  }
176
209
  else {
177
- const _b = params.$set, { id } = _b, createParams = __rest(_b, ["id"]);
210
+ const _d = params.$set, { id } = _d, createParams = __rest(_d, ["id"]);
178
211
  if (params.createIfNotExist === true) {
179
212
  doc = yield this.paymentServiceModel.findOneAndUpdate({
180
213
  'project.id': { $eq: createParams.project.id },
181
214
  typeOf: { $eq: createParams.typeOf }
182
- }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1 } })
215
+ }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1, id: { $toString: '$_id' } } })
216
+ .lean()
183
217
  .exec();
218
+ if (doc === null) {
219
+ throw new factory.errors.NotFound(this.paymentServiceModel.modelName);
220
+ }
221
+ savedId = doc.id;
184
222
  }
185
223
  else {
186
- doc = yield this.paymentServiceModel.create(createParams);
224
+ // doc = await this.paymentServiceModel.create(createParams);
225
+ const result = yield this.paymentServiceModel.insertMany(createParams, { rawResult: true });
226
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
227
+ if (typeof insertedId !== 'string') {
228
+ throw new factory.errors.Internal(`paymentService not saved unexpectedly. result:${JSON.stringify(result)}`);
229
+ }
230
+ savedId = insertedId;
187
231
  }
188
232
  }
189
- if (doc === null) {
190
- throw new factory.errors.NotFound(this.paymentServiceModel.modelName);
191
- }
192
- return doc.toObject();
233
+ return { id: savedId };
193
234
  });
194
235
  }
195
236
  /**
196
237
  * 決済サービスを検索する
197
238
  */
198
- searchPaymentServices(conditions, inclusion, exclusion) {
239
+ projectFields(conditions, inclusion, exclusion) {
199
240
  var _a;
200
241
  return __awaiter(this, void 0, void 0, function* () {
201
242
  const andConditions = PaymentServiceRepo.CREATE_MONGO_CONDITIONS(conditions);
202
- let projection = {};
243
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
203
244
  if (Array.isArray(inclusion) && inclusion.length > 0) {
204
- inclusion.forEach((field) => {
205
- projection[field] = 1;
206
- });
245
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
207
246
  }
208
247
  else {
209
- projection = {
210
- __v: 0,
211
- createdAt: 0,
212
- updatedAt: 0,
213
- offers: 0,
214
- provider: 0 // paymentServiceProviderRepoへの完全移行につき除外(2023-12-20~)
215
- };
216
248
  if (Array.isArray(exclusion) && exclusion.length > 0) {
217
- exclusion.forEach((field) => {
218
- projection[field] = 0;
219
- });
249
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
220
250
  }
221
251
  }
252
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
253
+ // let projection: { [key: string]: number } = {};
254
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
255
+ // inclusion.forEach((field) => {
256
+ // projection[field] = 1;
257
+ // });
258
+ // } else {
259
+ // projection = {
260
+ // __v: 0,
261
+ // createdAt: 0,
262
+ // updatedAt: 0,
263
+ // offers: 0,
264
+ // provider: 0 // paymentServiceProviderRepoへの完全移行につき除外(2023-12-20~)
265
+ // };
266
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
267
+ // exclusion.forEach((field) => {
268
+ // projection[field] = 0;
269
+ // });
270
+ // }
271
+ // }
222
272
  const query = this.paymentServiceModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
223
273
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
224
274
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -231,13 +281,13 @@ class PaymentServiceRepo {
231
281
  query.sort({ productID: conditions.sort.productID });
232
282
  }
233
283
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
234
- .exec()
235
- .then((docs) => docs.map((doc) => doc.toObject()));
284
+ .lean() // 2024-08-20~
285
+ .exec();
236
286
  });
237
287
  }
238
288
  deletePaymentServiceById(params) {
239
289
  return __awaiter(this, void 0, void 0, function* () {
240
- yield this.paymentServiceModel.findOneAndDelete({ _id: params.id })
290
+ yield this.paymentServiceModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
241
291
  .exec();
242
292
  });
243
293
  }
@@ -247,7 +297,7 @@ class PaymentServiceRepo {
247
297
  findAvailableChannel(params) {
248
298
  return __awaiter(this, void 0, void 0, function* () {
249
299
  let paymentService;
250
- paymentService = (yield this.searchPaymentServices({
300
+ paymentService = (yield this.projectFields({
251
301
  limit: 1,
252
302
  page: 1,
253
303
  project: { id: { $eq: params.project.id } },
@@ -1,15 +1,6 @@
1
1
  import { Connection, FilterQuery } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  type IAvailablePaymentServiceType = factory.service.paymentService.PaymentServiceType.CreditCard | factory.service.paymentService.PaymentServiceType.MovieTicket;
4
- /**
5
- * 決済サービス検索条件
6
- */
7
- type ISearchConditions4paymentService = factory.product.ISearchConditions & {
8
- typeOf?: {
9
- $eq?: factory.service.paymentService.PaymentServiceType;
10
- $in?: factory.service.paymentService.PaymentServiceType[];
11
- };
12
- };
13
4
  export type IPublicPaymentServiceByProvider = Pick<factory.service.paymentService.IService, 'name' | 'description' | 'typeOf' | 'id' | 'productID' | 'serviceType' | 'serviceOutput' | 'additionalProperty'> & {
14
5
  provider?: {
15
6
  credentials?: Pick<factory.service.paymentService.IProviderCredentials, 'shopId' | 'paymentUrl' | 'tokenizationCode'>;
@@ -46,7 +37,7 @@ export declare class PaymentServiceProviderRepo {
46
37
  /**
47
38
  * 販売者の提供決済サービス(公開情報のみ)検索
48
39
  */
49
- searchPublicPaymentServicesByProvider(params: Pick<ISearchConditions4paymentService, 'limit' | 'page' | 'sort' | 'project' | 'provider' | 'typeOf'>): Promise<IPublicPaymentServiceByProvider[]>;
40
+ searchPublicPaymentServicesByProvider(params: Pick<factory.service.paymentService.ISearchConditions, 'limit' | 'page' | 'sort' | 'project' | 'provider' | 'typeOf'>): Promise<IPublicPaymentServiceByProvider[]>;
50
41
  create(params: factory.service.paymentService.IProvider & {
51
42
  project: {
52
43
  id: string;
@@ -25,7 +25,7 @@
25
25
  import type { BulkWriteResult } from 'mongodb';
26
26
  import type { Connection, FilterQuery } from 'mongoose';
27
27
  import * as factory from '../factory';
28
- type IKeyOfProjection4product = keyof factory.product.IProduct | '_id';
28
+ type IKeyOfProjection = keyof factory.product.IProduct;
29
29
  /**
30
30
  * プロダクト検索条件
31
31
  */
@@ -41,7 +41,7 @@ export declare class ProductRepo {
41
41
  /**
42
42
  * プロダクトを検索する
43
43
  */
44
- searchProducts(conditions: ISearchConditions4product, inclusion: IKeyOfProjection4product[], exclusion: IKeyOfProjection4product[]): Promise<(factory.product.IProduct & {
44
+ projectFields(conditions: ISearchConditions4product, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<(factory.product.IProduct & {
45
45
  id: string;
46
46
  })[]>;
47
47
  deleteProductById(params: {