@chevre/domain 21.2.0-alpha.131 → 21.2.0-alpha.132

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.
@@ -0,0 +1,38 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const PROJECT_ID = process.env.PROJECT_ID;
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
+
11
+ const productRepo = new chevre.repository.Product(mongoose.connection);
12
+
13
+ const providers = await productRepo.searchProviders({
14
+ project: { id: { $eq: PROJECT_ID } },
15
+ id: 'xxx'
16
+ });
17
+ console.log(providers);
18
+ console.log(providers[0]?.credentials);
19
+ console.log(providers.length);
20
+
21
+ const paymentServices = await productRepo.searchPaymentServicesByProvider(
22
+ {
23
+ limit: 10,
24
+ page: 1,
25
+ sort: { productID: chevre.factory.sortType.Descending },
26
+ project: { id: { $eq: PROJECT_ID } },
27
+ typeOf: { $eq: chevre.factory.service.paymentService.PaymentServiceType.CreditCard },
28
+ provider: { id: { $eq: 'xxx' } }
29
+ }
30
+ );
31
+ console.log(paymentServices);
32
+ console.log(paymentServices[0]?.provider?.credentials);
33
+ console.log(paymentServices.length);
34
+ }
35
+
36
+ main()
37
+ .then(console.log)
38
+ .catch(console.error);
@@ -100,3 +100,9 @@ schema.index({ 'name.en': 1, productID: 1 }, {
100
100
  'name.en': { $exists: true }
101
101
  }
102
102
  });
103
+ schema.index({ 'provider.id': 1, productID: 1 }, {
104
+ name: 'searchByProviderId',
105
+ partialFilterExpression: {
106
+ 'provider.id': { $exists: true }
107
+ }
108
+ });
@@ -25,6 +25,9 @@
25
25
  import { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  export type IProduct = factory.product.IProduct | factory.service.paymentService.IService;
28
+ export type IPaymentServiceByProvider = Pick<factory.service.paymentService.IService, 'name' | 'description' | 'typeOf' | 'id' | 'productID' | 'serviceType' | 'additionalProperty'> & {
29
+ provider?: Pick<factory.service.paymentService.IProvider, 'credentials'>;
30
+ };
28
31
  /**
29
32
  * プロダクトリポジトリ
30
33
  */
@@ -51,6 +54,20 @@ export declare class MongoRepository {
51
54
  typeOf: factory.service.paymentService.PaymentServiceType;
52
55
  id: string;
53
56
  }): Promise<factory.product.IAvailableChannel>;
57
+ searchPaymentServicesByProvider(params: Pick<factory.product.ISearchConditions, 'limit' | 'page' | 'sort' | 'project' | 'provider' | 'typeOf'>): Promise<IPaymentServiceByProvider[]>;
58
+ /**
59
+ * 決済サービスのプロバイダー検索
60
+ */
61
+ searchProviders(params: {
62
+ limit?: number;
63
+ page?: number;
64
+ project?: {
65
+ id?: {
66
+ $eq?: string;
67
+ };
68
+ };
69
+ id: string;
70
+ }): Promise<factory.service.paymentService.IProvider[]>;
54
71
  /**
55
72
  * プロダクトを保管する
56
73
  * 作成 or 更新
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
+ const mongoose_1 = require("mongoose");
24
25
  const product_1 = require("./mongoose/schemas/product");
25
26
  const factory = require("../factory");
26
27
  const settings_1 = require("../settings");
@@ -33,7 +34,7 @@ class MongoRepository {
33
34
  }
34
35
  // tslint:disable-next-line:max-func-body-length
35
36
  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;
37
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
37
38
  // MongoDB検索条件
38
39
  const andConditions = [];
39
40
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -144,6 +145,11 @@ class MongoRepository {
144
145
  ]
145
146
  });
146
147
  }
148
+ // プロバイダー条件を追加(2023-06-21~)
149
+ const providerIdEq = (_x = (_w = params.provider) === null || _w === void 0 ? void 0 : _w.id) === null || _x === void 0 ? void 0 : _x.$eq;
150
+ if (typeof providerIdEq === 'string') {
151
+ andConditions.push({ 'provider.id': { $exists: true, $eq: providerIdEq } });
152
+ }
147
153
  return andConditions;
148
154
  }
149
155
  findById(conditions, projection) {
@@ -225,6 +231,113 @@ class MongoRepository {
225
231
  return availableChannel;
226
232
  });
227
233
  }
234
+ searchPaymentServicesByProvider(params) {
235
+ var _a, _b, _c, _d, _e, _f;
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ const matchStages = [];
238
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
239
+ if (typeof projectIdEq === 'string') {
240
+ matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
241
+ }
242
+ const typeOfEq = (_c = params.typeOf) === null || _c === void 0 ? void 0 : _c.$eq;
243
+ if (typeof typeOfEq === 'string') {
244
+ matchStages.push({ $match: { typeOf: { $eq: typeOfEq } } });
245
+ }
246
+ const providerIdEq = (_e = (_d = params.provider) === null || _d === void 0 ? void 0 : _d.id) === null || _e === void 0 ? void 0 : _e.$eq;
247
+ if (typeof providerIdEq === 'string') {
248
+ matchStages.push({ $match: { 'provider.id': { $exists: true, $eq: providerIdEq } } });
249
+ }
250
+ const aggregate = this.productModel.aggregate([
251
+ ...(typeof ((_f = params.sort) === null || _f === void 0 ? void 0 : _f.productID) === 'number')
252
+ ? [{ $sort: { productID: params.sort.productID } }]
253
+ : [],
254
+ {
255
+ $unwind: {
256
+ path: '$provider'
257
+ }
258
+ },
259
+ ...matchStages,
260
+ {
261
+ $project: {
262
+ _id: 0,
263
+ typeOf: '$typeOf',
264
+ productID: '$productID',
265
+ description: '$description',
266
+ name: '$name',
267
+ // provider: [ [Object] ],
268
+ additionalProperty: '$additionalProperty',
269
+ serviceType: '$serviceType',
270
+ id: { $toString: '$_id' },
271
+ // ↓セキュアな情報を隠蔽するように
272
+ provider: {
273
+ credentials: {
274
+ shopId: '$provider.credentials.shopId',
275
+ tokenizationCode: '$provider.credentials.tokenizationCode',
276
+ paymentUrl: {
277
+ expiresInSeconds: '$provider.credentials.paymentUrl.expiresInSeconds',
278
+ useCallback: '$provider.credentials.paymentUrl.useCallback',
279
+ useWebhook: '$provider.credentials.paymentUrl.useWebhook'
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ ]);
286
+ if (typeof params.limit === 'number' && params.limit > 0) {
287
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
288
+ aggregate.limit(params.limit * page)
289
+ .skip(params.limit * (page - 1));
290
+ }
291
+ return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
292
+ .exec();
293
+ });
294
+ }
295
+ /**
296
+ * 決済サービスのプロバイダー検索
297
+ */
298
+ searchProviders(params) {
299
+ var _a, _b;
300
+ return __awaiter(this, void 0, void 0, function* () {
301
+ const matchStages = [];
302
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
303
+ if (typeof projectIdEq === 'string') {
304
+ matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
305
+ }
306
+ matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.id) } } });
307
+ const aggregate = this.productModel.aggregate([
308
+ {
309
+ $unwind: {
310
+ path: '$provider'
311
+ }
312
+ },
313
+ ...matchStages,
314
+ {
315
+ $project: {
316
+ _id: 0,
317
+ // ↓セキュアな情報を隠蔽するように
318
+ credentials: {
319
+ shopId: '$provider.credentials.shopId',
320
+ tokenizationCode: '$provider.credentials.tokenizationCode',
321
+ paymentUrl: {
322
+ expiresInSeconds: '$provider.credentials.paymentUrl.expiresInSeconds',
323
+ useCallback: '$provider.credentials.paymentUrl.useCallback',
324
+ useWebhook: '$provider.credentials.paymentUrl.useWebhook'
325
+ }
326
+ },
327
+ id: '$provider.id',
328
+ name: '$provider.name'
329
+ }
330
+ }
331
+ ]);
332
+ if (typeof params.limit === 'number' && params.limit > 0) {
333
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
334
+ aggregate.limit(params.limit * page)
335
+ .skip(params.limit * (page - 1));
336
+ }
337
+ return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
338
+ .exec();
339
+ });
340
+ }
228
341
  /**
229
342
  * プロダクトを保管する
230
343
  * 作成 or 更新
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.39",
12
+ "@chevre/factory": "4.313.0-alpha.40",
13
13
  "@cinerino/sdk": "3.157.0-alpha.16",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.131"
120
+ "version": "21.2.0-alpha.132"
121
121
  }