@chevre/domain 20.4.0-alpha.3 → 20.4.0-alpha.4

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.
@@ -45,16 +45,6 @@ export declare class MongoRepository {
45
45
  /**
46
46
  * 口座を解約する
47
47
  */
48
- close(params: {
49
- /**
50
- * 口座番号
51
- */
52
- accountNumber: string;
53
- /**
54
- * 解約日時
55
- */
56
- closeDate: Date;
57
- }): Promise<void>;
58
48
  /**
59
49
  * 口座番号で検索する
60
50
  */
@@ -10,11 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = exports.modelName = void 0;
13
- const createDebug = require("debug");
14
13
  const account_1 = require("./mongoose/model/account");
15
14
  Object.defineProperty(exports, "modelName", { enumerable: true, get: function () { return account_1.modelName; } });
16
15
  const factory = require("../factory");
17
- const debug = createDebug('chevre-domain:repository');
18
16
  /**
19
17
  * 口座リポジトリ
20
18
  */
@@ -93,11 +91,11 @@ class MongoRepository {
93
91
  }
94
92
  // tslint:disable-next-line:no-single-line-block-comment
95
93
  /* istanbul ignore else */
96
- if (Array.isArray(params.statuses) && params.statuses.length > 0) {
97
- andConditions.push({
98
- status: { $in: params.statuses }
99
- });
100
- }
94
+ // if (Array.isArray(params.statuses) && params.statuses.length > 0) {
95
+ // andConditions.push({
96
+ // status: { $in: params.statuses }
97
+ // });
98
+ // }
101
99
  const nameRegex = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$regex;
102
100
  // tslint:disable-next-line:no-single-line-block-comment
103
101
  /* istanbul ignore else */
@@ -159,8 +157,8 @@ class MongoRepository {
159
157
  balance: p.initialBalance,
160
158
  availableBalance: p.initialBalance,
161
159
  pendingTransactions: [],
162
- openDate: p.openDate,
163
- status: factory.account.AccountStatusType.Opened
160
+ openDate: p.openDate
161
+ // status: factory.account.AccountStatusType.Opened
164
162
  };
165
163
  });
166
164
  // const doc = await this.accountModel.create(account);
@@ -179,39 +177,47 @@ class MongoRepository {
179
177
  /**
180
178
  * 口座を解約する
181
179
  */
182
- close(params) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- debug('closing account...');
185
- const doc = yield this.accountModel.findOneAndUpdate({
186
- accountNumber: params.accountNumber,
187
- pendingTransactions: { $size: 0 },
188
- status: factory.account.AccountStatusType.Opened
189
- }, {
190
- closeDate: params.closeDate,
191
- status: factory.account.AccountStatusType.Closed
192
- }, {
193
- new: true
194
- })
195
- .exec();
196
- // NotFoundであれば口座状態確認
197
- if (doc === null) {
198
- const account = yield this.findByAccountNumber({
199
- accountNumber: params.accountNumber
200
- });
201
- if (account.status === factory.account.AccountStatusType.Closed) {
202
- // すでに口座解約済の場合
203
- return;
204
- }
205
- else if (Array.isArray(account.pendingTransactions) && account.pendingTransactions.length > 0) {
206
- // 進行中取引が存在する場合の場合
207
- throw new factory.errors.Argument('accountNumber', 'Pending transactions exist');
208
- }
209
- else {
210
- throw new factory.errors.NotFound(this.accountModel.modelName);
211
- }
212
- }
213
- });
214
- }
180
+ // public async close(params: {
181
+ // /**
182
+ // * 口座番号
183
+ // */
184
+ // accountNumber: string;
185
+ // /**
186
+ // * 解約日時
187
+ // */
188
+ // closeDate: Date;
189
+ // }) {
190
+ // const doc = await this.accountModel.findOneAndUpdate(
191
+ // {
192
+ // accountNumber: params.accountNumber,
193
+ // pendingTransactions: { $size: 0 },
194
+ // status: factory.account.AccountStatusType.Opened
195
+ // },
196
+ // {
197
+ // closeDate: params.closeDate,
198
+ // status: factory.account.AccountStatusType.Closed
199
+ // },
200
+ // {
201
+ // new: true
202
+ // }
203
+ // )
204
+ // .exec();
205
+ // // NotFoundであれば口座状態確認
206
+ // if (doc === null) {
207
+ // const account = await this.findByAccountNumber({
208
+ // accountNumber: params.accountNumber
209
+ // });
210
+ // if (account.status === factory.account.AccountStatusType.Closed) {
211
+ // // すでに口座解約済の場合
212
+ // return;
213
+ // } else if (Array.isArray(account.pendingTransactions) && account.pendingTransactions.length > 0) {
214
+ // // 進行中取引が存在する場合の場合
215
+ // throw new factory.errors.Argument('accountNumber', 'Pending transactions exist');
216
+ // } else {
217
+ // throw new factory.errors.NotFound(this.accountModel.modelName);
218
+ // }
219
+ // }
220
+ // }
215
221
  /**
216
222
  * 口座番号で検索する
217
223
  */
@@ -233,7 +239,7 @@ class MongoRepository {
233
239
  */
234
240
  authorizeAmount(params) {
235
241
  return __awaiter(this, void 0, void 0, function* () {
236
- const doc = yield this.accountModel.findOneAndUpdate(Object.assign({ accountNumber: params.accountNumber, status: factory.account.AccountStatusType.Opened }, (params.force === true) ? undefined : { availableBalance: { $gte: params.amount } } // 利用可能金額確認
242
+ const doc = yield this.accountModel.findOneAndUpdate(Object.assign({ accountNumber: params.accountNumber }, (params.force === true) ? undefined : { availableBalance: { $gte: params.amount } } // 利用可能金額確認
237
243
  ), {
238
244
  $inc: { availableBalance: -params.amount },
239
245
  $push: { pendingTransactions: params.transaction } // 進行中取引追加
@@ -244,11 +250,11 @@ class MongoRepository {
244
250
  const account = yield this.findByAccountNumber({
245
251
  accountNumber: params.accountNumber
246
252
  });
247
- if (account.status === factory.account.AccountStatusType.Closed) {
248
- // 口座解約済の場合
249
- throw new factory.errors.Argument('accountNumber', 'Account already closed');
250
- }
251
- else if (typeof account.availableBalance === 'number' && account.availableBalance < params.amount) {
253
+ // if (account.status === factory.account.AccountStatusType.Closed) {
254
+ // // 口座解約済の場合
255
+ // throw new factory.errors.Argument('accountNumber', 'Account already closed');
256
+ // } else
257
+ if (typeof account.availableBalance === 'number' && account.availableBalance < params.amount) {
252
258
  // 残高不足の場合
253
259
  throw new factory.errors.Argument('accountNumber', 'Insufficient balance');
254
260
  }
@@ -264,22 +270,22 @@ class MongoRepository {
264
270
  startTransaction(params) {
265
271
  return __awaiter(this, void 0, void 0, function* () {
266
272
  const doc = yield this.accountModel.findOneAndUpdate({
267
- accountNumber: params.accountNumber,
268
- status: factory.account.AccountStatusType.Opened // 開いている口座
273
+ accountNumber: params.accountNumber
274
+ // status: factory.account.AccountStatusType.Opened // 開いている口座
269
275
  }, { $push: { pendingTransactions: params.transaction } })
270
276
  .exec();
271
277
  // NotFoundであれば口座状態確認
272
278
  if (doc === null) {
273
- const account = yield this.findByAccountNumber({
274
- accountNumber: params.accountNumber
275
- });
276
- if (account.status === factory.account.AccountStatusType.Closed) {
277
- // 口座解約済の場合
278
- throw new factory.errors.Argument('accountNumber', 'Account already closed');
279
- }
280
- else {
281
- throw new factory.errors.NotFound(this.accountModel.modelName);
282
- }
279
+ // const account = await this.findByAccountNumber({
280
+ // accountNumber: params.accountNumber
281
+ // });
282
+ // if (account.status === factory.account.AccountStatusType.Closed) {
283
+ // // 口座解約済の場合
284
+ // throw new factory.errors.Argument('accountNumber', 'Account already closed');
285
+ // } else {
286
+ // throw new factory.errors.NotFound(this.accountModel.modelName);
287
+ // }
288
+ throw new factory.errors.NotFound(this.accountModel.modelName);
283
289
  }
284
290
  });
285
291
  }
@@ -37,14 +37,6 @@ export declare function open(params: {
37
37
  /**
38
38
  * 口座を解約する
39
39
  */
40
- export declare function close(params: {
41
- /**
42
- * 口座番号
43
- */
44
- accountNumber: string;
45
- }): (repos: {
46
- account: AccountRepo;
47
- }) => Promise<void>;
48
40
  /**
49
41
  * 転送する
50
42
  * 確定取引結果から、実際の転送アクションを実行します。
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.cancelMoneyTransfer = exports.transferMoney = exports.close = exports.open = void 0;
12
+ exports.cancelMoneyTransfer = exports.transferMoney = exports.open = void 0;
13
13
  /**
14
14
  * 口座サービス
15
15
  * 開設、閉鎖等、口座アクション実行など
@@ -38,15 +38,21 @@ exports.open = open;
38
38
  /**
39
39
  * 口座を解約する
40
40
  */
41
- function close(params) {
42
- return (repos) => __awaiter(this, void 0, void 0, function* () {
43
- yield repos.account.close({
44
- accountNumber: params.accountNumber,
45
- closeDate: new Date()
46
- });
47
- });
48
- }
49
- exports.close = close;
41
+ // export function close(params: {
42
+ // /**
43
+ // * 口座番号
44
+ // */
45
+ // accountNumber: string;
46
+ // }) {
47
+ // return async (repos: {
48
+ // account: AccountRepo;
49
+ // }) => {
50
+ // await repos.account.close({
51
+ // accountNumber: params.accountNumber,
52
+ // closeDate: new Date()
53
+ // });
54
+ // };
55
+ // }
50
56
  /**
51
57
  * 転送する
52
58
  * 確定取引結果から、実際の転送アクションを実行します。
@@ -29,7 +29,8 @@ function start(params) {
29
29
  amount: params.object.amount,
30
30
  toLocation: {
31
31
  typeOf: account.typeOf,
32
- accountType: account.accountType,
32
+ // 廃止(2023-02-16~)
33
+ // accountType: account.accountType,
33
34
  accountNumber: account.accountNumber,
34
35
  name: account.name
35
36
  },
@@ -22,7 +22,8 @@ function createMoneyTransferActionAttributes(params) {
22
22
  case factory.account.transactionType.Deposit:
23
23
  toLocation = {
24
24
  typeOf: transaction.object.toLocation.typeOf,
25
- accountType: transaction.object.toLocation.accountType,
25
+ // 廃止(2023-02-16~)
26
+ // accountType: transaction.object.toLocation.accountType,
26
27
  accountNumber: transaction.object.toLocation.accountNumber,
27
28
  name: transaction.recipient.name
28
29
  };
@@ -30,13 +31,15 @@ function createMoneyTransferActionAttributes(params) {
30
31
  case factory.account.transactionType.Transfer:
31
32
  fromLocation = {
32
33
  typeOf: transaction.object.fromLocation.typeOf,
33
- accountType: transaction.object.fromLocation.accountType,
34
+ // 廃止(2023-02-16~)
35
+ // accountType: transaction.object.fromLocation.accountType,
34
36
  accountNumber: transaction.object.fromLocation.accountNumber,
35
37
  name: transaction.agent.name
36
38
  };
37
39
  toLocation = {
38
40
  typeOf: transaction.object.toLocation.typeOf,
39
- accountType: transaction.object.toLocation.accountType,
41
+ // 廃止(2023-02-16~)
42
+ // accountType: transaction.object.toLocation.accountType,
40
43
  accountNumber: transaction.object.toLocation.accountNumber,
41
44
  name: transaction.recipient.name
42
45
  };
@@ -44,28 +47,29 @@ function createMoneyTransferActionAttributes(params) {
44
47
  case factory.account.transactionType.Withdraw:
45
48
  fromLocation = {
46
49
  typeOf: transaction.object.fromLocation.typeOf,
47
- accountType: transaction.object.fromLocation.accountType,
50
+ // 廃止(2023-02-16~)
51
+ // accountType: transaction.object.fromLocation.accountType,
48
52
  accountNumber: transaction.object.fromLocation.accountNumber,
49
53
  name: transaction.agent.name
50
54
  };
51
55
  break;
52
56
  default:
53
57
  }
54
- let accountType;
55
- const transactionType = params.transaction.typeOf;
56
- switch (transactionType) {
57
- case factory.account.transactionType.Deposit:
58
- accountType = params.transaction.object.toLocation.accountType;
59
- break;
60
- case factory.account.transactionType.Transfer:
61
- accountType = params.transaction.object.fromLocation.accountType;
62
- break;
63
- case factory.account.transactionType.Withdraw:
64
- accountType = params.transaction.object.fromLocation.accountType;
65
- break;
66
- default:
67
- throw new factory.errors.NotImplemented(`transaction type ${transactionType} not implemented`);
68
- }
58
+ // let accountType: string;
59
+ // const transactionType = params.transaction.typeOf;
60
+ // switch (transactionType) {
61
+ // case factory.account.transactionType.Deposit:
62
+ // accountType = params.transaction.object.toLocation.accountType;
63
+ // break;
64
+ // case factory.account.transactionType.Transfer:
65
+ // accountType = params.transaction.object.fromLocation.accountType;
66
+ // break;
67
+ // case factory.account.transactionType.Withdraw:
68
+ // accountType = params.transaction.object.fromLocation.accountType;
69
+ // break;
70
+ // default:
71
+ // throw new factory.errors.NotImplemented(`transaction type ${transactionType} not implemented`);
72
+ // }
69
73
  const purpose = {
70
74
  typeOf: transaction.typeOf,
71
75
  id: transaction.id,
@@ -84,7 +88,8 @@ function createMoneyTransferActionAttributes(params) {
84
88
  recipient: transaction.recipient,
85
89
  amount: {
86
90
  typeOf: 'MonetaryAmount',
87
- currency: accountType,
91
+ // 廃止(2023-02-16~)
92
+ // currency: accountType,
88
93
  value: (typeof transaction.object.amount === 'number')
89
94
  ? transaction.object.amount
90
95
  : transaction.object.amount.value
@@ -47,13 +47,15 @@ function start(params) {
47
47
  amount: params.object.amount,
48
48
  fromLocation: {
49
49
  typeOf: fromAccount.typeOf,
50
- accountType: fromAccount.accountType,
50
+ // 廃止(2023-02-16~)
51
+ // accountType: fromAccount.accountType,
51
52
  accountNumber: fromAccount.accountNumber,
52
53
  name: fromAccount.name
53
54
  },
54
55
  toLocation: {
55
56
  typeOf: toAccount.typeOf,
56
- accountType: toAccount.accountType,
57
+ // 廃止(2023-02-16~)
58
+ // accountType: toAccount.accountType,
57
59
  accountNumber: toAccount.accountNumber,
58
60
  name: toAccount.name
59
61
  },
@@ -36,7 +36,8 @@ function start(params) {
36
36
  amount: params.object.amount,
37
37
  fromLocation: {
38
38
  typeOf: fromAccount.typeOf,
39
- accountType: fromAccount.accountType,
39
+ // 廃止(2023-02-16~)
40
+ // accountType: fromAccount.accountType,
40
41
  accountNumber: fromAccount.accountNumber,
41
42
  name: fromAccount.name
42
43
  },
@@ -221,25 +221,25 @@ function validateSeller(params) {
221
221
  function processAuthorizeAccount(params, transaction, paymentServiceId) {
222
222
  return (repos) => __awaiter(this, void 0, void 0, function* () {
223
223
  yield (0, validation_1.validateAccount)(params)(repos);
224
- const authorizeResult = yield PaymentCardPayment.authorize(params, paymentServiceId)(repos);
224
+ const { pendingTransaction, currency } = yield PaymentCardPayment.authorize(params, paymentServiceId)(repos);
225
225
  const totalPaymentDue = {
226
226
  typeOf: 'MonetaryAmount',
227
- currency: authorizeResult.object.fromLocation.accountType,
228
- value: (typeof authorizeResult.object.amount === 'number')
229
- ? authorizeResult.object.amount
230
- : authorizeResult.object.amount.value
227
+ currency,
228
+ value: (typeof pendingTransaction.object.amount === 'number')
229
+ ? pendingTransaction.object.amount
230
+ : pendingTransaction.object.amount.value
231
231
  };
232
- const pendingTransaction = {
233
- typeOf: authorizeResult.typeOf,
234
- id: authorizeResult.id,
235
- transactionNumber: authorizeResult.transactionNumber,
236
- object: { fromLocation: { accountNumber: authorizeResult.object.fromLocation.accountNumber } }
232
+ const savingPendingTransaction = {
233
+ typeOf: pendingTransaction.typeOf,
234
+ id: pendingTransaction.id,
235
+ transactionNumber: pendingTransaction.transactionNumber,
236
+ object: { fromLocation: { accountNumber: pendingTransaction.object.fromLocation.accountNumber } }
237
237
  };
238
238
  return saveAuthorizeResult({
239
239
  id: transaction.id,
240
240
  update: {
241
241
  'object.paymentMethod.totalPaymentDue': totalPaymentDue,
242
- 'object.pendingTransaction': pendingTransaction
242
+ 'object.pendingTransaction': savingPendingTransaction
243
243
  }
244
244
  })(repos);
245
245
  });
@@ -63,8 +63,9 @@ function createServiceOutput(params) {
63
63
  // 口座は複数のプロダクトに結合する可能性もあり、どのように利用されるかは知らない。ただbalanceを管理するだけ。通貨は知っている。
64
64
  typeOf: factory.accountType.Account,
65
65
  // ひとまずPermit識別子と口座番号は同一
66
- accountNumber: identifier,
67
- accountType: amount.currency
66
+ accountNumber: identifier
67
+ // 廃止(2023-02-16~)
68
+ // accountType: amount.currency
68
69
  };
69
70
  break;
70
71
  case factory.product.ProductType.MembershipService:
@@ -10,7 +10,10 @@ declare type IPendingTransaction = Pick<factory.account.transaction.withdraw.ITr
10
10
  declare function authorize(params: factory.assetTransaction.pay.IStartParamsWithoutDetail, paymentServiceId: string): (repos: {
11
11
  product: ProductRepo;
12
12
  project: ProjectRepo;
13
- }) => Promise<IPendingTransaction>;
13
+ }) => Promise<{
14
+ pendingTransaction: IPendingTransaction;
15
+ currency: string;
16
+ }>;
14
17
  declare function voidTransaction(params: factory.task.voidPayment.IData): (repos: {
15
18
  product: ProductRepo;
16
19
  }) => Promise<void>;
@@ -29,7 +29,7 @@ function authorize(params, paymentServiceId) {
29
29
  throw new factory.errors.ArgumentNull('transactionNumber');
30
30
  }
31
31
  // 決済方法検証
32
- const permit = yield validatePaymentMethod(params, paymentServiceId)(repos);
32
+ const { permit, currency } = yield validatePaymentMethod(params, paymentServiceId)(repos);
33
33
  const accountNumber = (_a = permit.paymentAccount) === null || _a === void 0 ? void 0 : _a.accountNumber;
34
34
  if (typeof accountNumber !== 'string') {
35
35
  throw new factory.errors.ArgumentNull('permit.paymentAccount.accountNumber');
@@ -55,13 +55,13 @@ function authorize(params, paymentServiceId) {
55
55
  // PecorinoAPIのエラーをハンドリング
56
56
  throw (0, errorHandler_1.handlePecorinoError)(error);
57
57
  }
58
- return pendingTransaction;
58
+ return { pendingTransaction, currency };
59
59
  });
60
60
  }
61
61
  exports.authorize = authorize;
62
62
  function validatePaymentMethod(params, paymentServiceId) {
63
63
  return (repos) => __awaiter(this, void 0, void 0, function* () {
64
- var _a, _b, _c, _d, _e, _f, _g, _h;
64
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
65
65
  const serviceOutputIdentifier = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.accountId;
66
66
  const amount = (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.amount;
67
67
  const paymentMethodType = (_c = params.object.paymentMethod) === null || _c === void 0 ? void 0 : _c.typeOf;
@@ -74,6 +74,14 @@ function validatePaymentMethod(params, paymentServiceId) {
74
74
  if (typeof paymentMethodType !== 'string') {
75
75
  throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
76
76
  }
77
+ // プロダクトから通貨区分を取得
78
+ const paymentCatdProduct = yield repos.product.findById({
79
+ id: paymentServiceId
80
+ });
81
+ const currency = (_e = (_d = paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
82
+ if (typeof currency !== 'string') {
83
+ throw new factory.errors.NotFound('product.serviceOutput.amount.currency');
84
+ }
77
85
  // プロダクトのavailableChannelを取得する
78
86
  const availableChannel = yield repos.product.findAvailableChannel({
79
87
  project: { id: params.project.id },
@@ -83,9 +91,9 @@ function validatePaymentMethod(params, paymentServiceId) {
83
91
  const permitService = new pecorinoapi.service.Permit({
84
92
  endpoint: String(availableChannel.serviceUrl),
85
93
  auth: new pecorinoapi.auth.ClientCredentials({
86
- domain: String((_d = availableChannel.credentials) === null || _d === void 0 ? void 0 : _d.authorizeServerDomain),
87
- clientId: String((_e = availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.clientId),
88
- clientSecret: String((_f = availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.clientSecret),
94
+ domain: String((_f = availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.authorizeServerDomain),
95
+ clientId: String((_g = availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.clientId),
96
+ clientSecret: String((_h = availableChannel.credentials) === null || _h === void 0 ? void 0 : _h.clientSecret),
89
97
  scopes: [],
90
98
  state: ''
91
99
  })
@@ -97,7 +105,7 @@ function validatePaymentMethod(params, paymentServiceId) {
97
105
  issuedThrough: { typeOf: factory.product.ProductType.PaymentCard }
98
106
  });
99
107
  // サービスタイプを確認
100
- if (((_h = (_g = serviceOutput.issuedThrough) === null || _g === void 0 ? void 0 : _g.serviceType) === null || _h === void 0 ? void 0 : _h.codeValue) !== paymentMethodType) {
108
+ if (((_k = (_j = serviceOutput.issuedThrough) === null || _j === void 0 ? void 0 : _j.serviceType) === null || _k === void 0 ? void 0 : _k.codeValue) !== paymentMethodType) {
101
109
  throw new factory.errors.Argument('object.paymentMethod.accountId', 'paymentMethodType not matched');
102
110
  }
103
111
  // 出金金額設定を確認
@@ -112,7 +120,7 @@ function validatePaymentMethod(params, paymentServiceId) {
112
120
  throw new factory.errors.Argument('object.paymentMethod.amount', `maximum payment amount requirement not satisfied`);
113
121
  }
114
122
  }
115
- return serviceOutput;
123
+ return { permit: serviceOutput, currency };
116
124
  });
117
125
  }
118
126
  function processAccountTransaction(params) {
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.289.0-alpha.5",
13
- "@cinerino/sdk": "3.140.0-alpha.6",
12
+ "@chevre/factory": "4.289.0-alpha.6",
13
+ "@cinerino/sdk": "3.140.0-alpha.7",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.4.0-alpha.3"
123
+ "version": "20.4.0-alpha.4"
124
124
  }
@@ -1,51 +0,0 @@
1
- // tslint:disable:no-console
2
- // import * as moment from 'moment';
3
- import * as mongoose from 'mongoose';
4
-
5
- import { chevre } from '../../../lib/index';
6
-
7
- // tslint:disable-next-line:max-func-body-length
8
- async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
-
11
- const projectRepo = new chevre.repository.Project(mongoose.connection);
12
-
13
- const cursor = projectRepo.getCursor(
14
- {
15
- },
16
- {
17
- // _id: 1,
18
- }
19
- );
20
- console.log('projects found');
21
-
22
- let i = 0;
23
- let updateCount = 0;
24
- // tslint:disable-next-line:max-func-body-length
25
- await cursor.eachAsync(async (doc) => {
26
- i += 1;
27
- const project: chevre.factory.project.IProject = doc.toObject();
28
-
29
- const useEventServiceAsProduct = project.subscription?.useEventServiceAsProduct;
30
- const alreadyMigrated = useEventServiceAsProduct === true;
31
-
32
- if (alreadyMigrated) {
33
- console.log('already migrated.', project.id, i);
34
- } else {
35
- console.log(
36
- 'updating product...', project.id, i);
37
- await projectRepo.findByIdAndIUpdate({
38
- id: project.id,
39
- subscription: { useEventServiceAsProduct: true }
40
- });
41
- updateCount += 1;
42
- console.log('updated...', project.id, i);
43
- }
44
- });
45
- console.log(i, 'projects checked');
46
- console.log(updateCount, 'projects updated');
47
- }
48
-
49
- main()
50
- .then()
51
- .catch(console.error);
@@ -1,105 +0,0 @@
1
- // tslint:disable:no-console no-magic-numbers
2
- // import * as moment from 'moment';
3
- import * as mongoose from 'mongoose';
4
- import * as redis from 'redis';
5
-
6
- import { chevre } from '../../../lib/index';
7
-
8
- async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
-
11
- const client = redis.createClient({
12
- host: <string>process.env.REDIS_HOST,
13
- port: Number(process.env.REDIS_PORT),
14
- password: <string>process.env.REDIS_KEY
15
- });
16
-
17
- const eventRepo = new chevre.repository.Event(mongoose.connection);
18
-
19
- const events = await eventRepo.search({
20
- typeOf: chevre.factory.eventType.ScreeningEvent,
21
- project: { id: { $eq: '' } },
22
- startFrom: new Date()
23
- // startThrough: moment().add(4, 'day').toDate()
24
- });
25
- console.log(events.length, 'events found');
26
-
27
- const sectionCode = 'Default';
28
- await Promise.all(events.map(async (event) => {
29
- await new Promise<void>((resolve) => {
30
- const key = `chevre:itemAvailability:screeningEvent:${event.id}`;
31
- client.hgetall(key, async (__, reply) => {
32
- if (reply !== null && Object.keys(reply).length > 0) {
33
-
34
- const fieldAndValues = reply;
35
- for (const field of Object.keys(fieldAndValues)) {
36
- // セクションがなければキーを更新
37
- if (field.slice(0, 7) !== sectionCode) {
38
- console.log(event.id, field);
39
- const newField = `${sectionCode}${field}`;
40
- const newValue = fieldAndValues[field];
41
- console.log('saving...', newField, newValue);
42
-
43
- await new Promise<void>((resolveSet) => {
44
- client.hsetnx(key, newField, newValue, (___, setReply) => {
45
- console.log('set', setReply, newField, newValue);
46
-
47
- resolveSet();
48
- });
49
- });
50
-
51
- // 元のフィールドを削除
52
- await new Promise<void>((resolveSet) => {
53
- client.hdel(key, field, (___, setReply) => {
54
- console.log('deleted', setReply, field);
55
-
56
- resolveSet();
57
- });
58
- });
59
- }
60
- }
61
- }
62
-
63
- resolve();
64
- // if (err !== null) {
65
- // reject(err);
66
- // } else {
67
- // if (reply !== null) {
68
- // client.ttl(targetKey, (ttlErr, ttl) => {
69
- // console.log('ttl:', ttl);
70
- // const args = Object.keys(reply)
71
- // .reduce(
72
- // (a, b) => {
73
- // return [...a, b, reply[b]];
74
- // },
75
- // []
76
- // );
77
- // console.log(args.length, 'args ready');
78
-
79
- // newClient.multi()
80
- // .hmset(newKey, ...args)
81
- // .expire(newKey, ttl)
82
- // .exec((hmsetErr, reply) => {
83
- // console.log('hmset result:', hmsetErr, reply);
84
- // resolve();
85
- // });
86
- // });
87
- // } else {
88
- // console.error('targetKey not found');
89
- // }
90
- // }
91
- });
92
- });
93
- }));
94
-
95
- // client.keys('chevre:itemAvailability:screeningEvent:*', async (err, reply) => {
96
- // console.log(err, reply.length, 'keys found');
97
- // const targetKeys = reply;
98
-
99
- // });
100
-
101
- }
102
-
103
- main()
104
- .then(console.log)
105
- .catch(console.error);