@chevre/domain 21.33.0-alpha.10 → 21.33.0-alpha.12

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,37 @@
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
+ function onTransactionStatusChangedListener() {
9
+ return async (params: {
10
+ /**
11
+ * 取引ID
12
+ */
13
+ id: string;
14
+ typeOf: chevre.factory.transactionType;
15
+ status: chevre.factory.transactionStatusType;
16
+ }) => {
17
+ const { id, typeOf, status } = params;
18
+ console.log('transactionStatusChanged.', id, typeOf, status);
19
+ };
20
+ }
21
+
22
+ chevre.eventEmitter.transaction.onTransactionStatusChanged(onTransactionStatusChangedListener());
23
+
24
+ async function main() {
25
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
26
+
27
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
28
+
29
+ const result = await transactionRepo.reexportTasksByExportAction({
30
+ intervalInMinutes: 10
31
+ });
32
+ console.log('reexported', result);
33
+ }
34
+
35
+ main()
36
+ .then()
37
+ .catch(console.error);
@@ -158,9 +158,12 @@ export declare class MongoRepository {
158
158
  }): Promise<Pick<factory.transaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
159
159
  /**
160
160
  * タスクエクスポートリトライ
161
- * TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
161
+ * @deprecated use reexportTasksByExportAction
162
162
  */
163
- reexportTasks(params: {
163
+ reexportTasksByExportationStatus(params: {
164
+ intervalInMinutes: number;
165
+ }): Promise<void>;
166
+ reexportTasksByExportAction(params: {
164
167
  intervalInMinutes: number;
165
168
  }): Promise<void>;
166
169
  /**
@@ -548,12 +548,11 @@ class MongoRepository {
548
548
  .then((doc) => (doc === null) ? null : doc.toObject());
549
549
  });
550
550
  }
551
- // tslint:disable-next-line:no-suspicious-comment
552
551
  /**
553
552
  * タスクエクスポートリトライ
554
- * TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
553
+ * @deprecated use reexportTasksByExportAction
555
554
  */
556
- reexportTasks(params) {
555
+ reexportTasksByExportationStatus(params) {
557
556
  return __awaiter(this, void 0, void 0, function* () {
558
557
  const reexportingTransactions = yield this.transactionModel.find({
559
558
  tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
@@ -591,6 +590,46 @@ class MongoRepository {
591
590
  }
592
591
  });
593
592
  }
593
+ reexportTasksByExportAction(params) {
594
+ return __awaiter(this, void 0, void 0, function* () {
595
+ const reexportingTransactions = yield this.transactionModel.find({
596
+ 'tasksExportAction.actionStatus': {
597
+ $exists: true,
598
+ $eq: factory.actionStatusType.ActiveActionStatus
599
+ },
600
+ 'tasksExportAction.startDate': {
601
+ $exists: true,
602
+ $lt: moment()
603
+ .add(-params.intervalInMinutes, 'minutes')
604
+ .toDate()
605
+ }
606
+ }, { _id: 1, typeOf: 1, status: 1 })
607
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
608
+ .exec();
609
+ if (reexportingTransactions.length > 0) {
610
+ for (const reexportingTransaction of reexportingTransactions) {
611
+ yield this.transactionModel.updateOne({
612
+ _id: { $eq: reexportingTransaction.id },
613
+ 'tasksExportAction.actionStatus': {
614
+ $exists: true,
615
+ $eq: factory.actionStatusType.ActiveActionStatus
616
+ }
617
+ }, {
618
+ tasksExportAction: {
619
+ actionStatus: factory.actionStatusType.PotentialActionStatus
620
+ },
621
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
622
+ })
623
+ .exec();
624
+ transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
625
+ id: reexportingTransaction.id,
626
+ typeOf: reexportingTransaction.typeOf,
627
+ status: reexportingTransaction.status
628
+ });
629
+ }
630
+ }
631
+ });
632
+ }
594
633
  /**
595
634
  * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
596
635
  */
@@ -1,6 +1,3 @@
1
- /**
2
- * 汎用決済サービス
3
- */
4
1
  import * as factory from '../../factory';
5
2
  import type { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
6
3
  import type { MongoRepository as ActionRepo } from '../../repo/action';
@@ -13,6 +13,7 @@ exports.publishPaymentUrl = exports.processVoidPayTransaction = exports.person2u
13
13
  /**
14
14
  * 汎用決済サービス
15
15
  */
16
+ const createDebug = require("debug");
16
17
  const factory = require("../../factory");
17
18
  const PayTransactionService = require("../assetTransaction/pay");
18
19
  const code_1 = require("../code");
@@ -22,6 +23,7 @@ const onPaymentStatusChanged_1 = require("./any/onPaymentStatusChanged");
22
23
  Object.defineProperty(exports, "onPaymentStatusChanged", { enumerable: true, get: function () { return onPaymentStatusChanged_1.onPaymentStatusChanged; } });
23
24
  const person2username_1 = require("./any/person2username");
24
25
  Object.defineProperty(exports, "person2username", { enumerable: true, get: function () { return person2username_1.person2username; } });
26
+ const debug = createDebug('chevre-domain:service:payment');
25
27
  /**
26
28
  * 決済承認中止
27
29
  * タスクから決済承認を取り消す
@@ -317,6 +319,23 @@ function authorize(params) {
317
319
  // const paymentMethodByTransaction = transaction.object.paymentMethods;
318
320
  const paymentMethodByTransaction = yield repos.transaction.findInProgressPaymentMethodId({ id: params.purpose.id });
319
321
  if (params.object.paymentMethodId === (paymentMethodByTransaction === null || paymentMethodByTransaction === void 0 ? void 0 : paymentMethodByTransaction.paymentMethodId)) {
322
+ // check existence of acceptAction when authorizing payment(2024-06-01~)
323
+ const acceptPayAction = (yield repos.action.search({
324
+ limit: 1,
325
+ page: 1,
326
+ project: { id: { $eq: transaction.project.id } },
327
+ typeOf: { $eq: factory.actionType.AcceptAction },
328
+ actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
329
+ purpose: { id: { $in: [transaction.id] } },
330
+ object: {
331
+ transactionNumber: { $eq: params.object.paymentMethodId },
332
+ typeOf: { $eq: factory.assetTransactionType.Pay }
333
+ }
334
+ }, ['result'], [])).shift();
335
+ if (acceptPayAction === undefined) {
336
+ throw new factory.errors.NotFound(factory.actionType.AcceptAction);
337
+ }
338
+ debug('acceptPayAction found:', acceptPayAction);
320
339
  // 検証強化(2024-01-04~)
321
340
  validatePaymentMethodByTransaction({
322
341
  object: params.object,
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": "21.33.0-alpha.10"
113
+ "version": "21.33.0-alpha.12"
114
114
  }