@chevre/domain 21.2.0-alpha.17 → 21.2.0-alpha.18

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,18 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
10
+ const result = await transactionRepo.makeExpired({
11
+ expires: new Date()
12
+ });
13
+ console.log(result);
14
+ }
15
+
16
+ main()
17
+ .then(console.log)
18
+ .catch(console.error);
@@ -405,15 +405,29 @@ class MongoRepository {
405
405
  */
406
406
  makeExpired(params) {
407
407
  return __awaiter(this, void 0, void 0, function* () {
408
- // ステータスと期限を見て更新
409
- yield this.transactionModel.updateMany({
410
- status: factory.transactionStatusType.InProgress,
408
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
409
+ const expiringTransactions = yield this.transactionModel.find({
410
+ status: { $eq: factory.transactionStatusType.InProgress },
411
411
  expires: { $lt: params.expires }
412
- }, {
413
- status: factory.transactionStatusType.Expired,
414
- endDate: new Date()
415
412
  })
413
+ .select({
414
+ _id: 1,
415
+ typeOf: 1
416
+ })
417
+ .setOptions({ maxTimeMS: 10000 })
416
418
  .exec();
419
+ if (expiringTransactions.length > 0) {
420
+ // ステータスと期限を見て更新
421
+ yield this.transactionModel.updateMany({
422
+ _id: { $in: expiringTransactions.map((t) => t.id) },
423
+ status: { $eq: factory.transactionStatusType.InProgress },
424
+ expires: { $lt: params.expires }
425
+ }, {
426
+ status: factory.transactionStatusType.Expired,
427
+ endDate: new Date()
428
+ })
429
+ .exec();
430
+ }
417
431
  });
418
432
  }
419
433
  /**
@@ -509,15 +509,36 @@ class MongoRepository {
509
509
  */
510
510
  makeExpired(params) {
511
511
  return __awaiter(this, void 0, void 0, function* () {
512
- // ステータスと期限を見て更新
513
- yield this.transactionModel.updateMany({
514
- status: factory.transactionStatusType.InProgress,
512
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
513
+ const expiringTransactions = yield this.transactionModel.find({
514
+ status: { $eq: factory.transactionStatusType.InProgress },
515
515
  expires: { $lt: params.expires }
516
- }, {
517
- status: factory.transactionStatusType.Expired,
518
- endDate: new Date()
519
516
  })
517
+ .select({
518
+ _id: 1,
519
+ typeOf: 1
520
+ })
521
+ .setOptions({ maxTimeMS: 10000 })
520
522
  .exec();
523
+ if (expiringTransactions.length > 0) {
524
+ // ステータスと期限を見て更新
525
+ yield this.transactionModel.updateMany({
526
+ _id: { $in: expiringTransactions.map((t) => t.id) },
527
+ status: { $eq: factory.transactionStatusType.InProgress },
528
+ expires: { $lt: params.expires }
529
+ }, {
530
+ status: factory.transactionStatusType.Expired,
531
+ endDate: new Date()
532
+ })
533
+ .exec();
534
+ expiringTransactions.forEach((expiringTransaction) => {
535
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
536
+ id: expiringTransaction.id,
537
+ typeOf: expiringTransaction.typeOf,
538
+ status: factory.transactionStatusType.Expired
539
+ });
540
+ });
541
+ }
521
542
  });
522
543
  }
523
544
  /**
package/package.json CHANGED
@@ -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.17"
120
+ "version": "21.2.0-alpha.18"
121
121
  }