@chevre/domain 21.2.0-alpha.0 → 21.2.0-alpha.10

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 (143) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +1 -1
  2. package/example/src/chevre/countDelayedTasks.ts +17 -0
  3. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  4. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  5. package/example/src/chevre/lockStockHolder.ts +48 -0
  6. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  7. package/example/src/chevre/processReserve.ts +2 -2
  8. package/example/src/chevre/searchEventSeats.ts +42 -0
  9. package/lib/chevre/repo/account.js +0 -4
  10. package/lib/chevre/repo/accountTitle.js +0 -4
  11. package/lib/chevre/repo/accountTransaction.js +0 -4
  12. package/lib/chevre/repo/accountingReport.js +0 -4
  13. package/lib/chevre/repo/action.js +0 -4
  14. package/lib/chevre/repo/additionalProperty.js +0 -4
  15. package/lib/chevre/repo/aggregation.js +0 -4
  16. package/lib/chevre/repo/assetTransaction.js +5 -4
  17. package/lib/chevre/repo/categoryCode.js +0 -4
  18. package/lib/chevre/repo/code.js +0 -4
  19. package/lib/chevre/repo/comment.js +0 -4
  20. package/lib/chevre/repo/confirmationNumber.d.ts +3 -1
  21. package/lib/chevre/repo/confirmationNumber.js +31 -30
  22. package/lib/chevre/repo/creativeWork.js +0 -4
  23. package/lib/chevre/repo/customer.js +0 -4
  24. package/lib/chevre/repo/emailMessage.js +0 -4
  25. package/lib/chevre/repo/event.js +0 -4
  26. package/lib/chevre/repo/member.js +0 -4
  27. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  28. package/lib/chevre/repo/mongoose/schemas/account.d.ts +1 -0
  29. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  30. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +1 -0
  31. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  32. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +1 -0
  33. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -0
  34. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +1 -0
  35. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  36. package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -0
  37. package/lib/chevre/repo/mongoose/schemas/action.js +1 -0
  38. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +1 -0
  39. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  40. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +1 -0
  41. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  42. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +1 -0
  43. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +1 -0
  44. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +1 -0
  45. package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -0
  46. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +1 -0
  47. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  48. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +1 -0
  49. package/lib/chevre/repo/mongoose/schemas/comments.js +1 -0
  50. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +1 -0
  51. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  52. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +1 -0
  53. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  54. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +1 -0
  55. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  56. package/lib/chevre/repo/mongoose/schemas/event.d.ts +1 -0
  57. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  58. package/lib/chevre/repo/mongoose/schemas/member.d.ts +1 -0
  59. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  60. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +1 -0
  61. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  62. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +1 -0
  63. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  64. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +1 -0
  65. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  66. package/lib/chevre/repo/mongoose/schemas/order.d.ts +1 -0
  67. package/lib/chevre/repo/mongoose/schemas/order.js +1 -0
  68. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +1 -0
  69. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +1 -0
  70. package/lib/chevre/repo/mongoose/schemas/place.d.ts +1 -0
  71. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  72. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +1 -0
  73. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  74. package/lib/chevre/repo/mongoose/schemas/product.d.ts +1 -0
  75. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  76. package/lib/chevre/repo/mongoose/schemas/project.d.ts +1 -0
  77. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  78. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +1 -0
  79. package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -0
  80. package/lib/chevre/repo/mongoose/schemas/role.d.ts +1 -0
  81. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  82. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +1 -0
  83. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  84. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +1 -0
  85. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +1 -0
  86. package/lib/chevre/repo/mongoose/schemas/task.d.ts +1 -0
  87. package/lib/chevre/repo/mongoose/schemas/task.js +1 -0
  88. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +1 -0
  89. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  90. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +1 -0
  91. package/lib/chevre/repo/mongoose/schemas/transaction.js +1 -0
  92. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +1 -0
  93. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  94. package/lib/chevre/repo/offer.js +0 -5
  95. package/lib/chevre/repo/offerCatalog.js +0 -4
  96. package/lib/chevre/repo/order.js +0 -4
  97. package/lib/chevre/repo/orderNumber.d.ts +2 -1
  98. package/lib/chevre/repo/orderNumber.js +24 -28
  99. package/lib/chevre/repo/ownershipInfo.js +0 -4
  100. package/lib/chevre/repo/permit.js +0 -4
  101. package/lib/chevre/repo/place.d.ts +5 -1
  102. package/lib/chevre/repo/place.js +1 -10
  103. package/lib/chevre/repo/priceSpecification.js +0 -4
  104. package/lib/chevre/repo/product.js +0 -4
  105. package/lib/chevre/repo/project.js +0 -4
  106. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -2
  107. package/lib/chevre/repo/rateLimit/offer.js +14 -14
  108. package/lib/chevre/repo/reservation.js +0 -4
  109. package/lib/chevre/repo/role.js +0 -4
  110. package/lib/chevre/repo/seller.js +0 -4
  111. package/lib/chevre/repo/serviceOutput.js +0 -4
  112. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -1
  113. package/lib/chevre/repo/serviceOutputIdentifier.js +14 -15
  114. package/lib/chevre/repo/{itemAvailability/screeningEvent.d.ts → stockHolder.d.ts} +8 -14
  115. package/lib/chevre/repo/stockHolder.js +273 -0
  116. package/lib/chevre/repo/task.d.ts +3 -0
  117. package/lib/chevre/repo/task.js +12 -4
  118. package/lib/chevre/repo/telemetry.js +0 -4
  119. package/lib/chevre/repo/transaction.js +0 -4
  120. package/lib/chevre/repo/transactionNumber.d.ts +2 -1
  121. package/lib/chevre/repo/transactionNumber.js +14 -15
  122. package/lib/chevre/repo/trip.js +0 -4
  123. package/lib/chevre/repository.d.ts +3 -5
  124. package/lib/chevre/repository.js +5 -8
  125. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -2
  126. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +4 -3
  127. package/lib/chevre/service/assetTransaction/reserve.d.ts +4 -4
  128. package/lib/chevre/service/assetTransaction/reserve.js +71 -5
  129. package/lib/chevre/service/offer/event/authorize.d.ts +2 -2
  130. package/lib/chevre/service/offer/event/cancel.d.ts +2 -2
  131. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -2
  132. package/lib/chevre/service/offer.d.ts +13 -26
  133. package/lib/chevre/service/offer.js +21 -116
  134. package/lib/chevre/service/reserve/cancelReservation.d.ts +3 -3
  135. package/lib/chevre/service/reserve/cancelReservation.js +6 -6
  136. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -2
  137. package/lib/chevre/service/task/cancelPendingReservation.js +3 -3
  138. package/lib/chevre/service/task/cancelReservation.js +3 -3
  139. package/lib/chevre/service/task/voidReserveTransaction.js +3 -3
  140. package/lib/chevre/settings.d.ts +1 -0
  141. package/lib/chevre/settings.js +5 -2
  142. package/package.json +2 -2
  143. package/lib/chevre/repo/itemAvailability/screeningEvent.js +0 -181
@@ -22,7 +22,7 @@ async function main() {
22
22
  id: String(process.env.EVENT_ID)
23
23
  })({
24
24
  event: new chevre.repository.Event(mongoose.connection),
25
- eventAvailability: new chevre.repository.itemAvailability.ScreeningEvent(client),
25
+ stockHolder: new chevre.repository.StockHolder(client),
26
26
  offer: new chevre.repository.Offer(mongoose.connection),
27
27
  offerCatalog: new chevre.repository.OfferCatalog(mongoose.connection),
28
28
  offerRateLimit: new chevre.repository.rateLimit.Offer(client),
@@ -0,0 +1,17 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ export async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
10
+
11
+ const count = await taskRepo.countDelayedTasks({ delayInSeconds: 60 });
12
+ console.log('count:', count);
13
+ }
14
+
15
+ main()
16
+ .then()
17
+ .catch(console.error);
@@ -0,0 +1,60 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ export async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
10
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
11
+
12
+ for (const typeOf of [
13
+ chevre.factory.transactionType.PlaceOrder,
14
+ chevre.factory.transactionType.ReturnOrder,
15
+ chevre.factory.transactionType.MoneyTransfer
16
+ ]) {
17
+ const count = await transactionRepo.count({
18
+ typeOf,
19
+ statuses: [
20
+ chevre.factory.transactionStatusType.Canceled,
21
+ chevre.factory.transactionStatusType.Confirmed,
22
+ chevre.factory.transactionStatusType.Expired
23
+ ],
24
+ tasksExportationStatuses: [
25
+ chevre.factory.transactionTasksExportationStatus.Exporting,
26
+ chevre.factory.transactionTasksExportationStatus.Unexported
27
+ ],
28
+ endThrough: new Date()
29
+ });
30
+ console.log('count:', count, typeOf);
31
+ }
32
+
33
+ for (const typeOf of [
34
+ chevre.factory.assetTransactionType.CancelReservation,
35
+ chevre.factory.assetTransactionType.MoneyTransfer,
36
+ chevre.factory.assetTransactionType.Pay,
37
+ chevre.factory.assetTransactionType.Refund,
38
+ chevre.factory.assetTransactionType.RegisterService,
39
+ chevre.factory.assetTransactionType.Reserve
40
+ ]) {
41
+ const count = await assetTransactionRepo.count({
42
+ typeOf,
43
+ statuses: [
44
+ chevre.factory.transactionStatusType.Canceled,
45
+ chevre.factory.transactionStatusType.Confirmed,
46
+ chevre.factory.transactionStatusType.Expired
47
+ ],
48
+ tasksExportationStatuses: [
49
+ chevre.factory.transactionTasksExportationStatus.Exporting,
50
+ chevre.factory.transactionTasksExportationStatus.Unexported
51
+ ],
52
+ endThrough: new Date()
53
+ });
54
+ console.log('count:', count, typeOf);
55
+ }
56
+ }
57
+
58
+ main()
59
+ .then()
60
+ .catch(console.error);
@@ -0,0 +1,36 @@
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
+ const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ export async function main() {
11
+ const now = new Date();
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
13
+
14
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
15
+
16
+ const transactions = await transactionRepo.search<chevre.factory.transactionType.MoneyTransfer>(
17
+ {
18
+ project: { id: { $eq: project.id } },
19
+ typeOf: chevre.factory.transactionType.MoneyTransfer,
20
+ statuses: [chevre.factory.transactionStatusType.Confirmed],
21
+ startFrom: moment(now)
22
+ .add(-1, 'year')
23
+ .toDate(),
24
+ startThrough: now,
25
+ inclusion: ['_id', 'startDate', 'typeOf', 'object'],
26
+ exclusion: []
27
+ }
28
+ );
29
+ const count = transactions.filter((t) => t.object.description === '受け取り')
30
+ .length;
31
+ console.log('transactions found', count);
32
+ }
33
+
34
+ main()
35
+ .then()
36
+ .catch(console.error);
@@ -0,0 +1,48 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as redis from 'redis';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
12
+ socket: {
13
+ port: Number(<string>process.env.REDIS_PORT),
14
+ host: <string>process.env.REDIS_HOST
15
+ },
16
+ password: <string>process.env.REDIS_KEY
17
+ });
18
+ await client.connect();
19
+
20
+ const startDate = moment('2023-04-18T00:00:00Z');
21
+
22
+ const stockHolderRepo = new chevre.repository.StockHolder(client);
23
+ await stockHolderRepo.lock({
24
+ eventId: 'sampleEventId',
25
+ startDate: startDate.toDate(),
26
+ offers: [
27
+ {
28
+ seatSection: 'sampleSeatSection',
29
+ seatNumber: 'sampleSeatNumber'
30
+ },
31
+ {
32
+ seatSection: 'sampleSeatSection1',
33
+ seatNumber: 'sampleSeatNumber1'
34
+ }
35
+ ],
36
+ expires: moment(startDate)
37
+ .add(1, 'month')
38
+ .toDate(),
39
+ holder: 'sampleStockHolder'
40
+ });
41
+ console.log('locked');
42
+ }
43
+
44
+ main()
45
+ .then(() => {
46
+ console.log('success!');
47
+ })
48
+ .catch(console.error);
@@ -0,0 +1,89 @@
1
+ // tslint:disable:no-console
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
+ // const project = { id: String(process.env.PROJECT_ID) };
9
+
10
+ const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
11
+
12
+ async function main() {
13
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
+ socket: {
15
+ host: process.env.REDIS_HOST,
16
+ port: Number(process.env.REDIS_PORT)
17
+ },
18
+ password: process.env.REDIS_KEY
19
+ });
20
+ await client.connect();
21
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
22
+
23
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
24
+ const stockHolderRepo = new chevre.repository.StockHolder(client);
25
+
26
+ const cursor = eventRepo.getCursor(
27
+ {
28
+ // 'project.id': { $eq: project.id },
29
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
30
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
31
+ startDate: {
32
+ $gte: moment('2023-04-23T15:00:00Z')
33
+ .toDate()
34
+ }
35
+ // _id: { $eq: 'al6aff83w' }
36
+ },
37
+ {
38
+ // _id: 1,
39
+ }
40
+ );
41
+ console.log('events found');
42
+
43
+ let i = 0;
44
+ let updateCount = 0;
45
+ await cursor.eachAsync(async (doc) => {
46
+ i += 1;
47
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
48
+
49
+ const oldKey = chevre.repository.StockHolder.GET_KEY({
50
+ eventId: event.id,
51
+ startDate: new Date()
52
+ });
53
+ const newKey = chevre.repository.StockHolder.GET_KEY({
54
+ eventId: event.id,
55
+ startDate: moment(event.startDate)
56
+ .toDate()
57
+ });
58
+
59
+ let conflicted = false;
60
+ try {
61
+ await stockHolderRepo.checkIfConflicted({
62
+ key: newKey,
63
+ eventId: event.id
64
+ });
65
+ } catch (error) {
66
+ conflicted = true;
67
+ }
68
+
69
+ if (conflicted) {
70
+ updateCount += 1;
71
+ await stockHolderRepo.migrateKey({
72
+ key: newKey,
73
+ eventId: event.id
74
+ });
75
+ console.log(
76
+ 'updated...', event.project.id, event.id, event.startDate, i);
77
+ } else {
78
+ console.log(
79
+ 'already exist...', event.project.id, event.id, event.startDate, i);
80
+ }
81
+ });
82
+
83
+ console.log(i, 'events checked');
84
+ console.log(updateCount, 'events updated');
85
+ }
86
+
87
+ main()
88
+ .then()
89
+ .catch(console.error);
@@ -30,7 +30,7 @@ async function main() {
30
30
  const priceSpecRepo = new chevre.repository.PriceSpecification(mongoose.connection);
31
31
  const reservationRepo = new chevre.repository.Reservation(mongoose.connection);
32
32
  const eventRepo = new chevre.repository.Event(mongoose.connection);
33
- const itemAvailabilityRepo = new chevre.repository.itemAvailability.ScreeningEvent(client);
33
+ const itemAvailabilityRepo = new chevre.repository.StockHolder(client);
34
34
  const offerRateLimitRepo = new chevre.repository.rateLimit.Offer(client);
35
35
 
36
36
  const identifier = `CIN${(new Date()).valueOf()}`;
@@ -70,7 +70,7 @@ async function main() {
70
70
  validateEventOfferPeriod: false,
71
71
  validateAppliesToMovieTicket: true
72
72
  })({
73
- eventAvailability: itemAvailabilityRepo,
73
+ stockHolder: itemAvailabilityRepo,
74
74
  event: eventRepo,
75
75
  offer: offerRepo,
76
76
  offerCatalog: offerCatalogRepo,
@@ -0,0 +1,42 @@
1
+ // tslint:disable:no-console
2
+ import * as redis from 'redis';
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
+ const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
11
+ socket: {
12
+ port: Number(<string>process.env.REDIS_PORT),
13
+ host: <string>process.env.REDIS_HOST
14
+ },
15
+ password: <string>process.env.REDIS_KEY
16
+ });
17
+ await client.connect();
18
+
19
+ const itemAvailabilityRepo = new chevre.repository.StockHolder(client);
20
+
21
+ const result = await itemAvailabilityRepo.searchHolders({
22
+ eventId: 'alckc9mlx',
23
+ startDate: new Date(),
24
+ offers: [
25
+ {
26
+ seatSection: 'Default',
27
+ seatNumber: 'B-10'
28
+ },
29
+ {
30
+ seatSection: 'xxx',
31
+ seatNumber: 'xxx'
32
+ }
33
+ ]
34
+ });
35
+ console.log(result);
36
+ }
37
+
38
+ main()
39
+ .then(() => {
40
+ console.log('success!');
41
+ })
42
+ .catch(console.error);
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const account_1 = require("./mongoose/schemas/account");
15
14
  const factory = require("../factory");
16
15
  /**
@@ -19,9 +18,6 @@ const factory = require("../factory");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.accountModel = connection.model(account_1.modelName, account_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.accountModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
27
23
  static CREATE_MONGO_CONDITIONS(params) {
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const factory = require("../factory");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const accountTitle_1 = require("./mongoose/schemas/accountTitle");
16
15
  /**
17
16
  * 科目リポジトリ
@@ -19,9 +18,6 @@ const accountTitle_1 = require("./mongoose/schemas/accountTitle");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.accountTitleModel = connection.model(accountTitle_1.modelName, accountTitle_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.accountTitleModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  deleteByProject(params) {
27
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const accountTransaction_1 = require("./mongoose/schemas/accountTransaction");
16
15
  const factory = require("../factory");
17
16
  /**
@@ -20,9 +19,6 @@ const factory = require("../factory");
20
19
  class MongoRepository {
21
20
  constructor(connection) {
22
21
  this.transactionModel = connection.model(accountTransaction_1.modelName, accountTransaction_1.schema);
23
- if (connection.get('autoIndex') === true) {
24
- this.transactionModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
25
- }
26
22
  }
27
23
  static CREATE_MONGO_CONDITIONS(params) {
28
24
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const accountingReport_1 = require("./mongoose/schemas/accountingReport");
15
14
  const errorHandler_1 = require("../errorHandler");
16
15
  /**
@@ -19,9 +18,6 @@ const errorHandler_1 = require("../errorHandler");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.accountingReportModel = connection.model(accountingReport_1.modelName, accountingReport_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.accountingReportModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  /**
27
23
  * なければ作成する
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const factory = require("../factory");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const action_1 = require("./mongoose/schemas/action");
16
15
  /**
17
16
  * アクションリポジトリ
@@ -19,9 +18,6 @@ const action_1 = require("./mongoose/schemas/action");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.actionModel = connection.model(action_1.modelName, action_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.actionModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
27
23
  static CREATE_MONGO_CONDITIONS(params) {
@@ -21,7 +21,6 @@ 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 onIndexCreated_1 = require("./mongoose/onIndexCreated");
25
24
  const additionalProperty_1 = require("./mongoose/schemas/additionalProperty");
26
25
  const factory = require("../factory");
27
26
  /**
@@ -30,9 +29,6 @@ const factory = require("../factory");
30
29
  class MongoRepository {
31
30
  constructor(connection) {
32
31
  this.additionalPropertyModel = connection.model(additionalProperty_1.modelName, additionalProperty_1.schema);
33
- if (connection.get('autoIndex') === true) {
34
- this.additionalPropertyModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
35
- }
36
32
  }
37
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
38
34
  static CREATE_MONGO_CONDITIONS(params) {
@@ -21,7 +21,6 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = exports.AggregationType = void 0;
24
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
25
24
  const aggregation_1 = require("./mongoose/schemas/aggregation");
26
25
  var AggregationType;
27
26
  (function (AggregationType) {
@@ -43,9 +42,6 @@ var AggregationType;
43
42
  class MongoRepository {
44
43
  constructor(connection) {
45
44
  this.aggregationModel = connection.model(aggregation_1.modelName, aggregation_1.schema);
46
- if (connection.get('autoIndex') === true) {
47
- this.aggregationModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
48
- }
49
45
  }
50
46
  saveAggregation(params) {
51
47
  return __awaiter(this, void 0, void 0, function* () {
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
16
15
  const factory = require("../factory");
17
16
  /**
@@ -20,9 +19,6 @@ const factory = require("../factory");
20
19
  class MongoRepository {
21
20
  constructor(connection) {
22
21
  this.transactionModel = connection.model(assetTransaction_1.modelName, assetTransaction_1.schema);
23
- if (connection.get('autoIndex') === true) {
24
- this.transactionModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
25
- }
26
22
  }
27
23
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
28
24
  static CREATE_MONGO_CONDITIONS(params) {
@@ -106,6 +102,11 @@ class MongoRepository {
106
102
  }
107
103
  });
108
104
  }
105
+ if (Array.isArray(params.tasksExportationStatuses)) {
106
+ andConditions.push({
107
+ tasksExportationStatus: { $in: params.tasksExportationStatuses }
108
+ });
109
+ }
109
110
  switch (params.typeOf) {
110
111
  case factory.assetTransactionType.Pay:
111
112
  const objectAccountIdEq = (_e = (_d = params.object) === null || _d === void 0 ? void 0 : _d.accountId) === null || _e === void 0 ? void 0 : _e.$eq;
@@ -21,7 +21,6 @@ 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 onIndexCreated_1 = require("./mongoose/onIndexCreated");
25
24
  const categoryCode_1 = require("./mongoose/schemas/categoryCode");
26
25
  const factory = require("../factory");
27
26
  /**
@@ -30,9 +29,6 @@ const factory = require("../factory");
30
29
  class MongoRepository {
31
30
  constructor(connection) {
32
31
  this.categoryCodeModel = connection.model(categoryCode_1.modelName, categoryCode_1.schema);
33
- if (connection.get('autoIndex') === true) {
34
- this.categoryCodeModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
35
- }
36
32
  }
37
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
38
34
  static CREATE_MONGO_CONDITIONS(params) {
@@ -13,7 +13,6 @@ exports.MongoRepository = exports.modelName = void 0;
13
13
  const moment = require("moment");
14
14
  const uuid = require("uuid");
15
15
  const factory = require("../factory");
16
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
17
16
  const authorization_1 = require("./mongoose/schemas/authorization");
18
17
  Object.defineProperty(exports, "modelName", { enumerable: true, get: function () { return authorization_1.modelName; } });
19
18
  /**
@@ -22,9 +21,6 @@ Object.defineProperty(exports, "modelName", { enumerable: true, get: function ()
22
21
  class MongoRepository {
23
22
  constructor(connection) {
24
23
  this.authorizationModel = connection.model(authorization_1.modelName, authorization_1.schema);
25
- if (connection.get('autoIndex') === true) {
26
- this.authorizationModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
27
- }
28
24
  }
29
25
  // tslint:disable-next-line:max-func-body-length
30
26
  static CREATE_MONGO_CONDITIONS(params) {
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
14
13
  const comments_1 = require("./mongoose/schemas/comments");
15
14
  const factory = require("../factory");
16
15
  /**
@@ -19,9 +18,6 @@ const factory = require("../factory");
19
18
  class MongoRepository {
20
19
  constructor(connection) {
21
20
  this.commentModel = connection.model(comments_1.modelName, comments_1.schema);
22
- if (connection.get('autoIndex') === true) {
23
- this.commentModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
24
- }
25
21
  }
26
22
  static CREATE_MONGO_CONDITIONS(params) {
27
23
  var _a, _b, _c, _d, _e, _f;
@@ -3,10 +3,12 @@ import { RedisClientType } from 'redis';
3
3
  * 確認番号リポジトリ
4
4
  */
5
5
  export declare class RedisRepository {
6
+ private static readonly REDIS_KEY_PREFIX_NEW;
6
7
  private static readonly REDIS_KEY_PREFIX;
7
8
  private readonly redisClient;
8
9
  constructor(redisClient: RedisClientType);
9
- static ALIGN_DIGITS(params: string): string;
10
+ private static alignDigits;
11
+ private static createKey;
10
12
  /**
11
13
  * 発行する
12
14
  */
@@ -16,6 +16,7 @@ const util = require("util");
16
16
  // tslint:disable-next-line:no-require-imports no-var-requires
17
17
  const fpe = require('node-fpe');
18
18
  const factory = require("../factory");
19
+ const settings_1 = require("../settings");
19
20
  const CONFIRMATION_NUMBER_MIN_LENGH = 4;
20
21
  /**
21
22
  * 確認番号リポジトリ
@@ -24,7 +25,7 @@ class RedisRepository {
24
25
  constructor(redisClient) {
25
26
  this.redisClient = redisClient;
26
27
  }
27
- static ALIGN_DIGITS(params) {
28
+ static alignDigits(params) {
28
29
  let aligndNumber = String(params);
29
30
  if (aligndNumber.length < CONFIRMATION_NUMBER_MIN_LENGH) {
30
31
  aligndNumber = `${'0'.repeat(CONFIRMATION_NUMBER_MIN_LENGH)}${aligndNumber}`
@@ -32,6 +33,21 @@ class RedisRepository {
32
33
  }
33
34
  return aligndNumber;
34
35
  }
36
+ static createKey(params) {
37
+ const useNewKey = params.orderDate instanceof Date
38
+ && moment(params.orderDate)
39
+ .isSameOrAfter(settings_1.USE_NEW_CONFIRMATION_NUMBER_KEY_FROM);
40
+ if (useNewKey) {
41
+ return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX_NEW, moment(params.orderDate)
42
+ .tz('Asia/Tokyo')
43
+ .format('YYMM'));
44
+ }
45
+ else {
46
+ return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, moment(params.orderDate)
47
+ .tz('Asia/Tokyo')
48
+ .format('YYMM'));
49
+ }
50
+ }
35
51
  /**
36
52
  * 発行する
37
53
  */
@@ -41,44 +57,29 @@ class RedisRepository {
41
57
  const TTL = moment(params.orderDate)
42
58
  .add(1, 'month')
43
59
  .diff(moment(params.orderDate), 'seconds');
44
- const key = util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, moment(params.orderDate)
45
- .tz('Asia/Tokyo')
46
- .format('YYMM'));
60
+ const key = RedisRepository.createKey({ orderDate: params.orderDate });
47
61
  const [incrReply] = yield this.redisClient.multi()
48
62
  .incr(key)
49
63
  .expire(key, TTL)
50
64
  .exec();
51
- // if (!Array.isArray(results)) {
52
- // // なぜかresults: nullのことがあるのでハンドリング
53
- // throw new factory.errors.ServiceUnavailable('incr confirmationNumber result not array');
54
- // }
55
65
  // tslint:disable-next-line:no-single-line-block-comment
56
- /* istanbul ignore else: please write tests */
57
- if (typeof incrReply === 'number') {
58
- const no = incrReply;
59
- // debug('no incremented.', no);
60
- // 桁数調整
61
- let confirmationNumber = RedisRepository.ALIGN_DIGITS(String(no));
62
- // debug('encrypting confirmationNumber...', confirmationNumber);
63
- // checkdigit
64
- const cd = cdigit.luhn.compute(confirmationNumber);
65
- // debug('check digit:', cd);
66
- confirmationNumber = fpe({ password: cd })
67
- .encrypt(confirmationNumber);
68
- confirmationNumber = `${cd}${confirmationNumber}`;
69
- // console.log(
70
- // 'decrypted confirmationNumber:',
71
- // fpe({ password: confirmationNumber.slice(0, 1) })
72
- // .decrypt(confirmationNumber.slice(1))
73
- // );
74
- return confirmationNumber;
75
- }
76
- else {
66
+ /* istanbul ignore if */
67
+ if (typeof incrReply !== 'number') {
77
68
  // 基本的にありえないフロー
78
- throw new factory.errors.ServiceUnavailable('Confirmation number not published');
69
+ throw new factory.errors.ServiceUnavailable('confirmation number not incremented unexpectedly');
79
70
  }
71
+ // 桁数調整
72
+ let confirmationNumber = RedisRepository.alignDigits(incrReply);
73
+ // checkdigit
74
+ const cd = cdigit.luhn.compute(confirmationNumber);
75
+ // debug('check digit:', cd);
76
+ confirmationNumber = fpe({ password: cd })
77
+ .encrypt(confirmationNumber);
78
+ confirmationNumber = `${cd}${confirmationNumber}`;
79
+ return confirmationNumber;
80
80
  });
81
81
  }
82
82
  }
83
+ RedisRepository.REDIS_KEY_PREFIX_NEW = 'confirmationNumber';
83
84
  RedisRepository.REDIS_KEY_PREFIX = 'cinerino:confirmationNumber';
84
85
  exports.RedisRepository = RedisRepository;