@chevre/domain 26.0.0-alpha.26 → 26.0.0-alpha.28

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 (34) hide show
  1. package/lib/chevre/repo/action.d.ts +1 -1
  2. package/lib/chevre/repo/action.js +0 -260
  3. package/lib/chevre/repo/adminTransaction.d.ts +131 -0
  4. package/lib/chevre/repo/adminTransaction.js +237 -0
  5. package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
  6. package/lib/chevre/repo/aggregateTransaction.js +166 -0
  7. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
  8. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +85 -76
  9. package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
  10. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
  11. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
  12. package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → updateAction.d.ts} +5 -3
  13. package/lib/chevre/repo/mongoose/schemas/updateAction.js +65 -0
  14. package/lib/chevre/repo/transaction.d.ts +1 -187
  15. package/lib/chevre/repo/transaction.js +2 -383
  16. package/lib/chevre/repo/updateAction.d.ts +52 -0
  17. package/lib/chevre/repo/updateAction.js +429 -0
  18. package/lib/chevre/repository.d.ts +15 -5
  19. package/lib/chevre/repository.js +35 -13
  20. package/lib/chevre/service/aggregation/system.d.ts +2 -2
  21. package/lib/chevre/service/aggregation/system.js +2 -2
  22. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +2 -2
  23. package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
  24. package/lib/chevre/service/event.d.ts +2 -2
  25. package/lib/chevre/service/event.js +3 -3
  26. package/lib/chevre/service/task/deleteTransaction.js +2 -4
  27. package/lib/chevre/service/task/importEventsFromCOA.js +2 -2
  28. package/lib/chevre/service/task/syncResourcesFromCOA.js +11 -11
  29. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -2
  30. package/lib/chevre/service/transaction/deleteTransaction.js +2 -2
  31. package/package.json +2 -2
  32. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -82
  33. package/lib/chevre/repo/ownershipInfo.d.ts +0 -20
  34. package/lib/chevre/repo/ownershipInfo.js +0 -130
@@ -1,37 +1,11 @@
1
- import type { Connection, UpdateQuery } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import { factory } from '../factory';
3
- import { IDocType } from './mongoose/schemas/transaction';
4
- interface IAggregationByStatus {
5
- transactionCount: number;
6
- avgDuration: number;
7
- maxDuration: number;
8
- minDuration: number;
9
- percentilesDuration: {
10
- name: string;
11
- value: number;
12
- }[];
13
- }
14
- interface IStatus {
15
- status: factory.transactionStatusType;
16
- aggregation: IAggregationByStatus;
17
- }
18
- export interface IAggregatePlaceOrder {
19
- statuses: IStatus[];
20
- }
21
3
  /**
22
4
  * 取引リポジトリ
23
5
  */
24
6
  export declare class TransactionRepo {
25
7
  private readonly transactionModel;
26
8
  constructor(connection: Connection);
27
- countPotentiallyExportTasks(params: {
28
- endDate: {
29
- $lt: Date;
30
- };
31
- limit?: number;
32
- }): Promise<{
33
- count: number;
34
- }>;
35
9
  /**
36
10
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
37
11
  */
@@ -53,27 +27,6 @@ export declare class TransactionRepo {
53
27
  startDate?: factory.sortType;
54
28
  };
55
29
  }): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | null>;
56
- /**
57
- * tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
58
- * PotentialActionStatusに変更する
59
- * 2025-03-10~
60
- */
61
- reExportAction(params: {
62
- startDate: {
63
- $lt: Date;
64
- };
65
- }): Promise<import("mongoose").UpdateWriteOpResult>;
66
- /**
67
- * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
68
- */
69
- exportTasksMany(params: {
70
- now: Date;
71
- delayInSeconds: number;
72
- status: {
73
- $in: factory.transactionStatusType[];
74
- };
75
- limit: number;
76
- }): Promise<Pick<import("@chevre/factory/lib/chevre/transaction/placeOrder").ITransaction | import("@chevre/factory/lib/chevre/transaction/returnOrder").ITransaction, "id" | "typeOf" | "status">[]>;
77
30
  /**
78
31
  * set task status exported by transaction id
79
32
  * IDでタスクをエクスポート済に変更する
@@ -81,143 +34,4 @@ export declare class TransactionRepo {
81
34
  setTasksExportedById(params: {
82
35
  id: string;
83
36
  }): Promise<void>;
84
- /**
85
- * add(2025-03-13~)
86
- */
87
- countPotentiallyExpired(params: {
88
- expires: {
89
- $lt: Date;
90
- };
91
- limit?: number;
92
- }): Promise<{
93
- count: number;
94
- }>;
95
- /**
96
- * add(2025-03-03~)
97
- */
98
- makeOneExpiredIfExists(params: {
99
- expires: {
100
- $lt: Date;
101
- };
102
- }): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | undefined>;
103
- /**
104
- * 取引を期限切れにする
105
- */
106
- makeExpired(params: {
107
- expires: {
108
- $lt: Date;
109
- };
110
- limit: number;
111
- }): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'>[]>;
112
- findByIdAndDelete(params: {
113
- id: string;
114
- }): Promise<void>;
115
- unsetUnnecessaryFields(params: {
116
- filter: any;
117
- $unset: any;
118
- }): Promise<import("mongoose").UpdateWriteOpResult>;
119
- updateById4migration(params: {
120
- id: string;
121
- update: UpdateQuery<IDocType>;
122
- }): Promise<import("mongoose").UpdateWriteOpResult>;
123
- /**
124
- * 終了日時を一定期間過ぎたアクションを削除する
125
- */
126
- deleteEndDatePassedCertainPeriod(params: {
127
- typeOf: factory.transactionType;
128
- endDate: {
129
- $gte: Date;
130
- $lt: Date;
131
- };
132
- }): Promise<import("mongodb").DeleteResult>;
133
- getCursor(conditions: any, projection: any, sort?: factory.sortType): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
134
- object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
135
- error?: any;
136
- project: import("@chevre/factory/lib/chevre/transaction").IProject;
137
- seller: import("@chevre/factory/lib/chevre/transaction/placeOrder").ISeller;
138
- typeOf: factory.transactionType.PlaceOrder;
139
- expires: Date;
140
- result?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IResult | undefined;
141
- startDate: Date;
142
- endDate?: Date | undefined;
143
- instrument?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IInstrument | undefined;
144
- agent: import("@chevre/factory/lib/chevre/transaction/placeOrder").IAgent;
145
- status: factory.transactionStatusType;
146
- tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
147
- potentialActions?: undefined;
148
- } & {
149
- _id: import("mongoose").Types.ObjectId;
150
- } & {
151
- __v: number;
152
- }) | ({
153
- object: import("@chevre/factory/lib/chevre/transaction/returnOrder").IObject;
154
- error?: any;
155
- project: import("@chevre/factory/lib/chevre/transaction").IProject;
156
- seller: import("@chevre/factory/lib/chevre/transaction").ISeller;
157
- typeOf: factory.transactionType.ReturnOrder;
158
- expires: Date;
159
- result?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined;
160
- startDate: Date;
161
- endDate?: Date | undefined;
162
- agent: import("@chevre/factory/lib/chevre/transaction").IAgent;
163
- recipient?: undefined;
164
- status: factory.transactionStatusType;
165
- tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
166
- potentialActions?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IPotentialActions | undefined;
167
- } & {
168
- _id: import("mongoose").Types.ObjectId;
169
- } & {
170
- __v: number;
171
- })), import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
172
- object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
173
- error?: any;
174
- project: import("@chevre/factory/lib/chevre/transaction").IProject;
175
- seller: import("@chevre/factory/lib/chevre/transaction/placeOrder").ISeller;
176
- typeOf: factory.transactionType.PlaceOrder;
177
- expires: Date;
178
- result?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IResult | undefined;
179
- startDate: Date;
180
- endDate?: Date | undefined;
181
- instrument?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IInstrument | undefined;
182
- agent: import("@chevre/factory/lib/chevre/transaction/placeOrder").IAgent;
183
- status: factory.transactionStatusType;
184
- tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
185
- potentialActions?: undefined;
186
- } & {
187
- _id: import("mongoose").Types.ObjectId;
188
- } & {
189
- __v: number;
190
- }) | ({
191
- object: import("@chevre/factory/lib/chevre/transaction/returnOrder").IObject;
192
- error?: any;
193
- project: import("@chevre/factory/lib/chevre/transaction").IProject;
194
- seller: import("@chevre/factory/lib/chevre/transaction").ISeller;
195
- typeOf: factory.transactionType.ReturnOrder;
196
- expires: Date;
197
- result?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined;
198
- startDate: Date;
199
- endDate?: Date | undefined;
200
- agent: import("@chevre/factory/lib/chevre/transaction").IAgent;
201
- recipient?: undefined;
202
- status: factory.transactionStatusType;
203
- tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
204
- potentialActions?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IPotentialActions | undefined;
205
- } & {
206
- _id: import("mongoose").Types.ObjectId;
207
- } & {
208
- __v: number;
209
- }))) | null>;
210
- aggregatePlaceOrder(params: {
211
- project?: {
212
- id?: {
213
- $ne?: string;
214
- };
215
- };
216
- startFrom: Date;
217
- startThrough: Date;
218
- typeOf: factory.transactionType;
219
- clientId?: string;
220
- }): Promise<IAggregatePlaceOrder>;
221
- private agggregateByStatus;
222
37
  }
223
- export {};
@@ -1,48 +1,16 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.TransactionRepo = void 0;
7
- const moment_1 = __importDefault(require("moment"));
8
- const transaction_1 = require("../eventEmitter/transaction");
9
4
  const factory_1 = require("../factory");
10
5
  const settings_1 = require("../settings");
11
- const transaction_2 = require("./mongoose/schemas/transaction");
6
+ const transaction_1 = require("./mongoose/schemas/transaction");
12
7
  /**
13
8
  * 取引リポジトリ
14
9
  */
15
10
  class TransactionRepo {
16
11
  transactionModel;
17
12
  constructor(connection) {
18
- this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
19
- }
20
- async countPotentiallyExportTasks(params) {
21
- const { endDate, limit } = params;
22
- const endDateLt = endDate?.$lt;
23
- if (!(endDateLt instanceof Date)) {
24
- throw new factory_1.factory.errors.Argument('endDate.$lt', 'must be Date');
25
- }
26
- const query = this.transactionModel.countDocuments({
27
- status: {
28
- $in: [
29
- factory_1.factory.transactionStatusType.Canceled,
30
- factory_1.factory.transactionStatusType.Confirmed,
31
- factory_1.factory.transactionStatusType.Expired
32
- ]
33
- },
34
- 'tasksExportAction.actionStatus': {
35
- $exists: true,
36
- $eq: factory_1.factory.actionStatusType.PotentialActionStatus
37
- },
38
- endDate: { $exists: true, $lt: endDateLt }
39
- });
40
- if (typeof limit === 'number' && limit >= 0) {
41
- query.limit(limit);
42
- }
43
- const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
44
- .exec();
45
- return { count };
13
+ this.transactionModel = connection.model(transaction_1.modelName, (0, transaction_1.createSchema)());
46
14
  }
47
15
  /**
48
16
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
@@ -101,72 +69,6 @@ class TransactionRepo {
101
69
  .exec()
102
70
  .then((doc) => (doc === null) ? null : doc);
103
71
  }
104
- /**
105
- * tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
106
- * PotentialActionStatusに変更する
107
- * 2025-03-10~
108
- */
109
- async reExportAction(params) {
110
- const { startDate } = params;
111
- if (!(startDate.$lt instanceof Date)) {
112
- throw new factory_1.factory.errors.Argument('startDate.$lt', 'must be Date');
113
- }
114
- return this.transactionModel.updateMany({
115
- 'tasksExportAction.actionStatus': {
116
- $exists: true,
117
- $eq: factory_1.factory.actionStatusType.ActiveActionStatus
118
- },
119
- 'tasksExportAction.startDate': {
120
- $exists: true,
121
- $lt: startDate.$lt
122
- }
123
- }, {
124
- $set: {
125
- tasksExportAction: {
126
- actionStatus: factory_1.factory.actionStatusType.PotentialActionStatus
127
- }
128
- }
129
- })
130
- .exec();
131
- }
132
- /**
133
- * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
134
- */
135
- async exportTasksMany(params) {
136
- const delayedTransactions = await this.transactionModel.find({
137
- status: { $in: params.status.$in },
138
- 'tasksExportAction.actionStatus': {
139
- $exists: true,
140
- $eq: factory_1.factory.actionStatusType.PotentialActionStatus
141
- },
142
- endDate: {
143
- $exists: true,
144
- $lt: (0, moment_1.default)(params.now)
145
- .add(-params.delayInSeconds, 'seconds')
146
- .toDate()
147
- }
148
- })
149
- .select({
150
- _id: 0,
151
- id: { $toString: '$_id' },
152
- typeOf: 1,
153
- status: 1
154
- })
155
- .limit(params.limit)
156
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
157
- .lean()
158
- .exec();
159
- if (delayedTransactions.length > 0) {
160
- delayedTransactions.forEach((delayedTransaction) => {
161
- transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
162
- id: delayedTransaction.id,
163
- typeOf: delayedTransaction.typeOf,
164
- status: delayedTransaction.status
165
- });
166
- });
167
- }
168
- return delayedTransactions;
169
- }
170
72
  /**
171
73
  * set task status exported by transaction id
172
74
  * IDでタスクをエクスポート済に変更する
@@ -189,288 +91,5 @@ class TransactionRepo {
189
91
  })
190
92
  .exec();
191
93
  }
192
- /**
193
- * add(2025-03-13~)
194
- */
195
- async countPotentiallyExpired(params) {
196
- const { expires, limit } = params;
197
- const query = this.transactionModel.countDocuments({
198
- status: { $eq: factory_1.factory.transactionStatusType.InProgress },
199
- expires: { $lt: expires.$lt }
200
- });
201
- if (typeof limit === 'number' && limit >= 0) {
202
- query.limit(limit);
203
- }
204
- const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
205
- .exec();
206
- return { count };
207
- }
208
- /**
209
- * add(2025-03-03~)
210
- */
211
- async makeOneExpiredIfExists(params) {
212
- const endDate = new Date();
213
- const sort = {
214
- expires: factory_1.factory.sortType.Ascending
215
- };
216
- const doc = await this.transactionModel.findOneAndUpdate({
217
- status: { $eq: factory_1.factory.transactionStatusType.InProgress },
218
- expires: { $lt: params.expires.$lt }
219
- }, {
220
- status: factory_1.factory.transactionStatusType.Expired,
221
- endDate
222
- }, {
223
- new: true,
224
- projection: {
225
- _id: 0,
226
- id: { $toString: '$_id' },
227
- typeOf: 1
228
- }
229
- })
230
- .sort(sort)
231
- .lean()
232
- .exec();
233
- if (doc === null) {
234
- // no op
235
- return;
236
- }
237
- else {
238
- transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
239
- id: doc.id,
240
- typeOf: doc.typeOf,
241
- status: factory_1.factory.transactionStatusType.Expired
242
- });
243
- return doc;
244
- }
245
- }
246
- /**
247
- * 取引を期限切れにする
248
- */
249
- async makeExpired(params) {
250
- if (typeof params.limit !== 'number' || params.limit === 0) {
251
- throw new factory_1.factory.errors.ArgumentNull('limit');
252
- }
253
- const sort = {
254
- expires: factory_1.factory.sortType.Ascending
255
- };
256
- // IDをemitしたいのでまずリスト検索(2023-04-27~)
257
- const expiringTransactions = await this.transactionModel.find({
258
- status: { $eq: factory_1.factory.transactionStatusType.InProgress },
259
- expires: { $lt: params.expires.$lt }
260
- })
261
- .select({
262
- _id: 0,
263
- id: { $toString: '$_id' },
264
- typeOf: 1
265
- })
266
- .limit(params.limit)
267
- .sort(sort) // sort(2025-03-03~)
268
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
269
- .lean()
270
- .exec();
271
- if (expiringTransactions.length > 0) {
272
- // ステータスと期限を見て更新
273
- await this.transactionModel.updateMany({
274
- _id: { $in: expiringTransactions.map((t) => t.id) },
275
- status: { $eq: factory_1.factory.transactionStatusType.InProgress },
276
- expires: { $lt: params.expires.$lt }
277
- }, {
278
- status: factory_1.factory.transactionStatusType.Expired,
279
- endDate: new Date()
280
- })
281
- .exec();
282
- expiringTransactions.forEach((expiringTransaction) => {
283
- transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
284
- id: expiringTransaction.id,
285
- typeOf: expiringTransaction.typeOf,
286
- status: factory_1.factory.transactionStatusType.Expired
287
- });
288
- });
289
- }
290
- return expiringTransactions;
291
- }
292
- async findByIdAndDelete(params) {
293
- await this.transactionModel.findByIdAndDelete(params.id)
294
- .exec();
295
- }
296
- async unsetUnnecessaryFields(params) {
297
- return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
298
- .exec();
299
- }
300
- async updateById4migration(params) {
301
- return this.transactionModel.updateOne({ _id: { $eq: params.id } }, params.update)
302
- .exec();
303
- }
304
- /**
305
- * 終了日時を一定期間過ぎたアクションを削除する
306
- */
307
- async deleteEndDatePassedCertainPeriod(params) {
308
- return this.transactionModel.deleteMany({
309
- typeOf: { $eq: params.typeOf },
310
- // 終了日時を一定期間過ぎたもの
311
- endDate: {
312
- $exists: true,
313
- $gte: params.endDate.$gte,
314
- $lt: params.endDate.$lt
315
- }
316
- })
317
- .exec();
318
- }
319
- getCursor(conditions, projection, sort) {
320
- return this.transactionModel.find(conditions, projection)
321
- .sort({ startDate: (sort === factory_1.factory.sortType.Ascending) ? sort : factory_1.factory.sortType.Descending })
322
- .cursor();
323
- }
324
- async aggregatePlaceOrder(params) {
325
- const statuses = await Promise.all([
326
- factory_1.factory.transactionStatusType.Confirmed,
327
- factory_1.factory.transactionStatusType.Canceled,
328
- factory_1.factory.transactionStatusType.Expired
329
- ].map(async (transactionStatus) => {
330
- const matchConditions = {
331
- startDate: {
332
- $gte: params.startFrom,
333
- $lte: params.startThrough
334
- },
335
- typeOf: { $eq: params.typeOf },
336
- status: { $eq: transactionStatus },
337
- ...(typeof params.project?.id?.$ne === 'string')
338
- ? { 'project.id': { $ne: params.project.id.$ne } }
339
- : undefined,
340
- ...(typeof params.clientId === 'string')
341
- // customerIdentifierAll.push();
342
- ? {
343
- 'agent.identifier': {
344
- $exists: true,
345
- $all: [{ name: 'clientId', value: params.clientId }]
346
- }
347
- }
348
- : undefined
349
- };
350
- return this.agggregateByStatus({ matchConditions, status: transactionStatus });
351
- }));
352
- return { statuses };
353
- }
354
- async agggregateByStatus(params) {
355
- const matchConditions = params.matchConditions;
356
- const transactionStatus = params.status;
357
- const aggregations = await this.transactionModel.aggregate([
358
- {
359
- $match: matchConditions
360
- },
361
- {
362
- $project: {
363
- duration: { $subtract: ['$endDate', '$startDate'] },
364
- status: '$status',
365
- startDate: '$startDate',
366
- endDate: '$endDate',
367
- typeOf: '$typeOf'
368
- }
369
- },
370
- {
371
- $group: {
372
- _id: '$typeOf',
373
- transactionCount: { $sum: 1 },
374
- maxDuration: { $max: '$duration' },
375
- minDuration: { $min: '$duration' },
376
- avgDuration: { $avg: '$duration' }
377
- }
378
- },
379
- {
380
- $project: {
381
- _id: 0,
382
- transactionCount: '$transactionCount',
383
- avgDuration: '$avgDuration',
384
- maxDuration: '$maxDuration',
385
- minDuration: '$minDuration'
386
- }
387
- }
388
- ])
389
- .exec();
390
- const percents = [50, 95, 99];
391
- if (aggregations.length === 0) {
392
- return {
393
- status: transactionStatus,
394
- aggregation: {
395
- transactionCount: 0,
396
- avgDuration: 0,
397
- maxDuration: 0,
398
- minDuration: 0,
399
- percentilesDuration: percents.map((percent) => {
400
- return {
401
- name: String(percent),
402
- value: 0
403
- };
404
- })
405
- // totalPrice: 0,
406
- // maxPrice: 0,
407
- // minPrice: 0,
408
- // avgPrice: 0
409
- }
410
- };
411
- }
412
- const ranks4percentile = percents.map((percentile) => {
413
- return {
414
- percentile,
415
- rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
416
- };
417
- });
418
- const aggregations2 = await this.transactionModel.aggregate([
419
- {
420
- $match: matchConditions
421
- },
422
- {
423
- $project: {
424
- duration: { $subtract: ['$endDate', '$startDate'] },
425
- status: '$status',
426
- startDate: '$startDate',
427
- endDate: '$endDate',
428
- typeOf: '$typeOf'
429
- // result: '$result',
430
- // price: {
431
- // $cond: {
432
- // if: { $isNumber: '$result.order.price' },
433
- // then: '$result.order.price',
434
- // else: 0
435
- // }
436
- // }
437
- }
438
- },
439
- { $sort: { duration: 1 } },
440
- {
441
- $group: {
442
- _id: '$typeOf',
443
- durations: { $push: '$duration' }
444
- // totalPrice: { $sum: '$price' },
445
- // maxPrice: { $max: '$price' },
446
- // minPrice: { $min: '$price' },
447
- // avgPrice: { $avg: '$price' }
448
- }
449
- },
450
- {
451
- $project: {
452
- _id: 0,
453
- percentilesDuration: ranks4percentile.map((rank) => {
454
- return {
455
- name: String(rank.percentile),
456
- value: { $arrayElemAt: ['$durations', rank.rank] }
457
- };
458
- })
459
- // totalPrice: '$totalPrice',
460
- // maxPrice: '$maxPrice',
461
- // minPrice: '$minPrice',
462
- // avgPrice: '$avgPrice'
463
- }
464
- }
465
- ])
466
- .exec();
467
- return {
468
- status: transactionStatus,
469
- aggregation: {
470
- ...aggregations[0],
471
- ...aggregations2[0]
472
- }
473
- };
474
- }
475
94
  }
476
95
  exports.TransactionRepo = TransactionRepo;
@@ -0,0 +1,52 @@
1
+ import { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IDocType } from './mongoose/schemas/updateAction';
4
+ type StartableActionType = factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction;
5
+ export type IAction<T extends StartableActionType> = T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : never;
6
+ type IKeyOfProjection = keyof IDocType;
7
+ type IFindParams = Pick<factory.action.ISearchConditions, 'actionStatus' | 'actionStatusTypes' | 'agent' | 'id' | 'instrument' | 'limit' | 'object' | 'page' | 'project' | 'result' | 'sameAs' | 'sort' | 'startFrom' | 'startThrough' | 'typeOf'>;
8
+ /**
9
+ * リソース編集アクションリポジトリ
10
+ */
11
+ export declare class UpdateActionRepo {
12
+ private readonly updateActionModel;
13
+ constructor(connection: Connection);
14
+ static CREATE_MONGO_CONDITIONS(params: IFindParams): FilterQuery<IDocType>[];
15
+ /**
16
+ * アクション開始
17
+ */
18
+ startUpdateAction<T extends StartableActionType>(attributes: factory.action.IAttributes<T, any, any>): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
19
+ completeUpdateAction(params: {
20
+ typeOf: StartableActionType;
21
+ id: string;
22
+ result: any;
23
+ }): Promise<void>;
24
+ /**
25
+ * アクション失敗
26
+ */
27
+ giveUpUpdateAction(params: {
28
+ typeOf: StartableActionType;
29
+ id: string;
30
+ error: Error | Error[] | unknown;
31
+ }): Promise<void>;
32
+ findUpdateActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<IAction<StartableActionType>[]>;
33
+ searchBySameAs(params: {
34
+ sameAs: {
35
+ id: {
36
+ $eq: string;
37
+ };
38
+ };
39
+ purpose?: {
40
+ id: {
41
+ $eq: string;
42
+ };
43
+ };
44
+ /**
45
+ * 1taskから複数actionが発生する可能性があるので、typeOf指定が必須
46
+ */
47
+ typeOf: {
48
+ $eq: StartableActionType;
49
+ };
50
+ }): Promise<Pick<IAction<StartableActionType>, 'id' | 'actionStatus' | 'error' | 'purpose'>[]>;
51
+ }
52
+ export {};