@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
@@ -24,6 +24,18 @@ exports.ProductRepo = void 0;
24
24
  const product_1 = require("./mongoose/schemas/product");
25
25
  const factory = require("../factory");
26
26
  const settings_1 = require("../settings");
27
+ const AVAILABLE_PROJECT_FIELDS = [
28
+ 'project',
29
+ 'typeOf',
30
+ 'additionalProperty',
31
+ 'availableChannel',
32
+ 'description',
33
+ 'hasOfferCatalog',
34
+ 'name',
35
+ 'productID',
36
+ 'serviceOutput',
37
+ 'serviceType'
38
+ ];
27
39
  /**
28
40
  * プロダクトリポジトリ
29
41
  */
@@ -33,7 +45,7 @@ class ProductRepo {
33
45
  }
34
46
  // tslint:disable-next-line:max-func-body-length
35
47
  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;
48
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
37
49
  // MongoDB検索条件
38
50
  const andConditions = [];
39
51
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -144,38 +156,46 @@ class ProductRepo {
144
156
  ]
145
157
  });
146
158
  }
147
- // プロバイダー条件を追加(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;
149
- if (typeof providerIdEq === 'string') {
150
- andConditions.push({ 'provider.id': { $exists: true, $eq: providerIdEq } });
151
- }
159
+ // const providerIdEq = params.provider?.id?.$eq;
160
+ // if (typeof providerIdEq === 'string') {
161
+ // andConditions.push({ 'provider.id': { $exists: true, $eq: providerIdEq } });
162
+ // }
152
163
  return andConditions;
153
164
  }
154
165
  /**
155
166
  * プロダクトを検索する
156
167
  */
157
- searchProducts(conditions, inclusion, exclusion) {
168
+ projectFields(conditions, inclusion, exclusion) {
158
169
  var _a;
159
170
  return __awaiter(this, void 0, void 0, function* () {
160
171
  const andConditions = ProductRepo.CREATE_MONGO_CONDITIONS(conditions);
161
- let projection = {};
172
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
162
173
  if (Array.isArray(inclusion) && inclusion.length > 0) {
163
- inclusion.forEach((field) => {
164
- projection[field] = 1;
165
- });
174
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
166
175
  }
167
176
  else {
168
- projection = {
169
- __v: 0,
170
- createdAt: 0,
171
- updatedAt: 0
172
- };
173
177
  if (Array.isArray(exclusion) && exclusion.length > 0) {
174
- exclusion.forEach((field) => {
175
- projection[field] = 0;
176
- });
178
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
177
179
  }
178
180
  }
181
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
182
+ // let projection: { [key: string]: number } = {};
183
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
184
+ // inclusion.forEach((field) => {
185
+ // projection[field] = 1;
186
+ // });
187
+ // } else {
188
+ // projection = {
189
+ // __v: 0,
190
+ // createdAt: 0,
191
+ // updatedAt: 0
192
+ // };
193
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
194
+ // exclusion.forEach((field) => {
195
+ // projection[field] = 0;
196
+ // });
197
+ // }
198
+ // }
179
199
  const query = this.productModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
180
200
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
181
201
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -188,13 +208,13 @@ class ProductRepo {
188
208
  query.sort({ productID: conditions.sort.productID });
189
209
  }
190
210
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
191
- .exec()
192
- .then((docs) => docs.map((doc) => doc.toObject()));
211
+ .lean() // 2024-08-20~
212
+ .exec();
193
213
  });
194
214
  }
195
215
  deleteProductById(params) {
196
216
  return __awaiter(this, void 0, void 0, function* () {
197
- yield this.productModel.findOneAndDelete({ _id: params.id })
217
+ yield this.productModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
198
218
  .exec();
199
219
  });
200
220
  }
@@ -202,11 +222,13 @@ class ProductRepo {
202
222
  * プロダクトを保管する
203
223
  */
204
224
  saveProduct(params) {
225
+ var _a, _b;
205
226
  return __awaiter(this, void 0, void 0, function* () {
206
227
  let doc;
228
+ let savedId;
207
229
  if (typeof params.id === 'string') {
208
230
  // 上書き禁止属性を除外
209
- const _a = params.$set, { id, productID, project, typeOf, offers } = _a, setFields = __rest(_a, ["id", "productID", "project", "typeOf", "offers"]);
231
+ const _c = params.$set, { id, productID, project, typeOf, offers } = _c, setFields = __rest(_c, ["id", "productID", "project", "typeOf", "offers"]);
210
232
  switch (typeOf) {
211
233
  case factory.product.ProductType.EventService:
212
234
  case factory.product.ProductType.MembershipService:
@@ -219,30 +241,43 @@ class ProductRepo {
219
241
  }, {
220
242
  $set: setFields,
221
243
  $unset: params.$unset
222
- }, { upsert: false, new: true, projection: { _id: 1 } })
244
+ }, { upsert: false, new: true, projection: { _id: 1, id: { $toString: '$_id' } } })
245
+ .lean()
223
246
  .exec();
247
+ if (doc === null) {
248
+ throw new factory.errors.NotFound(this.productModel.modelName);
249
+ }
224
250
  break;
225
251
  default:
226
252
  throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
227
253
  }
254
+ savedId = params.id;
228
255
  }
229
256
  else {
230
- const _b = params.$set, { id } = _b, createParams = __rest(_b, ["id"]);
257
+ const _d = params.$set, { id } = _d, createParams = __rest(_d, ["id"]);
231
258
  if (params.createIfNotExist === true) {
232
259
  doc = yield this.productModel.findOneAndUpdate({
233
260
  'project.id': { $eq: createParams.project.id },
234
261
  typeOf: { $eq: createParams.typeOf }
235
- }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1 } })
262
+ }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1, id: { $toString: '$_id' } } })
263
+ .lean()
236
264
  .exec();
265
+ if (doc === null) {
266
+ throw new factory.errors.NotFound(this.productModel.modelName);
267
+ }
268
+ savedId = doc.id;
237
269
  }
238
270
  else {
239
- doc = yield this.productModel.create(createParams);
271
+ // doc = await this.productModel.create(createParams);
272
+ const result = yield this.productModel.insertMany(createParams, { rawResult: true });
273
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
274
+ if (typeof insertedId !== 'string') {
275
+ throw new factory.errors.Internal(`product not saved unexpectedly. result:${JSON.stringify(result)}`);
276
+ }
277
+ savedId = insertedId;
240
278
  }
241
279
  }
242
- if (doc === null) {
243
- throw new factory.errors.NotFound(this.productModel.modelName);
244
- }
245
- return doc.toObject();
280
+ return { id: savedId };
246
281
  });
247
282
  }
248
283
  /**
@@ -297,8 +332,7 @@ class ProductRepo {
297
332
  */
298
333
  findAvailableChannel(params) {
299
334
  return __awaiter(this, void 0, void 0, function* () {
300
- let paymentService;
301
- paymentService = (yield this.searchProducts({
335
+ const paymentService = (yield this.projectFields({
302
336
  limit: 1,
303
337
  page: 1,
304
338
  project: { id: { $eq: params.project.id } },
@@ -24,7 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import type { Connection, FilterQuery } from 'mongoose';
26
26
  import * as factory from '../factory';
27
- type IKeyOfProjection = keyof factory.project.IProject | '_id';
27
+ type IKeyOfProjection = keyof factory.project.IProject;
28
28
  /**
29
29
  * プロジェクトリポジトリ
30
30
  * makesOfferについてはsee ProjectMakesOfferRepo
@@ -44,9 +44,9 @@ export declare class ProjectRepo {
44
44
  /**
45
45
  * プロジェクト検索
46
46
  */
47
- search(conditions: factory.project.ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<factory.project.IProject[]>;
48
- createById(params: factory.project.IProject): Promise<factory.project.IProject>;
49
- findByIdAndIUpdate(params: {
47
+ projectFields(conditions: factory.project.ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<factory.project.IProject[]>;
48
+ createById(params: factory.project.IProject): Promise<Pick<factory.project.IProject, 'id'>>;
49
+ updateById(params: {
50
50
  id: string;
51
51
  alternateName?: string;
52
52
  logo?: string;
@@ -8,11 +8,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.ProjectRepo = void 0;
13
24
  const project_1 = require("./mongoose/schemas/project");
14
25
  const factory = require("../factory");
15
26
  const settings_1 = require("../settings");
27
+ const AVAILABLE_PROJECT_FIELDS = [
28
+ // 'aggregateReservation',
29
+ 'alternateName',
30
+ 'logo',
31
+ 'hasMerchantReturnPolicy',
32
+ // 'makesOffer',
33
+ 'name',
34
+ 'settings',
35
+ 'subscription',
36
+ 'typeOf'
37
+ ];
16
38
  /**
17
39
  * プロジェクトリポジトリ
18
40
  * makesOfferについてはsee ProjectMakesOfferRepo
@@ -43,7 +65,7 @@ class ProjectRepo {
43
65
  }
44
66
  findById(params) {
45
67
  return __awaiter(this, void 0, void 0, function* () {
46
- const project = (yield this.search({
68
+ const project = (yield this.projectFields({
47
69
  limit: 1,
48
70
  page: 1,
49
71
  id: { $eq: params.id }
@@ -56,42 +78,52 @@ class ProjectRepo {
56
78
  }
57
79
  findAlternateNameById(params) {
58
80
  return __awaiter(this, void 0, void 0, function* () {
59
- const doc = yield this.projectModel.findOne({ _id: { $eq: params.id } }, { alternateName: 1 })
81
+ const doc = yield this.projectModel.findOne({ _id: { $eq: params.id } }, { alternateName: 1, _id: 0 })
82
+ .lean()
60
83
  .exec();
61
84
  if (doc === null) {
62
85
  throw new factory.errors.NotFound(this.projectModel.modelName);
63
86
  }
64
- return doc.toObject();
87
+ return doc;
65
88
  });
66
89
  }
67
90
  /**
68
91
  * プロジェクト検索
69
92
  */
70
- search(conditions, inclusion, exclusion) {
93
+ projectFields(conditions, inclusion, exclusion) {
71
94
  var _a;
72
95
  return __awaiter(this, void 0, void 0, function* () {
73
96
  const andConditions = ProjectRepo.CREATE_MONGO_CONDITIONS(conditions);
74
- let projection = {};
97
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
75
98
  if (Array.isArray(inclusion) && inclusion.length > 0) {
76
- inclusion.forEach((field) => {
77
- if (String(field) !== 'makesOffer') {
78
- projection[field] = 1;
79
- }
80
- });
99
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
81
100
  }
82
101
  else {
83
- projection = {
84
- __v: 0,
85
- createdAt: 0,
86
- updatedAt: 0,
87
- makesOffer: 0
88
- };
89
102
  if (Array.isArray(exclusion) && exclusion.length > 0) {
90
- exclusion.forEach((field) => {
91
- projection[field] = 0;
92
- });
103
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
93
104
  }
94
105
  }
106
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
107
+ // let projection: { [key: string]: number } = {};
108
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
109
+ // inclusion.forEach((field) => {
110
+ // if (String(field) !== 'makesOffer') {
111
+ // projection[field] = 1;
112
+ // }
113
+ // });
114
+ // } else {
115
+ // projection = {
116
+ // __v: 0,
117
+ // createdAt: 0,
118
+ // updatedAt: 0,
119
+ // makesOffer: 0
120
+ // };
121
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
122
+ // exclusion.forEach((field) => {
123
+ // projection[field] = 0;
124
+ // });
125
+ // }
126
+ // }
95
127
  const query = this.projectModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
96
128
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
97
129
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -102,17 +134,28 @@ class ProjectRepo {
102
134
  query.sort({ _id: conditions.sort._id });
103
135
  }
104
136
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
105
- .exec()
106
- .then((docs) => docs.map((doc) => doc.toObject()));
137
+ .lean() // 2024-08-22~
138
+ .exec();
107
139
  });
108
140
  }
109
141
  createById(params) {
142
+ var _a, _b;
110
143
  return __awaiter(this, void 0, void 0, function* () {
111
- return this.projectModel.create(Object.assign(Object.assign({}, params), { _id: params.id }))
112
- .then((doc) => doc.toObject());
144
+ // return this.projectModel.create({ ...params, _id: params.id })
145
+ // .then((doc) => doc.toObject());
146
+ const { id } = params, createParams = __rest(params, ["id"]);
147
+ if (typeof id !== 'string' || id === '') {
148
+ throw new factory.errors.ArgumentNull('id');
149
+ }
150
+ const result = yield this.projectModel.insertMany(Object.assign(Object.assign({}, createParams), { typeOf: factory.organizationType.Project, _id: id }), { rawResult: true });
151
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
152
+ if (typeof insertedId !== 'string') {
153
+ throw new factory.errors.Internal(`project not saved unexpectedly. result:${JSON.stringify(result)}`);
154
+ }
155
+ return { id: insertedId };
113
156
  });
114
157
  }
115
- findByIdAndIUpdate(params) {
158
+ updateById(params) {
116
159
  var _a, _b, _c, _d, _e, _f, _g, _h;
117
160
  return __awaiter(this, void 0, void 0, function* () {
118
161
  let hasMerchantReturnPolicy;
@@ -136,7 +179,7 @@ class ProjectRepo {
136
179
  ? { 'subscription.useEventServiceAsProduct': params.subscription.useEventServiceAsProduct }
137
180
  : undefined), (hasMerchantReturnPolicy !== undefined) ? { hasMerchantReturnPolicy } : undefined), { $unset: {
138
181
  'settings.cognito': 1 // 廃止(2023-11-10~)
139
- } }))
182
+ } }), { projection: { _id: 1 } })
140
183
  .exec();
141
184
  });
142
185
  }
@@ -153,9 +196,7 @@ class ProjectRepo {
153
196
  }
154
197
  deleteById(params) {
155
198
  return __awaiter(this, void 0, void 0, function* () {
156
- yield this.projectModel.deleteOne({
157
- _id: { $eq: params.id }
158
- })
199
+ yield this.projectModel.deleteOne({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
159
200
  .exec();
160
201
  });
161
202
  }
@@ -24,17 +24,17 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import { AnyExpression, Connection, FilterQuery, QueryOptions } from 'mongoose';
26
26
  import * as factory from '../factory';
27
- export type ISeller = Omit<factory.seller.ISeller, 'paymentAccepted'>;
28
- export type ISavingSeller = Omit<factory.seller.ISeller, 'paymentAccepted'>;
29
- export interface IUnset {
27
+ export type ISellerWithId = Pick<factory.seller.ISeller, 'additionalProperty' | 'branchCode' | 'hasMerchantReturnPolicy' | 'id' | 'makesOffer' | 'name' | 'project' | 'telephone' | 'typeOf' | 'url'> & {
28
+ id: string;
29
+ };
30
+ type ISavingSeller = Pick<factory.seller.ISeller, 'additionalProperty' | 'branchCode' | 'hasMerchantReturnPolicy' | 'id' | 'makesOffer' | 'name' | 'project' | 'telephone' | 'typeOf' | 'url'>;
31
+ interface IUnset {
30
32
  $unset?: {
31
33
  [key: string]: 1;
32
34
  };
33
35
  }
34
- export type ISellerByAggregate = Pick<ISeller, 'additionalProperty' | 'branchCode' | 'hasMerchantReturnPolicy' | 'id' | 'name' | 'project' | 'telephone' | 'typeOf' | 'url'> & {
35
- id: string;
36
- };
37
- export interface IMemberSearchConditions {
36
+ type ISellerByAggregate = Pick<ISellerWithId, 'additionalProperty' | 'branchCode' | 'hasMerchantReturnPolicy' | 'id' | 'name' | 'project' | 'telephone' | 'typeOf' | 'url'>;
37
+ interface IMemberSearchConditions {
38
38
  /**
39
39
  * 販売者メンバーで絞る場合
40
40
  */
@@ -46,7 +46,7 @@ export interface IMemberSearchConditions {
46
46
  };
47
47
  };
48
48
  }
49
- type IKeyOfProjection = keyof ISeller | '_id';
49
+ type IKeyOfProjection = keyof ISellerWithId;
50
50
  /**
51
51
  * 販売者リポジトリ
52
52
  * 対応決済方法については
@@ -75,9 +75,7 @@ export declare class SellerRepo {
75
75
  /**
76
76
  * 販売者検索
77
77
  */
78
- search(conditions: factory.seller.ISearchConditions & IMemberSearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<(ISeller & {
79
- id: string;
80
- })[]>;
78
+ projectFields(conditions: factory.seller.ISearchConditions & IMemberSearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<ISellerWithId[]>;
81
79
  /**
82
80
  * 販売者を削除する
83
81
  */
@@ -98,7 +96,7 @@ export declare class SellerRepo {
98
96
  addAvailableAtOrFrom(params: {
99
97
  id: string;
100
98
  makesOffer: factory.seller.IMakesOffer;
101
- }): Promise<any>;
99
+ }): Promise<void>;
102
100
  getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<any, QueryOptions<any>>;
103
101
  unsetUnnecessaryFields(params: {
104
102
  filter: any;
@@ -25,6 +25,17 @@ const mongoose_1 = require("mongoose");
25
25
  const seller_1 = require("./mongoose/schemas/seller");
26
26
  const factory = require("../factory");
27
27
  const settings_1 = require("../settings");
28
+ const AVAILABLE_PROJECT_FIELDS = [
29
+ 'additionalProperty',
30
+ 'branchCode',
31
+ 'hasMerchantReturnPolicy',
32
+ 'makesOffer',
33
+ 'name',
34
+ 'project',
35
+ 'typeOf',
36
+ 'url',
37
+ 'telephone'
38
+ ];
28
39
  /**
29
40
  * 販売者リポジトリ
30
41
  * 対応決済方法については
@@ -191,32 +202,46 @@ class SellerRepo {
191
202
  * 販売者を保管する
192
203
  */
193
204
  save(params) {
205
+ var _a, _b;
194
206
  return __awaiter(this, void 0, void 0, function* () {
195
207
  let doc;
208
+ let savedId;
196
209
  const savingId = params.id;
197
210
  if (typeof savingId === 'string') {
198
211
  if (savingId === '') {
199
212
  throw new factory.errors.ArgumentNull('id');
200
213
  }
201
214
  // 上書き禁止属性を除外(2022-08-24~)
202
- const _a = params.attributes, { id, branchCode, project, typeOf, $unset } = _a, updateFields = __rest(_a, ["id", "branchCode", "project", "typeOf", "$unset"]);
215
+ const _c = params.attributes, { id, branchCode, project, typeOf, $unset } = _c, updateFields = __rest(_c, ["id", "branchCode", "project", "typeOf", "$unset"]);
203
216
  const filter = {
204
217
  _id: { $eq: savingId },
205
218
  'project.id': { $eq: project.id }
206
219
  };
207
220
  const update = Object.assign({ $set: updateFields }, ($unset !== undefined && $unset !== null) ? { $unset } : undefined);
208
- const options = { upsert: false, new: true, projection: { _id: 1 } };
221
+ const options = {
222
+ upsert: false,
223
+ new: true,
224
+ projection: { _id: 1, id: { $toString: '$_id' } }
225
+ };
209
226
  doc = yield this.sellerModel.findOneAndUpdate(filter, update, options)
227
+ .lean()
210
228
  .exec();
229
+ if (doc === null) {
230
+ throw new factory.errors.NotFound(this.sellerModel.modelName);
231
+ }
232
+ savedId = savingId;
211
233
  }
212
234
  else {
213
- const _b = params.attributes, { id, $unset } = _b, createParams = __rest(_b, ["id", "$unset"]);
214
- doc = yield this.sellerModel.create(createParams);
215
- }
216
- if (doc === null) {
217
- throw new factory.errors.NotFound(this.sellerModel.modelName);
235
+ const _d = params.attributes, { id, $unset } = _d, createParams = __rest(_d, ["id", "$unset"]);
236
+ // doc = await this.sellerModel.create<ISavingSeller>(createParams);
237
+ const result = yield this.sellerModel.insertMany(createParams, { rawResult: true });
238
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
239
+ if (typeof insertedId !== 'string') {
240
+ throw new factory.errors.Internal(`seller not saved unexpectedly. result:${JSON.stringify(result)}`);
241
+ }
242
+ savedId = insertedId;
218
243
  }
219
- return doc.toObject();
244
+ return { id: savedId };
220
245
  });
221
246
  }
222
247
  /**
@@ -249,29 +274,38 @@ class SellerRepo {
249
274
  /**
250
275
  * 販売者検索
251
276
  */
252
- search(conditions, inclusion, exclusion) {
277
+ projectFields(conditions, inclusion, exclusion) {
253
278
  var _a;
254
279
  return __awaiter(this, void 0, void 0, function* () {
255
280
  const andConditions = SellerRepo.CREATE_MONGO_CONDITIONS(conditions);
256
- let projection = {};
281
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
257
282
  if (Array.isArray(inclusion) && inclusion.length > 0) {
258
- inclusion.forEach((field) => {
259
- projection[field] = 1;
260
- });
283
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
261
284
  }
262
285
  else {
263
- projection = {
264
- __v: 0,
265
- createdAt: 0,
266
- updatedAt: 0,
267
- paymentAccepted: 0 // 除外(2023-12-01~)
268
- };
269
286
  if (Array.isArray(exclusion) && exclusion.length > 0) {
270
- exclusion.forEach((field) => {
271
- projection[field] = 0;
272
- });
287
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
273
288
  }
274
289
  }
290
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
291
+ // let projection: { [key: string]: number } = {};
292
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
293
+ // inclusion.forEach((field) => {
294
+ // projection[field] = 1;
295
+ // });
296
+ // } else {
297
+ // projection = {
298
+ // __v: 0,
299
+ // createdAt: 0,
300
+ // updatedAt: 0,
301
+ // paymentAccepted: 0 // 除外(2023-12-01~)
302
+ // };
303
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
304
+ // exclusion.forEach((field) => {
305
+ // projection[field] = 0;
306
+ // });
307
+ // }
308
+ // }
275
309
  const query = this.sellerModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
276
310
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
277
311
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -284,8 +318,8 @@ class SellerRepo {
284
318
  query.sort({ branchCode: conditions.sort.branchCode });
285
319
  }
286
320
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
287
- .exec()
288
- .then((docs) => docs.map((doc) => doc.toObject()));
321
+ .lean() // 2024-08-22~
322
+ .exec();
289
323
  });
290
324
  }
291
325
  /**
@@ -294,9 +328,9 @@ class SellerRepo {
294
328
  deleteById(params) {
295
329
  return __awaiter(this, void 0, void 0, function* () {
296
330
  yield this.sellerModel.findOneAndRemove({
297
- _id: params.id,
331
+ _id: { $eq: params.id },
298
332
  'project.id': { $eq: params.project.id }
299
- })
333
+ }, { projection: { _id: 1 } })
300
334
  .exec();
301
335
  });
302
336
  }
@@ -313,7 +347,7 @@ class SellerRepo {
313
347
  }
314
348
  addAvailableAtOrFrom(params) {
315
349
  return __awaiter(this, void 0, void 0, function* () {
316
- return this.sellerModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $push: { makesOffer: params.makesOffer } })
350
+ yield this.sellerModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $push: { makesOffer: params.makesOffer } }, { projection: { _id: 1 } })
317
351
  .exec();
318
352
  });
319
353
  }
@@ -4,7 +4,7 @@ export interface ITicketIssuedBy {
4
4
  id: string;
5
5
  typeOf: factory.organizationType.Corporation | factory.organizationType.Project;
6
6
  }
7
- interface ITicket {
7
+ export interface ITicket {
8
8
  /**
9
9
  * チケットID(jti)
10
10
  */
@@ -42,6 +42,7 @@ interface ISearchConditions {
42
42
  $eq?: string;
43
43
  };
44
44
  }
45
+ type IKeyOfProjection = keyof ITicket;
45
46
  /**
46
47
  * チケットリポジトリ
47
48
  */
@@ -53,6 +54,6 @@ export declare class TicketRepo {
53
54
  * 承認コードからチケットを発行する
54
55
  */
55
56
  issueByTicketToken(params: IIssueParams): Promise<Pick<ITicket, 'id'>>;
56
- search(params: ISearchConditions): Promise<ITicket[]>;
57
+ projectFields(params: ISearchConditions, inclusion: IKeyOfProjection[]): Promise<ITicket[]>;
57
58
  }
58
59
  export {};