@chevre/domain 22.2.0-alpha.12 → 22.2.0-alpha.14

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 (31) hide show
  1. package/example/src/chevre/playAroundTicket.ts +3 -2
  2. package/example/src/chevre/projectFields.ts +4 -4
  3. package/lib/chevre/repo/paymentService.d.ts +2 -2
  4. package/lib/chevre/repo/paymentService.js +63 -28
  5. package/lib/chevre/repo/product.d.ts +2 -2
  6. package/lib/chevre/repo/product.js +62 -27
  7. package/lib/chevre/repo/ticket.d.ts +3 -2
  8. package/lib/chevre/repo/ticket.js +23 -10
  9. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +1 -1
  10. package/lib/chevre/service/aggregation/event/findEventOffers.js +1 -1
  11. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  12. package/lib/chevre/service/assetTransaction/pay/factory.d.ts +1 -1
  13. package/lib/chevre/service/assetTransaction/pay.js +3 -3
  14. package/lib/chevre/service/assetTransaction/refund/factory.d.ts +1 -1
  15. package/lib/chevre/service/assetTransaction/refund.js +3 -3
  16. package/lib/chevre/service/assetTransaction/registerService.js +3 -5
  17. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +5 -7
  18. package/lib/chevre/service/assetTransaction/reserve/start.js +1 -3
  19. package/lib/chevre/service/code.js +2 -2
  20. package/lib/chevre/service/moneyTransfer.js +1 -3
  21. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +2 -2
  22. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +4 -12
  23. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -3
  24. package/lib/chevre/service/offer/product.d.ts +1 -1
  25. package/lib/chevre/service/offer/product.js +2 -2
  26. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +2 -2
  27. package/lib/chevre/service/payment/paymentCard.js +1 -3
  28. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +2 -2
  29. package/lib/chevre/service/task/onResourceUpdated.js +1 -1
  30. package/package.json +1 -1
  31. package/example/src/chevre/searchProducts.ts +0 -28
@@ -14,7 +14,7 @@ async function main() {
14
14
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
15
15
 
16
16
  const ticketRepo = await chevre.repository.Ticket.createInstance(mongoose.connection);
17
- const tickets = await ticketRepo.search(
17
+ const tickets = await ticketRepo.projectFields(
18
18
  {
19
19
  limit: 1,
20
20
  page: 1,
@@ -23,7 +23,8 @@ async function main() {
23
23
  id: { $eq: project.id }
24
24
  },
25
25
  ticketToken: { $eq: TICKET_TOKEN }
26
- }
26
+ },
27
+ []
27
28
  );
28
29
  console.log('tickets:', tickets);
29
30
  console.log(tickets.length, 'tickets found');
@@ -8,15 +8,15 @@ const project = { id: String(process.env.PROJECT_ID) };
8
8
  async function main() {
9
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
10
 
11
- const categoryCodeRepo = await chevre.repository.CategoryCode.createInstance(mongoose.connection);
11
+ const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
12
12
 
13
- const docs = await categoryCodeRepo.projectFields(
13
+ const docs = await productRepo.projectFields(
14
14
  {
15
- limit: 1,
15
+ limit: 10,
16
16
  page: 1,
17
17
  project: { id: { $eq: project.id } }
18
18
  },
19
- ['codeValue', 'inCodeSet', 'name', 'project', 'id'],
19
+ [],
20
20
  []
21
21
  );
22
22
  // tslint:disable-next-line:no-null-keyword
@@ -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
  */
@@ -155,70 +166,94 @@ class PaymentServiceRepo {
155
166
  * 決済サービスを保管する
156
167
  */
157
168
  savePaymentService(params) {
169
+ var _a, _b;
158
170
  return __awaiter(this, void 0, void 0, function* () {
159
171
  let doc;
172
+ let savedId;
160
173
  if (typeof params.id === 'string') {
161
174
  // 上書き禁止属性を除外
162
- const _a = params.$set, { id, productID, project, typeOf, provider } = _a, setFields = __rest(_a, ["id", "productID", "project", "typeOf", "provider"]);
175
+ const _c = params.$set, { id, productID, project, typeOf, provider } = _c, setFields = __rest(_c, ["id", "productID", "project", "typeOf", "provider"]);
163
176
  switch (typeOf) {
164
177
  case factory.service.paymentService.PaymentServiceType.CreditCard:
165
178
  case factory.service.paymentService.PaymentServiceType.MovieTicket:
166
179
  doc = yield this.paymentServiceModel.findOneAndUpdate({
167
180
  _id: { $eq: params.id },
168
181
  typeOf: { $eq: typeOf }
169
- }, { $set: setFields }, { upsert: false, new: true, projection: { _id: 1 } })
182
+ }, { $set: setFields }, { upsert: false, new: true, projection: { _id: 1, id: { $toString: '$_id' } } })
183
+ .lean()
170
184
  .exec();
185
+ if (doc === null) {
186
+ throw new factory.errors.NotFound(this.paymentServiceModel.modelName);
187
+ }
171
188
  break;
172
189
  default:
173
190
  throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
174
191
  }
192
+ savedId = params.id;
175
193
  }
176
194
  else {
177
- const _b = params.$set, { id } = _b, createParams = __rest(_b, ["id"]);
195
+ const _d = params.$set, { id } = _d, createParams = __rest(_d, ["id"]);
178
196
  if (params.createIfNotExist === true) {
179
197
  doc = yield this.paymentServiceModel.findOneAndUpdate({
180
198
  'project.id': { $eq: createParams.project.id },
181
199
  typeOf: { $eq: createParams.typeOf }
182
- }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1 } })
200
+ }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1, id: { $toString: '$_id' } } })
201
+ .lean()
183
202
  .exec();
203
+ if (doc === null) {
204
+ throw new factory.errors.NotFound(this.paymentServiceModel.modelName);
205
+ }
206
+ savedId = doc.id;
184
207
  }
185
208
  else {
186
- doc = yield this.paymentServiceModel.create(createParams);
209
+ // doc = await this.paymentServiceModel.create(createParams);
210
+ const result = yield this.paymentServiceModel.insertMany(createParams, { rawResult: true });
211
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
212
+ if (typeof insertedId !== 'string') {
213
+ throw new factory.errors.Internal(`paymentService not saved unexpectedly. result:${JSON.stringify(result)}`);
214
+ }
215
+ savedId = insertedId;
187
216
  }
188
217
  }
189
- if (doc === null) {
190
- throw new factory.errors.NotFound(this.paymentServiceModel.modelName);
191
- }
192
- return doc.toObject();
218
+ return { id: savedId };
193
219
  });
194
220
  }
195
221
  /**
196
222
  * 決済サービスを検索する
197
223
  */
198
- searchPaymentServices(conditions, inclusion, exclusion) {
224
+ projectFields(conditions, inclusion, exclusion) {
199
225
  var _a;
200
226
  return __awaiter(this, void 0, void 0, function* () {
201
227
  const andConditions = PaymentServiceRepo.CREATE_MONGO_CONDITIONS(conditions);
202
- let projection = {};
228
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
203
229
  if (Array.isArray(inclusion) && inclusion.length > 0) {
204
- inclusion.forEach((field) => {
205
- projection[field] = 1;
206
- });
230
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
207
231
  }
208
232
  else {
209
- projection = {
210
- __v: 0,
211
- createdAt: 0,
212
- updatedAt: 0,
213
- offers: 0,
214
- provider: 0 // paymentServiceProviderRepoへの完全移行につき除外(2023-12-20~)
215
- };
216
233
  if (Array.isArray(exclusion) && exclusion.length > 0) {
217
- exclusion.forEach((field) => {
218
- projection[field] = 0;
219
- });
234
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
220
235
  }
221
236
  }
237
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
238
+ // let projection: { [key: string]: number } = {};
239
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
240
+ // inclusion.forEach((field) => {
241
+ // projection[field] = 1;
242
+ // });
243
+ // } else {
244
+ // projection = {
245
+ // __v: 0,
246
+ // createdAt: 0,
247
+ // updatedAt: 0,
248
+ // offers: 0,
249
+ // provider: 0 // paymentServiceProviderRepoへの完全移行につき除外(2023-12-20~)
250
+ // };
251
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
252
+ // exclusion.forEach((field) => {
253
+ // projection[field] = 0;
254
+ // });
255
+ // }
256
+ // }
222
257
  const query = this.paymentServiceModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
223
258
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
224
259
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -231,13 +266,13 @@ class PaymentServiceRepo {
231
266
  query.sort({ productID: conditions.sort.productID });
232
267
  }
233
268
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
234
- .exec()
235
- .then((docs) => docs.map((doc) => doc.toObject()));
269
+ .lean() // 2024-08-20~
270
+ .exec();
236
271
  });
237
272
  }
238
273
  deletePaymentServiceById(params) {
239
274
  return __awaiter(this, void 0, void 0, function* () {
240
- yield this.paymentServiceModel.findOneAndDelete({ _id: params.id })
275
+ yield this.paymentServiceModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
241
276
  .exec();
242
277
  });
243
278
  }
@@ -247,7 +282,7 @@ class PaymentServiceRepo {
247
282
  findAvailableChannel(params) {
248
283
  return __awaiter(this, void 0, void 0, function* () {
249
284
  let paymentService;
250
- paymentService = (yield this.searchPaymentServices({
285
+ paymentService = (yield this.projectFields({
251
286
  limit: 1,
252
287
  page: 1,
253
288
  project: { id: { $eq: params.project.id } },
@@ -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: {
@@ -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
  */
@@ -154,28 +166,37 @@ class ProductRepo {
154
166
  /**
155
167
  * プロダクトを検索する
156
168
  */
157
- searchProducts(conditions, inclusion, exclusion) {
169
+ projectFields(conditions, inclusion, exclusion) {
158
170
  var _a;
159
171
  return __awaiter(this, void 0, void 0, function* () {
160
172
  const andConditions = ProductRepo.CREATE_MONGO_CONDITIONS(conditions);
161
- let projection = {};
173
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
162
174
  if (Array.isArray(inclusion) && inclusion.length > 0) {
163
- inclusion.forEach((field) => {
164
- projection[field] = 1;
165
- });
175
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
166
176
  }
167
177
  else {
168
- projection = {
169
- __v: 0,
170
- createdAt: 0,
171
- updatedAt: 0
172
- };
173
178
  if (Array.isArray(exclusion) && exclusion.length > 0) {
174
- exclusion.forEach((field) => {
175
- projection[field] = 0;
176
- });
179
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
177
180
  }
178
181
  }
182
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
183
+ // let projection: { [key: string]: number } = {};
184
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
185
+ // inclusion.forEach((field) => {
186
+ // projection[field] = 1;
187
+ // });
188
+ // } else {
189
+ // projection = {
190
+ // __v: 0,
191
+ // createdAt: 0,
192
+ // updatedAt: 0
193
+ // };
194
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
195
+ // exclusion.forEach((field) => {
196
+ // projection[field] = 0;
197
+ // });
198
+ // }
199
+ // }
179
200
  const query = this.productModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
180
201
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
181
202
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -188,13 +209,13 @@ class ProductRepo {
188
209
  query.sort({ productID: conditions.sort.productID });
189
210
  }
190
211
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
191
- .exec()
192
- .then((docs) => docs.map((doc) => doc.toObject()));
212
+ .lean() // 2024-08-20~
213
+ .exec();
193
214
  });
194
215
  }
195
216
  deleteProductById(params) {
196
217
  return __awaiter(this, void 0, void 0, function* () {
197
- yield this.productModel.findOneAndDelete({ _id: params.id })
218
+ yield this.productModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
198
219
  .exec();
199
220
  });
200
221
  }
@@ -202,11 +223,13 @@ class ProductRepo {
202
223
  * プロダクトを保管する
203
224
  */
204
225
  saveProduct(params) {
226
+ var _a, _b;
205
227
  return __awaiter(this, void 0, void 0, function* () {
206
228
  let doc;
229
+ let savedId;
207
230
  if (typeof params.id === 'string') {
208
231
  // 上書き禁止属性を除外
209
- const _a = params.$set, { id, productID, project, typeOf, offers } = _a, setFields = __rest(_a, ["id", "productID", "project", "typeOf", "offers"]);
232
+ const _c = params.$set, { id, productID, project, typeOf, offers } = _c, setFields = __rest(_c, ["id", "productID", "project", "typeOf", "offers"]);
210
233
  switch (typeOf) {
211
234
  case factory.product.ProductType.EventService:
212
235
  case factory.product.ProductType.MembershipService:
@@ -219,30 +242,43 @@ class ProductRepo {
219
242
  }, {
220
243
  $set: setFields,
221
244
  $unset: params.$unset
222
- }, { upsert: false, new: true, projection: { _id: 1 } })
245
+ }, { upsert: false, new: true, projection: { _id: 1, id: { $toString: '$_id' } } })
246
+ .lean()
223
247
  .exec();
248
+ if (doc === null) {
249
+ throw new factory.errors.NotFound(this.productModel.modelName);
250
+ }
224
251
  break;
225
252
  default:
226
253
  throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
227
254
  }
255
+ savedId = params.id;
228
256
  }
229
257
  else {
230
- const _b = params.$set, { id } = _b, createParams = __rest(_b, ["id"]);
258
+ const _d = params.$set, { id } = _d, createParams = __rest(_d, ["id"]);
231
259
  if (params.createIfNotExist === true) {
232
260
  doc = yield this.productModel.findOneAndUpdate({
233
261
  'project.id': { $eq: createParams.project.id },
234
262
  typeOf: { $eq: createParams.typeOf }
235
- }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1 } })
263
+ }, { $setOnInsert: createParams }, { new: true, upsert: true, projection: { _id: 1, id: { $toString: '$_id' } } })
264
+ .lean()
236
265
  .exec();
266
+ if (doc === null) {
267
+ throw new factory.errors.NotFound(this.productModel.modelName);
268
+ }
269
+ savedId = doc.id;
237
270
  }
238
271
  else {
239
- doc = yield this.productModel.create(createParams);
272
+ // doc = await this.productModel.create(createParams);
273
+ const result = yield this.productModel.insertMany(createParams, { rawResult: true });
274
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
275
+ if (typeof insertedId !== 'string') {
276
+ throw new factory.errors.Internal(`product not saved unexpectedly. result:${JSON.stringify(result)}`);
277
+ }
278
+ savedId = insertedId;
240
279
  }
241
280
  }
242
- if (doc === null) {
243
- throw new factory.errors.NotFound(this.productModel.modelName);
244
- }
245
- return doc.toObject();
281
+ return { id: savedId };
246
282
  });
247
283
  }
248
284
  /**
@@ -297,8 +333,7 @@ class ProductRepo {
297
333
  */
298
334
  findAvailableChannel(params) {
299
335
  return __awaiter(this, void 0, void 0, function* () {
300
- let paymentService;
301
- paymentService = (yield this.searchProducts({
336
+ const paymentService = (yield this.projectFields({
302
337
  limit: 1,
303
338
  page: 1,
304
339
  project: { id: { $eq: params.project.id } },
@@ -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 {};
@@ -13,6 +13,13 @@ exports.TicketRepo = void 0;
13
13
  const factory = require("../factory");
14
14
  const settings_1 = require("../settings");
15
15
  const ticket_1 = require("./mongoose/schemas/ticket");
16
+ const AVAILABLE_PROJECT_FIELDS = [
17
+ 'project',
18
+ 'typeOf',
19
+ 'ticketToken',
20
+ 'dateIssued',
21
+ 'issuedBy'
22
+ ];
16
23
  /**
17
24
  * チケットリポジトリ
18
25
  */
@@ -41,6 +48,7 @@ class TicketRepo {
41
48
  * 承認コードからチケットを発行する
42
49
  */
43
50
  issueByTicketToken(params) {
51
+ var _a, _b;
44
52
  return __awaiter(this, void 0, void 0, function* () {
45
53
  const { ticketToken, project, issuedBy } = params;
46
54
  const ticketIssuedBy = (typeof (issuedBy === null || issuedBy === void 0 ? void 0 : issuedBy.id) === 'string' && issuedBy.typeOf === factory.organizationType.Corporation)
@@ -53,19 +61,24 @@ class TicketRepo {
53
61
  ticketToken,
54
62
  typeOf: 'Ticket'
55
63
  };
56
- const doc = yield this.ticketModel.create(creatingTicket);
57
- return { id: doc.id };
64
+ const result = yield this.ticketModel.insertMany(creatingTicket, { rawResult: true });
65
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
66
+ if (typeof insertedId !== 'string') {
67
+ throw new factory.errors.Internal(`ticket not saved unexpectedly. result:${JSON.stringify(result)}`);
68
+ }
69
+ return { id: insertedId };
58
70
  });
59
71
  }
60
- search(params) {
72
+ projectFields(params, inclusion) {
61
73
  var _a;
62
74
  return __awaiter(this, void 0, void 0, function* () {
63
75
  const conditions = TicketRepo.CREATE_MONGO_CONDITIONS(params);
64
- const query = this.ticketModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
65
- // __v: 0,
66
- // createdAt: 0,
67
- // updatedAt: 0
68
- });
76
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
77
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
78
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
79
+ }
80
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
81
+ const query = this.ticketModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
69
82
  if (typeof params.limit === 'number' && params.limit > 0) {
70
83
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
71
84
  query.limit(params.limit)
@@ -75,8 +88,8 @@ class TicketRepo {
75
88
  query.sort({ dateIssued: params.sort.dateIssued });
76
89
  }
77
90
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
78
- .exec()
79
- .then((docs) => docs.map((doc) => doc.toObject()));
91
+ .lean() // 2024-08-20~
92
+ .exec();
80
93
  });
81
94
  }
82
95
  }
@@ -165,7 +165,7 @@ function calculateOfferCount(params) {
165
165
  try {
166
166
  const eventOffers = params.event.offers;
167
167
  if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
168
- const eventService = (yield repos.product.searchProducts({
168
+ const eventService = (yield repos.product.projectFields({
169
169
  limit: 1,
170
170
  page: 1,
171
171
  id: { $eq: eventOffers.itemOffered.id }
@@ -23,7 +23,7 @@ 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.searchProducts({
26
+ const eventService = (yield repos.product.projectFields({
27
27
  limit: 1,
28
28
  page: 1,
29
29
  id: { $eq: eventOffers.itemOffered.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.searchProducts({
31
+ const products = yield repos.product.projectFields({
32
32
  limit: 1,
33
33
  page: 1,
34
34
  project: { id: { $eq: params.project.id } },
@@ -6,6 +6,6 @@ export declare function createStartParams(params: factory.assetTransaction.pay.I
6
6
  transactionNumber: string;
7
7
  paymentServiceType: factory.service.paymentService.PaymentServiceType;
8
8
  amount: number;
9
- paymentService?: factory.service.paymentService.IService | factory.product.IProduct;
9
+ paymentService?: Pick<factory.service.paymentService.IService, 'availableChannel' | 'id' | 'serviceOutput' | 'serviceType'> | Pick<factory.product.IProduct, 'availableChannel' | 'id' | 'serviceOutput' | 'serviceType'>;
10
10
  location?: factory.action.trade.pay.ILocation;
11
11
  }): factory.assetTransaction.IStartParams<factory.assetTransactionType.Pay>;
@@ -268,7 +268,7 @@ function fixPaymentService(params) {
268
268
  break;
269
269
  // PaymentCardの場合、プロダクト検索
270
270
  case factory.service.paymentService.PaymentServiceType.PaymentCard:
271
- paymentService = (yield repos.product.searchProducts({
271
+ paymentService = (yield repos.product.projectFields({
272
272
  limit: 1,
273
273
  page: 1,
274
274
  project: { id: { $eq: params.project.id } },
@@ -280,13 +280,13 @@ function fixPaymentService(params) {
280
280
  }
281
281
  break;
282
282
  default:
283
- paymentService = (yield repos.paymentService.searchPaymentServices({
283
+ paymentService = (yield repos.paymentService.projectFields({
284
284
  limit: 1,
285
285
  page: 1,
286
286
  project: { id: { $eq: params.project.id } },
287
287
  typeOf: { $eq: paymentServiceType },
288
288
  id: { $eq: getPaymentServiceId(params) }
289
- }, [], [])).shift();
289
+ }, ['availableChannel', 'serviceOutput', 'serviceType'], [])).shift();
290
290
  if (paymentService === undefined) {
291
291
  throw new factory.errors.NotFound('PaymentService');
292
292
  }
@@ -6,5 +6,5 @@ export declare function createStartParams(params: factory.assetTransaction.refun
6
6
  transactionNumber: string;
7
7
  paymentServiceType: factory.service.paymentService.PaymentServiceType;
8
8
  payAction: factory.action.trade.pay.IAction;
9
- paymentService?: factory.product.IProduct | factory.service.paymentService.IService;
9
+ paymentService?: factory.product.IProduct | Pick<factory.service.paymentService.IService, 'availableChannel' | 'id' | 'typeOf' | 'serviceOutput'>;
10
10
  }): factory.assetTransaction.IStartParams<factory.assetTransactionType.Refund>;
@@ -86,7 +86,7 @@ function fixPaymentService(params) {
86
86
  break;
87
87
  // PaymentCardの場合、プロダクト検索
88
88
  case factory.service.paymentService.PaymentServiceType.PaymentCard:
89
- paymentService = (yield repos.product.searchProducts({
89
+ paymentService = (yield repos.product.projectFields({
90
90
  limit: 1,
91
91
  page: 1,
92
92
  project: { id: { $eq: params.payAction.project.id } },
@@ -98,13 +98,13 @@ function fixPaymentService(params) {
98
98
  }
99
99
  break;
100
100
  default:
101
- paymentService = (yield repos.paymentService.searchPaymentServices({
101
+ paymentService = (yield repos.paymentService.projectFields({
102
102
  limit: 1,
103
103
  page: 1,
104
104
  project: { id: { $eq: params.payAction.project.id } },
105
105
  typeOf: { $eq: params.paymentServiceType },
106
106
  id: { $eq: paymentServiceId }
107
- }, [], [])).shift();
107
+ }, ['availableChannel', 'serviceOutput', 'typeOf'], [])).shift();
108
108
  if (paymentService === undefined) {
109
109
  throw new factory.errors.NotFound('PaymentService');
110
110
  }
@@ -44,8 +44,7 @@ function start(params) {
44
44
  throw new factory.errors.ArgumentNull('object.itemOffered.id');
45
45
  }
46
46
  // プロダクト確認
47
- // const product = await repos.product.findProductById({ id: productId }, [], []);
48
- const product = (yield repos.product.searchProducts({
47
+ const product = (yield repos.product.projectFields({
49
48
  limit: 1,
50
49
  page: 1,
51
50
  id: { $eq: productId }
@@ -138,12 +137,11 @@ function createTransactionObject(params) {
138
137
  function createPermitService(params) {
139
138
  return (repos) => __awaiter(this, void 0, void 0, function* () {
140
139
  var _a, _b, _c, _d, _e, _f, _g;
141
- // const product = await repos.product.findProductById({ id: params.issuedThrough.id }, [], []);
142
- const product = (yield repos.product.searchProducts({
140
+ const product = (yield repos.product.projectFields({
143
141
  limit: 1,
144
142
  page: 1,
145
143
  id: { $eq: params.issuedThrough.id }
146
- }, [], [])).shift();
144
+ }, ['availableChannel'], [])).shift();
147
145
  if (product === undefined) {
148
146
  throw new factory.errors.NotFound('Product');
149
147
  }
@@ -294,12 +294,12 @@ function validateProgramMembershipUsed(params) {
294
294
  if (typeof issuedThroughId !== 'string' || issuedThroughId === '') {
295
295
  throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed.issuedThrough.id');
296
296
  }
297
- permitIssuedThrough = (yield repos.product.searchProducts({
297
+ permitIssuedThrough = (yield repos.product.projectFields({
298
298
  limit: 1,
299
299
  page: 1,
300
300
  id: { $eq: issuedThroughId },
301
301
  typeOf: { $eq: factory.product.ProductType.MembershipService }
302
- }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
302
+ }, ['typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
303
303
  if (permitIssuedThrough === undefined) {
304
304
  throw new factory.errors.NotFound(factory.product.ProductType.MembershipService);
305
305
  }
@@ -309,12 +309,12 @@ function validateProgramMembershipUsed(params) {
309
309
  if (typeof issuedThroughId !== 'string' || issuedThroughId === '') {
310
310
  throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed.issuedThrough.id');
311
311
  }
312
- permitIssuedThrough = (yield repos.paymentService.searchPaymentServices({
312
+ permitIssuedThrough = (yield repos.paymentService.projectFields({
313
313
  limit: 1,
314
314
  page: 1,
315
315
  id: { $eq: issuedThroughId },
316
316
  typeOf: { $eq: factory.service.paymentService.PaymentServiceType.CreditCard }
317
- }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
317
+ }, ['typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
318
318
  if (permitIssuedThrough === undefined) {
319
319
  throw new factory.errors.NotFound(factory.service.paymentService.PaymentServiceType.CreditCard);
320
320
  }
@@ -410,9 +410,7 @@ function validateProgramMembershipUsed(params) {
410
410
  function createPermitService(params) {
411
411
  return (repos) => __awaiter(this, void 0, void 0, function* () {
412
412
  var _a, _b, _c, _d, _e, _f, _g;
413
- // const product = <Pick<factory.product.IProduct, 'availableChannel'>>
414
- // await repos.product.findProductById({ id: params.issuedThrough.id }, ['availableChannel'], []);
415
- const product = (yield repos.product.searchProducts({
413
+ const product = (yield repos.product.projectFields({
416
414
  limit: 1,
417
415
  page: 1,
418
416
  id: { $eq: params.issuedThrough.id }
@@ -405,9 +405,7 @@ function getAcceptedSeatNumbersAndSeatSections(params) {
405
405
  function createPermitService(params) {
406
406
  return (repos) => __awaiter(this, void 0, void 0, function* () {
407
407
  var _a, _b, _c, _d, _e, _f, _g;
408
- // const product = <Pick<factory.product.IProduct, 'availableChannel'>>
409
- // await repos.product.findProductById({ id: params.issuedThrough.id }, ['availableChannel'], []);
410
- const product = (yield repos.product.searchProducts({
408
+ const product = (yield repos.product.projectFields({
411
409
  limit: 1,
412
410
  page: 1,
413
411
  id: { $eq: params.issuedThrough.id }
@@ -110,12 +110,12 @@ function payload2authorizeObject(params) {
110
110
  // }
111
111
  if (typeof payload.jti === 'string') {
112
112
  // jtiに対応(2024-05-08~)
113
- const ticket = (yield repos.ticket.search({
113
+ const ticket = (yield repos.ticket.projectFields({
114
114
  limit: 1,
115
115
  page: 1,
116
116
  project: { id: { $eq: params.project.id } },
117
117
  id: { $eq: payload.jti }
118
- })).shift();
118
+ }, ['ticketToken'])).shift();
119
119
  if (ticket === undefined) {
120
120
  throw new factory.errors.NotFound('Ticket');
121
121
  }
@@ -329,9 +329,7 @@ function getIssuedThroughIdByAction(params) {
329
329
  function createPermitServiceCredentials(params) {
330
330
  return (repos) => __awaiter(this, void 0, void 0, function* () {
331
331
  var _a, _b, _c, _d, _e, _f, _g;
332
- // const paymentCardService = <Pick<factory.product.IProduct, 'availableChannel'>>
333
- // await repos.product.findProductById({ id: params.issuedThrough.id }, ['availableChannel'], []);
334
- const paymentCardService = (yield repos.product.searchProducts({
332
+ const paymentCardService = (yield repos.product.projectFields({
335
333
  limit: 1,
336
334
  page: 1,
337
335
  id: { $eq: params.issuedThrough.id },
@@ -60,12 +60,12 @@ function requestedProgramMembershipUsed2permit(params) {
60
60
  else if ((programMembershipUsed === null || programMembershipUsed === void 0 ? void 0 : programMembershipUsed.typeOf) === 'Ticket') {
61
61
  const { ticketToken } = programMembershipUsed;
62
62
  if (typeof ticketToken === 'string') {
63
- const ticket = (yield repos.ticket.search({
63
+ const ticket = (yield repos.ticket.projectFields({
64
64
  limit: 1,
65
65
  page: 1,
66
66
  project: { id: { $eq: params.project.id } },
67
67
  ticketToken: { $eq: ticketToken }
68
- })).shift();
68
+ }, ['ticketToken'])).shift();
69
69
  if (ticket === undefined) {
70
70
  throw new factory.errors.NotFound('Ticket');
71
71
  }
@@ -18,10 +18,8 @@ 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: Pick<factory.product.IProduct, 'hasOfferCatalog' | 'project'> | undefined;
22
21
  let catalogId;
23
- // const eventService = await repos.product.findProductById({ id: params.itemOffered?.id }, ['hasOfferCatalog', 'project'], []);
24
- const eventService = (yield repos.product.searchProducts({
22
+ const eventService = (yield repos.product.projectFields({
25
23
  limit: 1,
26
24
  page: 1,
27
25
  id: { $eq: String((_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.id) }
@@ -380,9 +378,7 @@ function searchOfferAppliesToMovieTicket(params) {
380
378
  const eventOffers = event.offers;
381
379
  let catalogId;
382
380
  if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
383
- // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
384
- // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
385
- const eventService = (yield repos.product.searchProducts({
381
+ const eventService = (yield repos.product.projectFields({
386
382
  limit: 1,
387
383
  page: 1,
388
384
  id: { $eq: eventOffers.itemOffered.id }
@@ -438,9 +434,7 @@ function searchOfferCatalogItems(params) {
438
434
  const eventOffers = event.offers;
439
435
  let catalogId;
440
436
  if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
441
- // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
442
- // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
443
- const eventService = (yield repos.product.searchProducts({
437
+ const eventService = (yield repos.product.projectFields({
444
438
  limit: 1,
445
439
  page: 1,
446
440
  id: { $eq: eventOffers.itemOffered.id }
@@ -508,9 +502,7 @@ function searchOfferCatalogItemAvailability(params) {
508
502
  const eventOffers = event.offers;
509
503
  let catalogId;
510
504
  if (typeof ((_a = eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
511
- // const eventService = <Pick<factory.product.IProduct, 'hasOfferCatalog'>>
512
- // await repos.product.findProductById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
513
- const eventService = (yield repos.product.searchProducts({
505
+ const eventService = (yield repos.product.projectFields({
514
506
  limit: 1,
515
507
  page: 1,
516
508
  id: { $eq: eventOffers.itemOffered.id }
@@ -19,9 +19,7 @@ function searchProductOffers(params) {
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a, _b;
21
21
  // プロダクト検索
22
- // const productWithOffers = <Pick<factory.product.IProduct, 'hasOfferCatalog' | 'project'>>
23
- // await repos.product.findProductById({ id: params.itemOffered.id }, ['hasOfferCatalog', 'project'], []);
24
- const productWithOffers = (yield repos.product.searchProducts({
22
+ const productWithOffers = (yield repos.product.projectFields({
25
23
  limit: 1,
26
24
  page: 1,
27
25
  id: { $eq: params.itemOffered.id }
@@ -68,7 +68,7 @@ export declare function search(params: {
68
68
  productOffer: ProductOfferRepo;
69
69
  }) => Promise<{
70
70
  offers: factory.product.ITicketOffer[];
71
- product: Omit<factory.product.IProduct, "offers">;
71
+ product: factory.product.IProduct;
72
72
  }>;
73
73
  export type IAuthorizeOfferAction = factory.action.authorize.offer.product.IAction;
74
74
  /**
@@ -27,7 +27,7 @@ function search(params) {
27
27
  return (repos) => __awaiter(this, void 0, void 0, function* () {
28
28
  var _a;
29
29
  const now = moment();
30
- const searchProductsResult = yield repos.product.searchProducts({
30
+ const searchProductsResult = yield repos.product.projectFields({
31
31
  limit: 1,
32
32
  page: 1,
33
33
  project: { id: { $eq: params.project.id } },
@@ -172,7 +172,7 @@ function fixProductAndOffers(params) {
172
172
  return (repos) => __awaiter(this, void 0, void 0, function* () {
173
173
  var _a, _b, _c;
174
174
  const productId = String((_b = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.id);
175
- const searchProductsResult = yield repos.product.searchProducts({
175
+ const searchProductsResult = yield repos.product.projectFields({
176
176
  limit: 1,
177
177
  page: 1,
178
178
  project: { id: { $eq: params.project.id } },
@@ -23,12 +23,12 @@ function verifyTicketTokenAsNeeded(params) {
23
23
  // トークン化されたメンバーシップがリクエストされた場合、実メンバーシップ情報へ変換する
24
24
  if (typeof ticketToken === 'string' && ticketToken !== '') {
25
25
  let authorizedObject;
26
- const ticket = (yield repos.ticket.search({
26
+ const ticket = (yield repos.ticket.projectFields({
27
27
  limit: 1,
28
28
  page: 1,
29
29
  project: { id: { $eq: project.id } },
30
30
  ticketToken: { $eq: ticketToken }
31
- })).shift();
31
+ }, ['ticketToken'])).shift();
32
32
  if (ticket === undefined) {
33
33
  throw new factory.errors.NotFound('Ticket');
34
34
  }
@@ -79,9 +79,7 @@ function validatePaymentMethod(params, paymentServiceId) {
79
79
  throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
80
80
  }
81
81
  // プロダクトから通貨区分を取得
82
- // const paymentCatdProduct = <Pick<factory.product.IProduct, 'serviceOutput'>>
83
- // await repos.product.findProductById({ id: paymentServiceId }, ['serviceOutput'], []);
84
- const paymentCatdProduct = (yield repos.product.searchProducts({
82
+ const paymentCatdProduct = (yield repos.product.projectFields({
85
83
  limit: 1,
86
84
  page: 1,
87
85
  id: { $eq: paymentServiceId },
@@ -343,10 +343,10 @@ function deleteResourcesByOfferCatalog(params) {
343
343
  const action = yield repos.action.start(deleteActionAttributes);
344
344
  try {
345
345
  // カタログからプロダクト検索
346
- const productsWithCatalog = yield repos.product.searchProducts({
346
+ const productsWithCatalog = yield repos.product.projectFields({
347
347
  project: { id: { $eq: params.project.id } },
348
348
  hasOfferCatalog: { id: { $eq: catalogId } }
349
- }, ['_id'], []);
349
+ }, ['id'], []);
350
350
  let deleteEventResult;
351
351
  let updateOfferResult;
352
352
  if (productsWithCatalog.length > 0) {
@@ -275,7 +275,7 @@ function createInformMovieTasks(params) {
275
275
  }
276
276
  function createInformProductTasks(params) {
277
277
  return (repos, settings) => __awaiter(this, void 0, void 0, function* () {
278
- const products4inform = yield repos.product.searchProducts({
278
+ const products4inform = yield repos.product.projectFields({
279
279
  typeOf: { $eq: params.typeOf },
280
280
  id: { $in: params.ids }
281
281
  }, ['additionalProperty', 'description', 'name', 'productID', 'project', 'typeOf', 'serviceType'], []);
package/package.json CHANGED
@@ -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.12"
113
+ "version": "22.2.0-alpha.14"
114
114
  }
@@ -1,28 +0,0 @@
1
- // tslint:disable:no-implicit-dependencies no-console
2
- import { chevre } from '../../../lib/index';
3
-
4
- import * as mongoose from 'mongoose';
5
-
6
- const project = { id: String(process.env.PROJECT_ID) };
7
-
8
- async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
-
11
- const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
12
- const products = await productRepo.searchProducts(
13
- {
14
- project: { id: { $eq: project.id } }
15
- },
16
- // ['_id', 'typeOf'],
17
- [],
18
- []
19
- );
20
- console.log('products:', products);
21
- console.log(products.length, 'products found');
22
- }
23
-
24
- main()
25
- .then(() => {
26
- console.log('success!');
27
- })
28
- .catch(console.error);