@chevre/domain 22.5.0-alpha.0 → 22.5.0-alpha.2

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 (26) hide show
  1. package/example/src/chevre/migrateProductHasOfferCatalog.ts +80 -0
  2. package/example/src/chevre/projectFields.ts +2 -2
  3. package/lib/chevre/repo/mongoose/schemas/product.js +9 -3
  4. package/lib/chevre/repo/paymentService.js +0 -10
  5. package/lib/chevre/repo/product.d.ts +12 -3
  6. package/lib/chevre/repo/product.js +44 -26
  7. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +9 -5
  8. package/lib/chevre/service/aggregation/event/findEventOffers.js +6 -3
  9. package/lib/chevre/service/assetTransaction/moneyTransfer.js +3 -1
  10. package/lib/chevre/service/assetTransaction/pay.js +3 -1
  11. package/lib/chevre/service/assetTransaction/refund/factory.d.ts +1 -1
  12. package/lib/chevre/service/assetTransaction/refund.js +3 -1
  13. package/lib/chevre/service/assetTransaction/registerService/factory.d.ts +1 -1
  14. package/lib/chevre/service/assetTransaction/registerService.js +6 -2
  15. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +6 -2
  16. package/lib/chevre/service/assetTransaction/reserve/start.js +3 -1
  17. package/lib/chevre/service/moneyTransfer.js +3 -1
  18. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +37 -21
  19. package/lib/chevre/service/offer/product/searchProductOffers.js +7 -4
  20. package/lib/chevre/service/offer/product.d.ts +1 -1
  21. package/lib/chevre/service/offer/product.js +6 -2
  22. package/lib/chevre/service/payment/paymentCard.js +3 -1
  23. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +3 -1
  24. package/lib/chevre/service/task/onResourceUpdated.js +3 -1
  25. package/package.json +3 -3
  26. package/example/src/chevre/migrateEventSeries2secondary.ts +0 -70
@@ -0,0 +1,80 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ // tslint:disable-next-line:max-func-body-length
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
13
+
14
+ const cursor = productRepo.getCursor(
15
+ {
16
+ typeOf: { $exists: true },
17
+ 'hasOfferCatalog.id': { $exists: true }
18
+ },
19
+ {
20
+ project: 1,
21
+ typeOf: 1,
22
+ productID: 1,
23
+ hasOfferCatalog: 1,
24
+ id: { $toString: '$_id' }
25
+ }
26
+ );
27
+ console.log('docs found');
28
+
29
+ let i = 0;
30
+ let updateCount = 0;
31
+ await cursor.eachAsync(async (doc) => {
32
+ i += 1;
33
+ const product: Pick<chevre.factory.product.IProduct, 'hasOfferCatalog' | 'productID' | 'project' | 'typeOf' | 'id'> = doc;
34
+ // console.log(product);
35
+ const { hasOfferCatalog } = product;
36
+ if (typeof hasOfferCatalog?.id !== 'string') {
37
+ throw new Error(`${product.project.id} ${product.productID} has no catalog`);
38
+ }
39
+ if (typeof product.id !== 'string') {
40
+ throw new Error(`${product.project.id} ${product.productID} has no id`);
41
+ }
42
+
43
+ const alreadyMigrated = Array.isArray(hasOfferCatalog?.itemListElement)
44
+ && hasOfferCatalog?.itemListElement.length === 1
45
+ && hasOfferCatalog?.id === hasOfferCatalog.itemListElement[0].id;
46
+ if (alreadyMigrated) {
47
+ console.log(
48
+ 'already exist.',
49
+ product.project.id,
50
+ product.typeOf,
51
+ product.id, product.productID, i, updateCount
52
+ );
53
+ } else {
54
+ updateCount += 1;
55
+ console.log(
56
+ 'updating...',
57
+ product.project.id,
58
+ product.typeOf,
59
+ product.id, product.productID, i, updateCount
60
+ );
61
+ await productRepo.migrateHasOfferCatalogItemListElement({
62
+ id: product.id,
63
+ hasOfferCatalog: { id: hasOfferCatalog.id }
64
+ });
65
+ console.log(
66
+ 'updated.',
67
+ product.project.id,
68
+ product.typeOf,
69
+ product.id, product.productID, i, updateCount
70
+ );
71
+ }
72
+ });
73
+
74
+ console.log(i, 'docs checked');
75
+ console.log(updateCount, 'docs updated');
76
+ }
77
+
78
+ main()
79
+ .then()
80
+ .catch(console.error);
@@ -8,7 +8,7 @@ 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 repo = await chevre.repository.Task.createInstance(mongoose.connection);
11
+ const repo = await chevre.repository.Product.createInstance(mongoose.connection);
12
12
 
13
13
  const docs = await repo.projectFields(
14
14
  {
@@ -16,7 +16,7 @@ async function main() {
16
16
  page: 1,
17
17
  project: { id: { $eq: project.id } }
18
18
  },
19
- ['id', 'identifier', 'data']
19
+ ['hasOfferCatalog.id']
20
20
  );
21
21
  // tslint:disable-next-line:no-null-keyword
22
22
  console.dir(docs, { depth: null });
@@ -19,9 +19,6 @@ const schemaDefinition = {
19
19
  // provider: [SchemaTypes.Mixed], // 廃止(2024-04-12~)
20
20
  serviceOutput: mongoose_1.SchemaTypes.Mixed,
21
21
  serviceType: mongoose_1.SchemaTypes.Mixed
22
- // createdAt: SchemaTypes.Mixed,
23
- // updatedAt: SchemaTypes.Mixed,
24
- // __v: SchemaTypes.Mixed
25
22
  };
26
23
  const schemaOptions = {
27
24
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -65,6 +62,15 @@ const indexes = [
65
62
  }
66
63
  }
67
64
  ],
65
+ [
66
+ { 'hasOfferCatalog.itemListElement.id': 1, productID: 1 },
67
+ {
68
+ name: 'offerCatalogItemId',
69
+ partialFilterExpression: {
70
+ 'hasOfferCatalog.itemListElement.id': { $exists: true }
71
+ }
72
+ }
73
+ ],
68
74
  [
69
75
  { 'serviceOutput.typeOf': 1, productID: 1 },
70
76
  {
@@ -65,16 +65,6 @@ class PaymentServiceRepo {
65
65
  typeOf: { $in: typeOfIn }
66
66
  });
67
67
  }
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
68
  const idEq = (_e = params.id) === null || _e === void 0 ? void 0 : _e.$eq;
79
69
  if (typeof idEq === 'string') {
80
70
  andConditions.push({ _id: { $eq: idEq } });
@@ -24,9 +24,9 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import type { BulkWriteResult } from 'mongodb';
26
26
  import type { Connection, FilterQuery } from 'mongoose';
27
- import { IDocTypeAsProduct } from './mongoose/schemas/product';
28
27
  import * as factory from '../factory';
29
- type IKeyOfProjection = keyof factory.product.IProduct;
28
+ import { IDocTypeAsProduct } from './mongoose/schemas/product';
29
+ type IKeyOfProjection = keyof factory.product.IProduct | 'hasOfferCatalog.id';
30
30
  /**
31
31
  * プロダクト検索条件
32
32
  */
@@ -42,7 +42,7 @@ export declare class ProductRepo {
42
42
  /**
43
43
  * プロダクトを検索する
44
44
  */
45
- projectFields(conditions: ISearchConditions4product, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<(factory.product.IProduct & {
45
+ projectFields(conditions: ISearchConditions4product, inclusion: IKeyOfProjection[]): Promise<(factory.product.IProduct & {
46
46
  id: string;
47
47
  })[]>;
48
48
  deleteProductById(params: {
@@ -95,6 +95,9 @@ export declare class ProductRepo {
95
95
  typeOf: factory.service.paymentService.PaymentServiceType.PaymentCard;
96
96
  id: string;
97
97
  }): Promise<factory.product.IAvailableChannel>;
98
+ /**
99
+ * 指定カタログの設定されたプロダクトを削除する
100
+ */
98
101
  deleteByHasOfferCatalog(params: {
99
102
  project: {
100
103
  id: string;
@@ -120,5 +123,11 @@ export declare class ProductRepo {
120
123
  filter: FilterQuery<factory.product.IProduct>;
121
124
  $unset: any;
122
125
  }): Promise<import("mongoose").UpdateWriteOpResult>;
126
+ migrateHasOfferCatalogItemListElement(params: {
127
+ id: string;
128
+ hasOfferCatalog: {
129
+ id: string;
130
+ };
131
+ }): Promise<void>;
123
132
  }
124
133
  export {};
@@ -21,9 +21,9 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.ProductRepo = void 0;
24
- const product_1 = require("./mongoose/schemas/product");
25
24
  const factory = require("../factory");
26
25
  const settings_1 = require("../settings");
26
+ const product_1 = require("./mongoose/schemas/product");
27
27
  const AVAILABLE_PROJECT_FIELDS = [
28
28
  'project',
29
29
  'typeOf',
@@ -34,7 +34,8 @@ const AVAILABLE_PROJECT_FIELDS = [
34
34
  'name',
35
35
  'productID',
36
36
  'serviceOutput',
37
- 'serviceType'
37
+ 'serviceType',
38
+ 'hasOfferCatalog.id'
38
39
  ];
39
40
  /**
40
41
  * プロダクトリポジトリ
@@ -68,8 +69,15 @@ class ProductRepo {
68
69
  }
69
70
  const hasOfferCatalogIdEq = (_f = (_e = params.hasOfferCatalog) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
70
71
  if (typeof hasOfferCatalogIdEq === 'string') {
72
+ // migrate to itemListElement(2024-09-30~)
73
+ // andConditions.push({
74
+ // 'hasOfferCatalog.id': {
75
+ // $exists: true,
76
+ // $eq: hasOfferCatalogIdEq
77
+ // }
78
+ // });
71
79
  andConditions.push({
72
- 'hasOfferCatalog.id': {
80
+ 'hasOfferCatalog.itemListElement.id': {
73
81
  $exists: true,
74
82
  $eq: hasOfferCatalogIdEq
75
83
  }
@@ -165,7 +173,9 @@ class ProductRepo {
165
173
  /**
166
174
  * プロダクトを検索する
167
175
  */
168
- projectFields(conditions, inclusion, exclusion) {
176
+ projectFields(conditions, inclusion
177
+ // exclusion: IKeyOfProjection[] // discontinue(2024-09-28~)
178
+ ) {
169
179
  var _a;
170
180
  return __awaiter(this, void 0, void 0, function* () {
171
181
  const andConditions = ProductRepo.CREATE_MONGO_CONDITIONS(conditions);
@@ -174,28 +184,12 @@ class ProductRepo {
174
184
  positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
175
185
  }
176
186
  else {
177
- if (Array.isArray(exclusion) && exclusion.length > 0) {
178
- positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
179
- }
187
+ throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
188
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
189
+ // positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
190
+ // }
180
191
  }
181
192
  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
- // }
199
193
  const query = this.productModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
200
194
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
201
195
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
@@ -338,7 +332,9 @@ class ProductRepo {
338
332
  project: { id: { $eq: params.project.id } },
339
333
  typeOf: { $eq: factory.product.ProductType.PaymentCard },
340
334
  id: { $eq: params.id }
341
- }, ['availableChannel'], [])).shift();
335
+ }, ['availableChannel']
336
+ // []
337
+ )).shift();
342
338
  if (paymentService === undefined) {
343
339
  throw new factory.errors.NotFound('PaymentService');
344
340
  }
@@ -349,11 +345,15 @@ class ProductRepo {
349
345
  return availableChannel;
350
346
  });
351
347
  }
348
+ /**
349
+ * 指定カタログの設定されたプロダクトを削除する
350
+ */
352
351
  deleteByHasOfferCatalog(params) {
353
352
  return __awaiter(this, void 0, void 0, function* () {
354
353
  return this.productModel.deleteMany({
355
354
  'project.id': { $eq: params.project.id },
356
- 'hasOfferCatalog.id': { $exists: true, $eq: params.hasOfferCatalog.id }
355
+ // 'hasOfferCatalog.id': { $exists: true, $eq: params.hasOfferCatalog.id } // migrate to itemListElement(2024-09-30~)
356
+ 'hasOfferCatalog.itemListElement.id': { $exists: true, $eq: params.hasOfferCatalog.id }
357
357
  })
358
358
  .exec();
359
359
  });
@@ -382,5 +382,23 @@ class ProductRepo {
382
382
  .exec();
383
383
  });
384
384
  }
385
+ migrateHasOfferCatalogItemListElement(params) {
386
+ return __awaiter(this, void 0, void 0, function* () {
387
+ const offerCatalogItems = [{ id: params.hasOfferCatalog.id }];
388
+ const doc = yield this.productModel.findOneAndUpdate({
389
+ _id: { $eq: params.id },
390
+ 'hasOfferCatalog.id': { $exists: true, $eq: params.hasOfferCatalog.id }
391
+ }, {
392
+ $set: {
393
+ 'hasOfferCatalog.itemListElement': offerCatalogItems
394
+ }
395
+ }, { upsert: false, new: true, projection: { _id: 1, id: { $toString: '$_id' } } })
396
+ .lean()
397
+ .exec();
398
+ if (doc === null) {
399
+ throw new factory.errors.NotFound(this.productModel.modelName);
400
+ }
401
+ });
402
+ }
385
403
  }
386
404
  exports.ProductRepo = ProductRepo;
@@ -160,7 +160,7 @@ function aggregateOfferByEvent(params) {
160
160
  }
161
161
  function calculateOfferCount(params) {
162
162
  return (repos) => __awaiter(this, void 0, void 0, function* () {
163
- var _a, _b, _c;
163
+ var _a, _b, _c, _d;
164
164
  let offerCount = 0;
165
165
  try {
166
166
  const eventOffers = params.event.offers;
@@ -169,17 +169,21 @@ function calculateOfferCount(params) {
169
169
  limit: 1,
170
170
  page: 1,
171
171
  id: { $eq: eventOffers.itemOffered.id }
172
- }, ['hasOfferCatalog'], [])).shift();
172
+ }, ['hasOfferCatalog']
173
+ // []
174
+ )).shift();
173
175
  if (eventService === undefined) {
174
176
  throw new factory.errors.NotFound(factory.product.ProductType.EventService);
175
177
  }
176
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
178
+ // const firstCatalogIdOfProduct = eventService.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
179
+ const firstCatalogIdOfProduct = (_c = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.id;
180
+ if (typeof firstCatalogIdOfProduct === 'string') {
177
181
  const catalogs = yield repos.offerCatalog.search({
178
182
  limit: 1,
179
183
  page: 1,
180
- id: { $in: [eventService.hasOfferCatalog.id] }
184
+ id: { $in: [firstCatalogIdOfProduct] }
181
185
  });
182
- const numberOfItems = (_c = catalogs.shift()) === null || _c === void 0 ? void 0 : _c.numberOfItems;
186
+ const numberOfItems = (_d = catalogs.shift()) === null || _d === void 0 ? void 0 : _d.numberOfItems;
183
187
  if (typeof numberOfItems === 'number') {
184
188
  offerCount = numberOfItems;
185
189
  }
@@ -17,7 +17,7 @@ const factory = require("../../../factory");
17
17
  */
18
18
  function findEventOffers(params) {
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
- var _a, _b;
20
+ var _a, _b, _c;
21
21
  let availableOffers = [];
22
22
  try {
23
23
  // 興行設定があれば興行のカタログを参照する
@@ -27,11 +27,14 @@ function findEventOffers(params) {
27
27
  limit: 1,
28
28
  page: 1,
29
29
  id: { $eq: eventOffers.itemOffered.id }
30
- }, ['hasOfferCatalog'], [])).shift();
30
+ }, ['hasOfferCatalog']
31
+ // []
32
+ )).shift();
31
33
  if (eventService === undefined) {
32
34
  throw new factory.errors.NotFound(factory.product.ProductType.EventService);
33
35
  }
34
- const offerCatalogId = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id;
36
+ // const offerCatalogId = eventService.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
37
+ const offerCatalogId = (_c = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.id;
35
38
  if (typeof offerCatalogId === 'string') {
36
39
  // サブカタログIDを決定
37
40
  let subOfferCatalogId = offerCatalogId;
@@ -34,7 +34,9 @@ function start(params) {
34
34
  project: { id: { $eq: params.project.id } },
35
35
  typeOf: { $eq: factory.product.ProductType.PaymentCard },
36
36
  id: { $eq: issuedThroughId }
37
- }, [], []);
37
+ }, ['availableChannel', 'serviceOutput']
38
+ // []
39
+ );
38
40
  const product = products.shift();
39
41
  if (product === undefined) {
40
42
  throw new factory.errors.NotFound('Product');
@@ -274,7 +274,9 @@ function fixPaymentService(params) {
274
274
  project: { id: { $eq: params.project.id } },
275
275
  typeOf: { $eq: factory.product.ProductType.PaymentCard },
276
276
  id: { $eq: getPaymentServiceId(params) }
277
- }, [], [])).shift();
277
+ }, ['availableChannel', 'serviceOutput', 'serviceType']
278
+ // []
279
+ )).shift();
278
280
  if (paymentService === undefined) {
279
281
  throw new factory.errors.NotFound('PaymentService');
280
282
  }
@@ -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 | Pick<factory.service.paymentService.IService, 'availableChannel' | 'id' | 'typeOf' | 'serviceOutput'>;
9
+ paymentService?: Pick<factory.product.IProduct, 'availableChannel' | 'typeOf'> | Pick<factory.service.paymentService.IService, 'availableChannel' | 'id' | 'typeOf' | 'serviceOutput'>;
10
10
  }): factory.assetTransaction.IStartParams<factory.assetTransactionType.Refund>;
@@ -92,7 +92,9 @@ function fixPaymentService(params) {
92
92
  project: { id: { $eq: params.payAction.project.id } },
93
93
  typeOf: { $eq: factory.product.ProductType.PaymentCard },
94
94
  id: { $eq: paymentServiceId }
95
- }, [], [])).shift();
95
+ }, ['availableChannel', 'typeOf']
96
+ // []
97
+ )).shift();
96
98
  if (paymentService === undefined) {
97
99
  throw new factory.errors.NotFound('PaymentService');
98
100
  }
@@ -12,7 +12,7 @@ export declare function createPointAward(params: {
12
12
  */
13
13
  export declare function createServiceOutput(params: {
14
14
  dateIssued: Date;
15
- product: factory.product.IProduct & {
15
+ product: Pick<factory.product.IProduct, 'id' | 'typeOf' | 'project' | 'serviceOutput' | 'serviceType'> & {
16
16
  id: string;
17
17
  };
18
18
  acceptedOffer: factory.assetTransaction.registerService.IAcceptedOfferWithoutDetail;
@@ -48,7 +48,9 @@ function start(params) {
48
48
  limit: 1,
49
49
  page: 1,
50
50
  id: { $eq: productId }
51
- }, [], [])).shift();
51
+ }, ['id', 'project', 'serviceOutput', 'serviceType', 'typeOf']
52
+ // []
53
+ )).shift();
52
54
  if (product === undefined) {
53
55
  throw new factory.errors.NotFound('Product');
54
56
  }
@@ -141,7 +143,9 @@ function createPermitService(params) {
141
143
  limit: 1,
142
144
  page: 1,
143
145
  id: { $eq: params.issuedThrough.id }
144
- }, ['availableChannel'], [])).shift();
146
+ }, ['availableChannel']
147
+ // []
148
+ )).shift();
145
149
  if (product === undefined) {
146
150
  throw new factory.errors.NotFound('Product');
147
151
  }
@@ -299,7 +299,9 @@ function validateProgramMembershipUsed(params) {
299
299
  page: 1,
300
300
  id: { $eq: issuedThroughId },
301
301
  typeOf: { $eq: factory.product.ProductType.MembershipService }
302
- }, ['typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
302
+ }, ['typeOf', 'project', 'serviceType', 'serviceOutput']
303
+ // []
304
+ )).shift();
303
305
  if (permitIssuedThrough === undefined) {
304
306
  throw new factory.errors.NotFound(factory.product.ProductType.MembershipService);
305
307
  }
@@ -414,7 +416,9 @@ function createPermitService(params) {
414
416
  limit: 1,
415
417
  page: 1,
416
418
  id: { $eq: params.issuedThrough.id }
417
- }, ['availableChannel'], [])).shift();
419
+ }, ['availableChannel']
420
+ // []
421
+ )).shift();
418
422
  if (product === undefined) {
419
423
  throw new factory.errors.NotFound('Product');
420
424
  }
@@ -409,7 +409,9 @@ function createPermitService(params) {
409
409
  limit: 1,
410
410
  page: 1,
411
411
  id: { $eq: params.issuedThrough.id }
412
- }, ['availableChannel'], [])).shift();
412
+ }, ['availableChannel']
413
+ // []
414
+ )).shift();
413
415
  if (product === undefined) {
414
416
  throw new factory.errors.NotFound('Product');
415
417
  }
@@ -334,7 +334,9 @@ function createPermitServiceCredentials(params) {
334
334
  page: 1,
335
335
  id: { $eq: params.issuedThrough.id },
336
336
  typeOf: { $eq: factory.product.ProductType.PaymentCard }
337
- }, ['availableChannel'], [])).shift();
337
+ }, ['availableChannel']
338
+ // []
339
+ )).shift();
338
340
  if (paymentCardService === undefined) {
339
341
  throw new factory.errors.NotFound(factory.product.ProductType.PaymentCard);
340
342
  }
@@ -17,18 +17,22 @@ const factory_1 = require("../factory");
17
17
  function searchTicketOffersByItemOffered(params) {
18
18
  // tslint:disable-next-line:max-func-body-length
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
- var _a, _b, _c, _d, _e, _f, _g;
20
+ var _a, _b, _c, _d, _e, _f, _g, _h;
21
21
  let catalogId;
22
22
  const eventService = (yield repos.product.projectFields({
23
23
  limit: 1,
24
24
  page: 1,
25
25
  id: { $eq: String((_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.id) }
26
- }, ['hasOfferCatalog', 'project'], [])).shift();
26
+ }, ['hasOfferCatalog', 'project']
27
+ // []
28
+ )).shift();
27
29
  if (eventService === undefined) {
28
30
  throw new factory.errors.NotFound(factory.product.ProductType.EventService);
29
31
  }
30
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
31
- catalogId = eventService.hasOfferCatalog.id;
32
+ // const firstCatalogIdOfProduct = eventService.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
33
+ const firstCatalogIdOfProduct = (_c = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.id;
34
+ if (typeof firstCatalogIdOfProduct === 'string') {
35
+ catalogId = firstCatalogIdOfProduct;
32
36
  }
33
37
  if (typeof catalogId !== 'string') {
34
38
  throw new factory.errors.NotFound('itemOffered.hasOfferCatalog');
@@ -47,7 +51,7 @@ function searchTicketOffersByItemOffered(params) {
47
51
  throw new factory.errors.NotImplemented('id specification on addSortIndex not implemented');
48
52
  }
49
53
  // 明示的にカタログ指定可能にする
50
- if (typeof ((_c = params.includedInDataCatalog) === null || _c === void 0 ? void 0 : _c.id) === 'string' && params.includedInDataCatalog.id.length > 0) {
54
+ if (typeof ((_d = params.includedInDataCatalog) === null || _d === void 0 ? void 0 : _d.id) === 'string' && params.includedInDataCatalog.id.length > 0) {
51
55
  if (isOfferCatalogItem) {
52
56
  // no op
53
57
  }
@@ -67,7 +71,7 @@ function searchTicketOffersByItemOffered(params) {
67
71
  throw new factory.errors.NotFound('OfferCatalogItem');
68
72
  }
69
73
  // 強制的にサブカタログの適用決済カード条件に変更
70
- const appliesToMovieTicketBySubCatalog = (_e = (_d = offerCatalogItem.relatedOffer) === null || _d === void 0 ? void 0 : _d.priceSpecification) === null || _e === void 0 ? void 0 : _e.appliesToMovieTicket;
74
+ const appliesToMovieTicketBySubCatalog = (_f = (_e = offerCatalogItem.relatedOffer) === null || _e === void 0 ? void 0 : _e.priceSpecification) === null || _f === void 0 ? void 0 : _f.appliesToMovieTicket;
71
75
  if (Array.isArray(appliesToMovieTicketBySubCatalog)) {
72
76
  priceSpecificationCondition = {
73
77
  appliesToMovieTicket: {
@@ -88,7 +92,7 @@ function searchTicketOffersByItemOffered(params) {
88
92
  }
89
93
  const { offers, sortedOfferIds } = yield repos.offer.searchByOfferCatalogIdWithSortIndex({
90
94
  offerCatalog: { id: subOfferCatalogId, isOfferCatalogItem },
91
- availableAtOrFrom: { id: (_f = params.store) === null || _f === void 0 ? void 0 : _f.id },
95
+ availableAtOrFrom: { id: (_g = params.store) === null || _g === void 0 ? void 0 : _g.id },
92
96
  unacceptedPaymentMethod: params.unacceptedPaymentMethod,
93
97
  excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket,
94
98
  priceSpecification: priceSpecificationCondition,
@@ -116,7 +120,7 @@ function searchTicketOffersByItemOffered(params) {
116
120
  const availableOffers = yield repos.offer.searchAllByIdsAndOfferCatalogId({
117
121
  ids: params.ids,
118
122
  includedInDataCatalog: { id: includedInDataCatalogIds, isOfferCatalogItem },
119
- availableAtOrFrom: { id: (_g = params.store) === null || _g === void 0 ? void 0 : _g.id },
123
+ availableAtOrFrom: { id: (_h = params.store) === null || _h === void 0 ? void 0 : _h.id },
120
124
  unacceptedPaymentMethod: params.unacceptedPaymentMethod,
121
125
  excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket,
122
126
  onlyValid: params.onlyValid === true
@@ -352,7 +356,7 @@ exports.searchEventTicketOffers = searchEventTicketOffers;
352
356
  */
353
357
  function searchOfferAppliesToMovieTicket(params) {
354
358
  return (repos) => __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b, _c;
359
+ var _a, _b, _c, _d;
356
360
  // optimize(2024-07-18~)
357
361
  const event = yield repos.event.projectEventFieldsById({ id: params.event.id }, ['project', 'startDate', 'typeOf', 'superEvent.id', 'offers.itemOffered.id', 'offers.unacceptedPaymentMethod']);
358
362
  // let soundFormatTypes: string[] = [];
@@ -382,12 +386,16 @@ function searchOfferAppliesToMovieTicket(params) {
382
386
  limit: 1,
383
387
  page: 1,
384
388
  id: { $eq: eventOffers.itemOffered.id }
385
- }, ['hasOfferCatalog'], [])).shift();
389
+ }, ['hasOfferCatalog']
390
+ // []
391
+ )).shift();
386
392
  if (eventService === undefined) {
387
393
  throw new factory.errors.NotFound(factory.product.ProductType.EventService);
388
394
  }
389
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
390
- catalogId = eventService.hasOfferCatalog.id;
395
+ // const firstCatalogIdOfProduct = eventService.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
396
+ const firstCatalogIdOfProduct = (_c = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.id;
397
+ if (typeof firstCatalogIdOfProduct === 'string') {
398
+ catalogId = firstCatalogIdOfProduct;
391
399
  }
392
400
  }
393
401
  if (typeof catalogId !== 'string') {
@@ -404,7 +412,7 @@ function searchOfferAppliesToMovieTicket(params) {
404
412
  return repos.offer.searchAvaialbleAppliesToMovieTicketByOfferCatalogId({
405
413
  // subOfferCatalog: { id: subOfferCatalogId, isOfferCatalogItem },
406
414
  subOfferCatalog: { id: subOfferCatalogId },
407
- availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
415
+ availableAtOrFrom: { id: (_d = params.store) === null || _d === void 0 ? void 0 : _d.id },
408
416
  unacceptedPaymentMethod: unacceptedPaymentMethod,
409
417
  excludeAppliesToMovieTicket: excludeAppliesToMovieTicket,
410
418
  onlyValid: params.onlyValid === true,
@@ -420,7 +428,7 @@ exports.searchOfferAppliesToMovieTicket = searchOfferAppliesToMovieTicket;
420
428
  */
421
429
  function searchOfferCatalogItems(params) {
422
430
  return (repos) => __awaiter(this, void 0, void 0, function* () {
423
- var _a, _b;
431
+ var _a, _b, _c;
424
432
  if (typeof params.limit !== 'number') {
425
433
  throw new factory.errors.Argument('limit', 'must be number');
426
434
  }
@@ -438,12 +446,16 @@ function searchOfferCatalogItems(params) {
438
446
  limit: 1,
439
447
  page: 1,
440
448
  id: { $eq: eventOffers.itemOffered.id }
441
- }, ['hasOfferCatalog'], [])).shift();
449
+ }, ['hasOfferCatalog']
450
+ // []
451
+ )).shift();
442
452
  if (eventService === undefined) {
443
453
  throw new factory.errors.NotFound(factory.product.ProductType.EventService);
444
454
  }
445
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
446
- catalogId = eventService.hasOfferCatalog.id;
455
+ // const firstCatalogIdOfProduct = eventService.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
456
+ const firstCatalogIdOfProduct = (_c = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.id;
457
+ if (typeof firstCatalogIdOfProduct === 'string') {
458
+ catalogId = firstCatalogIdOfProduct;
447
459
  }
448
460
  }
449
461
  if (typeof catalogId !== 'string') {
@@ -488,7 +500,7 @@ exports.searchOfferCatalogItems = searchOfferCatalogItems;
488
500
  */
489
501
  function searchOfferCatalogItemAvailability(params) {
490
502
  return (repos) => __awaiter(this, void 0, void 0, function* () {
491
- var _a, _b;
503
+ var _a, _b, _c;
492
504
  const { considerUnacceptedPaymentMethod } = params.options;
493
505
  if (typeof params.limit !== 'number') {
494
506
  throw new factory.errors.Argument('limit', 'must be number');
@@ -507,12 +519,16 @@ function searchOfferCatalogItemAvailability(params) {
507
519
  limit: 1,
508
520
  page: 1,
509
521
  id: { $eq: eventOffers.itemOffered.id }
510
- }, ['hasOfferCatalog'], [])).shift();
522
+ }, ['hasOfferCatalog']
523
+ // []
524
+ )).shift();
511
525
  if (eventService === undefined) {
512
526
  throw new factory.errors.NotFound(factory.product.ProductType.EventService);
513
527
  }
514
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
515
- catalogId = eventService.hasOfferCatalog.id;
528
+ // const firstCatalogIdOfProduct = eventService.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
529
+ const firstCatalogIdOfProduct = (_c = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.id;
530
+ if (typeof firstCatalogIdOfProduct === 'string') {
531
+ catalogId = firstCatalogIdOfProduct;
516
532
  }
517
533
  }
518
534
  if (typeof catalogId !== 'string') {
@@ -17,17 +17,20 @@ const factory = require("../../../factory");
17
17
  function searchProductOffers(params) {
18
18
  // tslint:disable-next-line:max-func-body-length
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
- var _a, _b;
20
+ var _a, _b, _c;
21
21
  // プロダクト検索
22
22
  const productWithOffers = (yield repos.product.projectFields({
23
23
  limit: 1,
24
24
  page: 1,
25
25
  id: { $eq: params.itemOffered.id }
26
- }, ['hasOfferCatalog', 'project'], [])).shift();
26
+ }, ['hasOfferCatalog', 'project']
27
+ // []
28
+ )).shift();
27
29
  if (productWithOffers === undefined) {
28
30
  throw new factory.errors.NotFound('Product');
29
31
  }
30
- const offerCatalogId = (_a = productWithOffers.hasOfferCatalog) === null || _a === void 0 ? void 0 : _a.id;
32
+ // const offerCatalogId = productWithOffers.hasOfferCatalog?.id; // migrate to itemListElement(2024-09-30~)
33
+ const offerCatalogId = (_b = (_a = productWithOffers.hasOfferCatalog) === null || _a === void 0 ? void 0 : _a.itemListElement.at(0)) === null || _b === void 0 ? void 0 : _b.id;
31
34
  if (typeof offerCatalogId !== 'string') {
32
35
  return [];
33
36
  }
@@ -47,7 +50,7 @@ function searchProductOffers(params) {
47
50
  throw new factory.errors.NotImplemented('id specification on addSortIndex not implemented');
48
51
  }
49
52
  // 明示的にカタログ指定可能にする
50
- if (typeof ((_b = params.includedInDataCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string' && params.includedInDataCatalog.id.length > 0) {
53
+ if (typeof ((_c = params.includedInDataCatalog) === null || _c === void 0 ? void 0 : _c.id) === 'string' && params.includedInDataCatalog.id.length > 0) {
51
54
  if (isOfferCatalogItem) {
52
55
  // no op
53
56
  }
@@ -68,7 +68,7 @@ export declare function search(params: {
68
68
  productOffer: ProductOfferRepo;
69
69
  }) => Promise<{
70
70
  offers: factory.product.ITicketOffer[];
71
- product: factory.product.IProduct;
71
+ product: Pick<factory.product.IProduct, "id" | "project" | "name" | "typeOf" | "description" | "serviceType" | "serviceOutput" | "productID">;
72
72
  }>;
73
73
  export type IAuthorizeOfferAction = factory.action.authorize.offer.product.IAction;
74
74
  /**
@@ -32,7 +32,9 @@ function search(params) {
32
32
  page: 1,
33
33
  project: { id: { $eq: params.project.id } },
34
34
  id: { $eq: params.itemOffered.id }
35
- }, [], []);
35
+ }, ['id', 'name', 'productID', 'project', 'serviceOutput', 'serviceType', 'typeOf', 'description']
36
+ // []
37
+ );
36
38
  const product = searchProductsResult.shift();
37
39
  if (product === undefined) {
38
40
  throw new factory.errors.NotFound('Product');
@@ -179,7 +181,9 @@ function fixProductAndOffers(params) {
179
181
  page: 1,
180
182
  project: { id: { $eq: params.project.id } },
181
183
  id: { $eq: productId }
182
- }, [], []);
184
+ }, ['id', 'name', 'productID', 'project', 'serviceOutput', 'serviceType', 'typeOf']
185
+ // []
186
+ );
183
187
  const product = searchProductsResult.shift();
184
188
  if (product === undefined) {
185
189
  throw new factory.errors.NotFound('Product');
@@ -84,7 +84,9 @@ function validatePaymentMethod(params, paymentServiceId) {
84
84
  page: 1,
85
85
  id: { $eq: paymentServiceId },
86
86
  typeOf: { $eq: factory.product.ProductType.PaymentCard }
87
- }, ['serviceOutput'], [])).shift();
87
+ }, ['serviceOutput']
88
+ // []
89
+ )).shift();
88
90
  const currency = (_e = (_d = paymentCatdProduct === null || paymentCatdProduct === void 0 ? void 0 : paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
89
91
  if (typeof currency !== 'string') {
90
92
  throw new factory.errors.NotFound('product.serviceOutput.amount.currency');
@@ -351,7 +351,9 @@ function deleteResourcesByOfferCatalog(params) {
351
351
  const productsWithCatalog = yield repos.product.projectFields({
352
352
  project: { id: { $eq: params.project.id } },
353
353
  hasOfferCatalog: { id: { $eq: catalogId } }
354
- }, ['id'], []);
354
+ }, ['id']
355
+ // []
356
+ );
355
357
  let deleteEventResult;
356
358
  let updateOfferResult;
357
359
  if (productsWithCatalog.length > 0) {
@@ -276,7 +276,9 @@ function createInformProductTasks(params) {
276
276
  const products4inform = yield repos.product.projectFields({
277
277
  typeOf: { $eq: params.typeOf },
278
278
  id: { $in: params.ids }
279
- }, ['additionalProperty', 'description', 'name', 'productID', 'project', 'typeOf', 'serviceType'], []);
279
+ }, ['additionalProperty', 'description', 'name', 'productID', 'project', 'typeOf', 'serviceType']
280
+ // []
281
+ );
280
282
  const informResources = settings.onResourceUpdated.informResource;
281
283
  if (products4inform.length > 0) {
282
284
  const taskRunsAt = new Date();
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.385.0",
13
- "@cinerino/sdk": "10.11.0",
12
+ "@chevre/factory": "4.386.0-alpha.0",
13
+ "@cinerino/sdk": "10.12.0-alpha.0",
14
14
  "@motionpicture/coa-service": "9.5.0",
15
15
  "@motionpicture/gmo-service": "5.3.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "22.5.0-alpha.0"
113
+ "version": "22.5.0-alpha.2"
114
114
  }
@@ -1,70 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- // const project = { id: String(process.env.PROJECT_ID) };
7
-
8
- // tslint:disable-next-line:max-func-body-length
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
13
-
14
- const cursor = eventSeriesRepo.getCursor(
15
- {
16
- typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries }
17
- },
18
- {
19
- _id: 1,
20
- startDate: 1,
21
- project: 1,
22
- typeOf: 1
23
- }
24
- );
25
- console.log('docs found');
26
-
27
- let i = 0;
28
- let updateCount = 0;
29
- await cursor.eachAsync(async (doc) => {
30
- i += 1;
31
- const eventSeries: Pick<chevre.factory.event.screeningEventSeries.IEvent, 'id' | 'startDate' | 'project' | 'typeOf'> =
32
- doc.toObject();
33
- const alreadyMigrated = false;
34
- if (alreadyMigrated) {
35
- console.log(
36
- 'already exist.',
37
- eventSeries.project.id,
38
- eventSeries.typeOf,
39
- eventSeries.id,
40
- eventSeries.startDate, i, updateCount
41
- );
42
- } else {
43
- updateCount += 1;
44
- console.log(
45
- 'updating...',
46
- eventSeries.project.id,
47
- eventSeries.typeOf,
48
- eventSeries.id,
49
- eventSeries.startDate, i, updateCount
50
- );
51
- // await eventSeriesRepo.sync2secondary({
52
- // id: eventSeries.id
53
- // });
54
- console.log(
55
- 'updated.',
56
- eventSeries.project.id,
57
- eventSeries.typeOf,
58
- eventSeries.id,
59
- eventSeries.startDate, i, updateCount
60
- );
61
- }
62
- });
63
-
64
- console.log(i, 'docs checked');
65
- console.log(updateCount, 'docs updated');
66
- }
67
-
68
- main()
69
- .then()
70
- .catch(console.error);