@chevre/domain 22.9.0-alpha.68 → 22.9.0-alpha.69

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.
@@ -6,9 +6,12 @@ import * as mongoose from 'mongoose';
6
6
  import { chevre } from '../../../../lib/index';
7
7
 
8
8
  const PROJECT_ID = String(process.env.PROJECT_ID);
9
- const SCREEN_CODE = '130';
9
+ // const SCREEN_CODE = '10';
10
+ // const MOVIE_THEATER_CODE = '118';
11
+ // const SCREEN_CODE = '130';
12
+ const SCREEN_CODE = '211';
10
13
  const MOVIE_THEATER_CODE = '020';
11
- const AGGREGATE_PERIOD_IN_MONTHS = 6;
14
+ const AGGREGATE_PERIOD_IN_MONTHS = 12;
12
15
  // tslint:disable-next-line:max-func-body-length
13
16
  async function main() {
14
17
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
@@ -17,7 +20,7 @@ async function main() {
17
20
  const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
18
21
 
19
22
  const seats = <Pick<chevre.factory.place.seat.IPlace, 'branchCode'>[]>await seatRepo.searchSeats({
20
- // limit: 10,
23
+ // limit: 50,
21
24
  $projection: {
22
25
  additionalProperty: 0,
23
26
  'containedInPlace.typeOf': 0,
@@ -44,10 +47,13 @@ async function main() {
44
47
  .toDate();
45
48
 
46
49
  let maxSumGraceTime: number = 0;
50
+ let maxRepeatRate: number = 0;
47
51
  const seatsWithAggregateOrder: {
48
52
  branchCode: string;
49
53
  aggregateOrder: {
54
+ emailCount: number;
50
55
  orderCount: number;
56
+ repeatRate: number;
51
57
  avgGraceTime?: number;
52
58
  sumGraceTime: number;
53
59
  avgGraceTimeInHours?: number;
@@ -76,6 +82,13 @@ async function main() {
76
82
  const diff = process.hrtime(startTime);
77
83
  console.log(`importing chevre took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
78
84
 
85
+ const emailCount = (typeof aggregateResult.aggregation.emailCount === 'number')
86
+ ? aggregateResult.aggregation.emailCount
87
+ : 0;
88
+ const repeatRate = (aggregateResult.aggregation.orderCount > 0)
89
+ // tslint:disable-next-line:no-magic-numbers
90
+ ? (aggregateResult.aggregation.orderCount - emailCount) * 100 / aggregateResult.aggregation.orderCount
91
+ : 0;
79
92
  const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
80
93
  ? aggregateResult.aggregation.sumGraceTime
81
94
  : 0;
@@ -90,11 +103,14 @@ async function main() {
90
103
  .asHours())
91
104
  : 0;
92
105
  maxSumGraceTime = Math.max(sumGraceTime, maxSumGraceTime);
106
+ maxRepeatRate = Math.max(repeatRate, maxRepeatRate);
93
107
 
94
108
  seatsWithAggregateOrder.push({
95
109
  branchCode,
96
110
  aggregateOrder: {
97
111
  ...aggregateResult.aggregation,
112
+ emailCount,
113
+ repeatRate,
98
114
  avgGraceTimeInHours,
99
115
  sumGraceTimeInHours,
100
116
  sumGraceTime
@@ -105,16 +121,35 @@ async function main() {
105
121
  const seatsJson = seatsWithAggregateOrder.map((seat, key) => {
106
122
  // tslint:disable-next-line:no-magic-numbers
107
123
  const score = Math.floor(seat.aggregateOrder.sumGraceTime * 100 / maxSumGraceTime);
108
- console.log('aggregateOrder:result', seat.branchCode, score, key);
124
+ console.log('aggregateOrder:result', seat.branchCode, key);
125
+
126
+ return {
127
+ branchCode: seat.branchCode,
128
+ score
129
+ };
130
+ });
131
+
132
+ const scoresByEmailJson = seatsWithAggregateOrder.map((seat, key) => {
133
+ // tslint:disable-next-line:no-magic-numbers
134
+ const score = Math.floor(seat.aggregateOrder.repeatRate * 100 / maxRepeatRate);
135
+ console.log('aggregateOrder:result', seat.branchCode, seat.aggregateOrder.emailCount, key);
109
136
 
110
137
  return {
111
138
  branchCode: seat.branchCode,
112
139
  score
140
+ // repeatRate: seat.aggregateOrder.repeatRate,
141
+ // emailCount: seat.aggregateOrder.emailCount,
142
+ // orderCount: seat.aggregateOrder.orderCount
113
143
  };
114
144
  });
115
145
 
146
+ console.log('maxSumGraceTime:', maxSumGraceTime);
147
+ console.log('maxRepeatRate:', maxRepeatRate);
148
+
149
+ // tslint:disable-next-line:non-literal-fs-path no-null-keyword
150
+ fs.writeFileSync(`${__dirname}/seatScoresByGraceTime.json`, JSON.stringify(seatsJson, null, ' '));
116
151
  // tslint:disable-next-line:non-literal-fs-path no-null-keyword
117
- fs.writeFileSync(`${__dirname}/seatsWithAggregateOrder.json`, JSON.stringify(seatsJson, null, ' '));
152
+ fs.writeFileSync(`${__dirname}/seatScoresByEmail.json`, JSON.stringify(scoresByEmailJson, null, ' '));
118
153
  }
119
154
 
120
155
  main()
@@ -196,6 +196,7 @@ export declare class OrderRepo {
196
196
  }): Promise<{
197
197
  aggregation: Pick<IAggregation, 'orderCount'> & {
198
198
  sumGraceTime?: number;
199
+ emailCount?: number;
199
200
  };
200
201
  }>;
201
202
  }
@@ -1116,6 +1116,19 @@ class OrderRepo {
1116
1116
  'acceptedOffers.itemOffered.reservationFor.location.branchCode': { $exists: true, $eq: screenCode },
1117
1117
  'acceptedOffers.itemOffered.reservedTicket.ticketedSeat.seatNumber': { $exists: true, $eq: seatNumber }
1118
1118
  };
1119
+ const aggregations4email = yield this.orderModel.aggregate([
1120
+ { $match: matchConditions },
1121
+ {
1122
+ $group: {
1123
+ _id: '$customer.email'
1124
+ }
1125
+ },
1126
+ {
1127
+ $count: 'emailCount'
1128
+ }
1129
+ ])
1130
+ .exec();
1131
+ const emailCount = (aggregations4email.length > 0) ? aggregations4email[0].emailCount : 0;
1119
1132
  const aggregations = yield this.orderModel.aggregate([
1120
1133
  { $match: matchConditions },
1121
1134
  {
@@ -1152,7 +1165,9 @@ class OrderRepo {
1152
1165
  }
1153
1166
  };
1154
1167
  }
1155
- return { aggregation: aggregations[0] };
1168
+ return {
1169
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), { emailCount })
1170
+ };
1156
1171
  });
1157
1172
  }
1158
1173
  }
@@ -22,7 +22,7 @@ function createOnOrderCancelledTasksByTransaction(params) {
22
22
  numberOfTried: 0,
23
23
  executionResults: [],
24
24
  data: {
25
- project: params.transaction.project,
25
+ // project: params.transaction.project, // discontinue(2025-03-12~)
26
26
  purpose: {
27
27
  typeOf: params.transaction.typeOf,
28
28
  id: params.transaction.id,
@@ -39,7 +39,7 @@ function createOnOrderCancelledTasksByTransaction(params) {
39
39
  numberOfTried: 0,
40
40
  executionResults: [],
41
41
  data: {
42
- project: params.transaction.project,
42
+ // project: params.transaction.project, // discontinue(2025-03-12~)
43
43
  purpose: {
44
44
  typeOf: params.transaction.typeOf,
45
45
  id: params.transaction.id,
@@ -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.call = call;
13
- const factory = require("../../factory");
14
13
  const accountingReport_1 = require("../../repo/accountingReport");
15
14
  const action_1 = require("../../repo/action");
16
15
  const assetTransaction_1 = require("../../repo/assetTransaction");
@@ -25,7 +24,7 @@ const any_1 = require("../payment/any");
25
24
  */
26
25
  function call(params) {
27
26
  return (_a) => __awaiter(this, [_a], void 0, function* ({ connection }) {
28
- yield (0, any_1.voidPayTransaction)(Object.assign(Object.assign({}, params.data), { project: { id: params.project.id, typeOf: factory.organizationType.Project }, sameAs: { id: params.id } }))({
27
+ yield (0, any_1.voidPayTransaction)(Object.assign(Object.assign({}, params.data), { project: { id: params.project.id }, sameAs: { id: params.id } }))({
29
28
  accountingReport: new accountingReport_1.AccountingReportRepo(connection),
30
29
  action: new action_1.ActionRepo(connection),
31
30
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
@@ -61,7 +61,7 @@ function call(params) {
61
61
  }, { timeout: settings.coa.timeout });
62
62
  const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
63
63
  try {
64
- yield (0, voidTransaction_1.voidTransaction)(Object.assign(Object.assign({}, params.data), { project: { id: params.project.id, typeOf: factory.organizationType.Project }, sameAs: { id: params.id } }))({
64
+ yield (0, voidTransaction_1.voidTransaction)(Object.assign(Object.assign({}, params.data), { project: { id: params.project.id }, sameAs: { id: params.id } }))({
65
65
  action: new action_1.ActionRepo(connection),
66
66
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
67
67
  stockHolder: new stockHolder_1.StockHolderRepo(redisClient, connection),
@@ -7,5 +7,6 @@ type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceO
7
7
  export declare function createTasks(params: {
8
8
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'seller' | 'startDate' | 'status' | 'typeOf'>;
9
9
  runsAt: Date;
10
+ optimizeRedundantTasks: boolean;
10
11
  }, setting: Pick<ISetting, 'onTransactionStatusChanged' | 'storage'> | null): IPlaceOrderPotentialTask[];
11
12
  export {};
@@ -104,7 +104,7 @@ function createTasks(params, setting
104
104
  numberOfTried: 0,
105
105
  executionResults: [],
106
106
  data: {
107
- project: transaction.project,
107
+ // project: transaction.project, // discontinue(2025-03-12~)
108
108
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
109
109
  }
110
110
  };
@@ -118,13 +118,14 @@ function createTasks(params, setting
118
118
  numberOfTried: 0,
119
119
  executionResults: [],
120
120
  data: {
121
- project: transaction.project,
121
+ // project: transaction.project, // discontinue(2025-03-12~)
122
122
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
123
123
  }
124
124
  };
125
- taskAttributes.push(...triggerWebhookTaskAttributes, voidReserveTaskAttributes, deleteTransactionTask, voidPaymentTaskAttributes);
125
+ taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask);
126
126
  switch (transaction.status) {
127
127
  case factory.transactionStatusType.Confirmed:
128
+ taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
128
129
  // const potentialActions = transaction.potentialActions;
129
130
  // if (potentialActions === undefined) {
130
131
  // throw new factory.errors.NotFound('Transaction PotentialActions');
@@ -159,7 +160,18 @@ function createTasks(params, setting
159
160
  taskAttributes.push(placeOrderTaskAttributes);
160
161
  break;
161
162
  case factory.transactionStatusType.Canceled:
163
+ taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
164
+ break;
162
165
  case factory.transactionStatusType.Expired:
166
+ // optimizeRedundantTasks(2025-03-)
167
+ if (params.optimizeRedundantTasks === true) {
168
+ if (typeof params.transaction.object.orderNumber === 'string') {
169
+ taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
170
+ }
171
+ }
172
+ else {
173
+ taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
174
+ }
163
175
  // tslint:disable-next-line:no-suspicious-comment
164
176
  // TODO reimplement
165
177
  // temporarily discontinue VoidRegisterServiceTransaction VoidMoneyTransferTransaction(2025-02-25~)
@@ -15,5 +15,9 @@ export declare function exportTasksById(params: {
15
15
  * タスク実行日時バッファ
16
16
  */
17
17
  runsTasksAfterInSeconds?: number;
18
+ /**
19
+ * support optimizeRedundantTasks(2025-03-11~)
20
+ */
21
+ optimizeRedundantTasks: boolean;
18
22
  }): ITaskAndTransactionOperation<void>;
19
23
  export {};
@@ -36,7 +36,8 @@ function exportTasksById(params) {
36
36
  const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['onTransactionStatusChanged', 'storage']);
37
37
  const taskAttributes = (0, factory_1.createTasks)({
38
38
  transaction,
39
- runsAt: taskRunsAt
39
+ runsAt: taskRunsAt,
40
+ optimizeRedundantTasks: params.optimizeRedundantTasks === true
40
41
  }, setting
41
42
  // settings
42
43
  );
@@ -44,6 +44,10 @@ export declare function exportOneTransactionTasksIfExists(params: {
44
44
  * タスク実行日時バッファ
45
45
  */
46
46
  runsTasksAfterInSeconds?: number;
47
+ /**
48
+ * support optimizeRedundantTasks(2025-03-11~)
49
+ */
50
+ optimizeRedundantTasks: boolean;
47
51
  status?: {
48
52
  $eq?: factory.transactionStatusType;
49
53
  };
@@ -126,7 +126,7 @@ function exportOneTransactionTasksIfExists(params) {
126
126
  : undefined))(repos);
127
127
  break;
128
128
  case factory.transactionType.PlaceOrder:
129
- yield PlaceOrderTransactionService.exportTasksById(Object.assign({ id: transaction.id }, (typeof params.runsTasksAfterInSeconds === 'number')
129
+ yield PlaceOrderTransactionService.exportTasksById(Object.assign({ id: transaction.id, optimizeRedundantTasks: params.optimizeRedundantTasks === true }, (typeof params.runsTasksAfterInSeconds === 'number')
130
130
  ? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
131
131
  : undefined))(repos);
132
132
  break;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.393.0-alpha.36",
14
+ "@chevre/factory": "4.393.0-alpha.37",
15
15
  "@cinerino/sdk": "10.21.0-alpha.24",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
@@ -112,5 +112,5 @@
112
112
  "postversion": "git push origin --tags",
113
113
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
114
114
  },
115
- "version": "22.9.0-alpha.68"
115
+ "version": "22.9.0-alpha.69"
116
116
  }