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

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 (26) hide show
  1. package/lib/chevre/repo/adminAssetTransaction.d.ts +132 -0
  2. package/lib/chevre/repo/adminAssetTransaction.js +504 -0
  3. package/lib/chevre/repo/aggregateAssetTransaction.d.ts +43 -0
  4. package/lib/chevre/repo/aggregateAssetTransaction.js +166 -0
  5. package/lib/chevre/repo/assetTransaction.d.ts +10 -235
  6. package/lib/chevre/repo/assetTransaction.js +48 -636
  7. package/lib/chevre/repository.d.ts +10 -0
  8. package/lib/chevre/repository.js +24 -2
  9. package/lib/chevre/service/aggregation/system.d.ts +5 -5
  10. package/lib/chevre/service/aggregation/system.js +2 -2
  11. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +10 -17
  12. package/lib/chevre/service/assetTransaction/refund.js +2 -2
  13. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -3
  14. package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +1 -49
  15. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +2 -2
  16. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +1 -1
  17. package/lib/chevre/service/reserve/cancelReservation.js +3 -3
  18. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  19. package/lib/chevre/service/reserve/confirmReservation.js +1 -1
  20. package/lib/chevre/service/reserve/useReservation.js +1 -1
  21. package/lib/chevre/service/task/returnPayTransaction.js +2 -2
  22. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +2 -2
  23. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +2 -2
  24. package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
  25. package/lib/chevre/service/validation/validateOrder.js +2 -2
  26. package/package.json +2 -2
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateAssetTransactionRepo = void 0;
4
+ const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
5
+ const factory_1 = require("../factory");
6
+ /**
7
+ * 資産取引集計リポジトリ
8
+ */
9
+ class AggregateAssetTransactionRepo {
10
+ transactionModel;
11
+ constructor(connection) {
12
+ this.transactionModel = connection.model(assetTransaction_1.modelName, (0, assetTransaction_1.createSchema)());
13
+ }
14
+ async aggregateAssetTransaction(params) {
15
+ const statuses = await Promise.all([
16
+ factory_1.factory.transactionStatusType.Confirmed,
17
+ factory_1.factory.transactionStatusType.Canceled,
18
+ factory_1.factory.transactionStatusType.Expired
19
+ ].map(async (transactionStatus) => {
20
+ const matchConditions = {
21
+ startDate: {
22
+ $gte: params.startFrom,
23
+ $lte: params.startThrough
24
+ },
25
+ typeOf: { $eq: params.typeOf },
26
+ status: { $eq: transactionStatus },
27
+ ...(typeof params.project?.id?.$ne === 'string')
28
+ ? { 'project.id': { $ne: params.project.id.$ne } }
29
+ : undefined,
30
+ ...(typeof params.project?.id?.$eq === 'string')
31
+ ? { 'project.id': { $eq: params.project.id.$eq } }
32
+ : undefined
33
+ };
34
+ return this.agggregateByStatus({ matchConditions, status: transactionStatus });
35
+ }));
36
+ return { statuses };
37
+ }
38
+ async agggregateByStatus(params) {
39
+ const matchConditions = params.matchConditions;
40
+ const transactionStatus = params.status;
41
+ const aggregations = await this.transactionModel.aggregate([
42
+ {
43
+ $match: matchConditions
44
+ },
45
+ {
46
+ $project: {
47
+ duration: { $subtract: ['$endDate', '$startDate'] },
48
+ graceTime: {
49
+ $cond: {
50
+ if: { $eq: ['$typeOf', factory_1.factory.assetTransactionType.Reserve] },
51
+ then: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
52
+ else: 0
53
+ }
54
+ },
55
+ status: '$status',
56
+ startDate: '$startDate',
57
+ endDate: '$endDate',
58
+ typeOf: '$typeOf',
59
+ reservationCount: {
60
+ $cond: {
61
+ if: { $isArray: '$object.subReservation' },
62
+ then: { $size: '$object.subReservation' },
63
+ else: 0
64
+ }
65
+ }
66
+ }
67
+ },
68
+ {
69
+ $group: {
70
+ _id: '$typeOf',
71
+ transactionCount: { $sum: 1 },
72
+ maxDuration: { $max: '$duration' },
73
+ minDuration: { $min: '$duration' },
74
+ avgDuration: { $avg: '$duration' },
75
+ reservationCount: { $sum: '$reservationCount' },
76
+ maxGraceTime: { $max: '$graceTime' },
77
+ minGraceTime: { $min: '$graceTime' },
78
+ avgGraceTime: { $avg: '$graceTime' }
79
+ }
80
+ },
81
+ {
82
+ $project: {
83
+ _id: 0,
84
+ transactionCount: '$transactionCount',
85
+ avgDuration: '$avgDuration',
86
+ maxDuration: '$maxDuration',
87
+ minDuration: '$minDuration',
88
+ reservationCount: '$reservationCount',
89
+ avgGraceTime: '$avgGraceTime',
90
+ maxGraceTime: '$maxGraceTime',
91
+ minGraceTime: '$minGraceTime'
92
+ }
93
+ }
94
+ ])
95
+ .exec();
96
+ const percents = [50, 95, 99];
97
+ if (aggregations.length === 0) {
98
+ return {
99
+ status: transactionStatus,
100
+ aggregation: {
101
+ transactionCount: 0,
102
+ avgDuration: 0,
103
+ maxDuration: 0,
104
+ minDuration: 0,
105
+ percentilesDuration: percents.map((percent) => {
106
+ return {
107
+ name: String(percent),
108
+ value: 0
109
+ };
110
+ }),
111
+ reservationCount: 0,
112
+ avgGraceTime: 0,
113
+ maxGraceTime: 0,
114
+ minGraceTime: 0
115
+ }
116
+ };
117
+ }
118
+ const ranks4percentile = percents.map((percentile) => {
119
+ return {
120
+ percentile,
121
+ rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
122
+ };
123
+ });
124
+ const aggregations2 = await this.transactionModel.aggregate([
125
+ {
126
+ $match: matchConditions
127
+ },
128
+ {
129
+ $project: {
130
+ duration: { $subtract: ['$endDate', '$startDate'] },
131
+ status: '$status',
132
+ startDate: '$startDate',
133
+ endDate: '$endDate',
134
+ typeOf: '$typeOf'
135
+ }
136
+ },
137
+ { $sort: { duration: 1 } },
138
+ {
139
+ $group: {
140
+ _id: '$typeOf',
141
+ durations: { $push: '$duration' }
142
+ }
143
+ },
144
+ {
145
+ $project: {
146
+ _id: 0,
147
+ percentilesDuration: ranks4percentile.map((rank) => {
148
+ return {
149
+ name: String(rank.percentile),
150
+ value: { $arrayElemAt: ['$durations', rank.rank] }
151
+ };
152
+ })
153
+ }
154
+ }
155
+ ])
156
+ .exec();
157
+ return {
158
+ status: transactionStatus,
159
+ aggregation: {
160
+ ...aggregations[0],
161
+ ...aggregations2[0]
162
+ }
163
+ };
164
+ }
165
+ }
166
+ exports.AggregateAssetTransactionRepo = AggregateAssetTransactionRepo;
@@ -1,36 +1,15 @@
1
1
  import type { Connection, FilterQuery } from 'mongoose';
2
- import { IDocType } from './mongoose/schemas/assetTransaction';
3
2
  import { factory } from '../factory';
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
- reservationCount: number;
14
- avgGraceTime: number;
15
- maxGraceTime: number;
16
- minGraceTime: number;
17
- }
18
- interface IStatus {
19
- status: factory.transactionStatusType;
20
- aggregation: IAggregationByStatus;
21
- }
22
- export interface IAggregateReserve {
23
- statuses: IStatus[];
24
- }
25
3
  type IKeyOfProjection<T extends factory.assetTransactionType> = keyof Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'agent' | 'endDate' | 'expires' | 'project' | 'startDate' | 'status' | 'typeOf' | 'transactionNumber'> | Exclude<keyof factory.assetTransaction.ITransaction<T>, 'id'>;
26
4
  type AvailableAssetTransactionType = factory.assetTransactionType.CancelReservation | factory.assetTransactionType.Pay | factory.assetTransactionType.Refund | factory.assetTransactionType.Reserve;
5
+ type IFindParams<T extends factory.assetTransactionType> = T extends factory.assetTransactionType.CancelReservation ? Pick<factory.assetTransaction.cancelReservation.ISearchConditions, 'ids' | 'limit' | 'object' | 'page' | 'project' | 'status' | 'statuses' | 'transactionNumber' | 'typeOf'> : T extends factory.assetTransactionType.Pay ? Pick<factory.assetTransaction.pay.ISearchConditions, 'ids' | 'limit' | 'object' | 'page' | 'project' | 'status' | 'statuses' | 'transactionNumber' | 'typeOf'> : T extends factory.assetTransactionType.Refund ? Pick<factory.assetTransaction.refund.ISearchConditions, 'ids' | 'limit' | 'object' | 'page' | 'project' | 'status' | 'statuses' | 'transactionNumber' | 'typeOf'> : T extends factory.assetTransactionType.Reserve ? Pick<factory.assetTransaction.reserve.ISearchConditions, 'ids' | 'limit' | 'object' | 'page' | 'project' | 'status' | 'statuses' | 'transactionNumber' | 'typeOf'> : never;
27
6
  /**
28
7
  * 資産取引リポジトリ
29
8
  */
30
9
  export declare class AssetTransactionRepo {
31
10
  private readonly transactionModel;
32
11
  constructor(connection: Connection);
33
- static CREATE_MONGO_CONDITIONS(params: factory.assetTransaction.ISearchConditions<factory.assetTransactionType>): FilterQuery<import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/pay").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/refund").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/reserve").ITransaction>[];
12
+ static CREATE_MONGO_CONDITIONS(params: IFindParams<factory.assetTransactionType>): FilterQuery<import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/pay").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/refund").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/reserve").ITransaction>[];
34
13
  /**
35
14
  * 取引を開始する
36
15
  */
@@ -76,14 +55,6 @@ export declare class AssetTransactionRepo {
76
55
  }): Promise<{
77
56
  id: string;
78
57
  }>;
79
- countPotentiallyExportTasks(params: {
80
- endDate: {
81
- $lt: Date;
82
- };
83
- limit?: number;
84
- }): Promise<{
85
- count: number;
86
- }>;
87
58
  /**
88
59
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
89
60
  */
@@ -104,27 +75,6 @@ export declare class AssetTransactionRepo {
104
75
  endDate?: factory.sortType;
105
76
  };
106
77
  }): Promise<Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'id' | 'typeOf'> | null>;
107
- /**
108
- * tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
109
- * PotentialActionStatusに変更する
110
- * 2025-03-10~
111
- */
112
- reExportAction(params: {
113
- startDate: {
114
- $lt: Date;
115
- };
116
- }): Promise<import("mongoose").UpdateWriteOpResult>;
117
- /**
118
- * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
119
- */
120
- exportTasksMany(params: {
121
- now: Date;
122
- delayInSeconds: number;
123
- status: {
124
- $in: factory.transactionStatusType[];
125
- };
126
- limit: number;
127
- }): Promise<Pick<import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/pay").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/refund").ITransaction | import("@chevre/factory/lib/chevre/assetTransaction/reserve").ITransaction, "id" | "typeOf" | "status">[]>;
128
78
  /**
129
79
  * set task status exported by transaction id
130
80
  * IDでタスクをエクスポート済に変更する
@@ -132,33 +82,6 @@ export declare class AssetTransactionRepo {
132
82
  setTasksExportedById(params: {
133
83
  id: string;
134
84
  }): Promise<void>;
135
- /**
136
- * add(2025-03-17~)
137
- */
138
- countPotentiallyExpired(params: {
139
- expires: {
140
- $lt: Date;
141
- };
142
- limit?: number;
143
- }): Promise<{
144
- count: number;
145
- }>;
146
- /**
147
- * add(2025-03-12~)
148
- */
149
- makeOneExpiredIfExists(params: {
150
- expires: {
151
- $lt: Date;
152
- };
153
- }): Promise<Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'id' | 'typeOf'> | undefined>;
154
- /**
155
- * 取引を期限切れにする
156
- */
157
- makeExpired(params: {
158
- expires: {
159
- $lt: Date;
160
- };
161
- }): Promise<void>;
162
85
  /**
163
86
  * 取引を中止する
164
87
  */
@@ -169,13 +92,17 @@ export declare class AssetTransactionRepo {
169
92
  }): Promise<{
170
93
  id: string;
171
94
  }>;
172
- count<T extends factory.assetTransactionType>(params: factory.assetTransaction.ISearchConditions<T>): Promise<{
173
- count: number;
174
- }>;
175
95
  /**
176
96
  * 取引を検索する
177
97
  */
178
- search<T extends AvailableAssetTransactionType>(params: factory.assetTransaction.ISearchConditions<T>, inclusion?: string[], exclusion?: string[]): Promise<factory.assetTransaction.ITransaction<T>[]>;
98
+ findAssetTransactionsByTypeOf<T extends AvailableAssetTransactionType>(params: IFindParams<T> & {
99
+ sort?: never;
100
+ startFrom?: never;
101
+ startThrough?: never;
102
+ endFrom?: never;
103
+ endThrough?: never;
104
+ tasksExportAction?: never;
105
+ }, inclusion?: string[]): Promise<factory.assetTransaction.ITransaction<T>[]>;
179
106
  /**
180
107
  * 取引番号指定で削除する
181
108
  */
@@ -198,157 +125,5 @@ export declare class AssetTransactionRepo {
198
125
  id: string;
199
126
  };
200
127
  }): Promise<void>;
201
- /**
202
- * 終了日時を一定期間過ぎたアクションを削除する
203
- */
204
- deleteEndDatePassedCertainPeriod(params: {
205
- $lt: Date;
206
- }): Promise<import("mongodb").DeleteResult>;
207
- /**
208
- * 特定の取引を更新する(汎用)
209
- */
210
- findByIdAndUpdateInProgress<T extends factory.assetTransactionType>(params: {
211
- id: string;
212
- update: any;
213
- }): Promise<factory.assetTransaction.ITransaction<T>>;
214
- /**
215
- * 互換性維持対応
216
- */
217
- migrateObjectReservationNumber(params: {
218
- id: string;
219
- object: {
220
- reservationNumber: string;
221
- };
222
- }): Promise<(import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").IAttributes & {
223
- id: string;
224
- } & {
225
- seller?: any;
226
- } & {
227
- _id: import("mongoose").Types.ObjectId;
228
- } & {
229
- __v: number;
230
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/pay").IAttributes & {
231
- id: string;
232
- } & {
233
- seller?: any;
234
- } & {
235
- _id: import("mongoose").Types.ObjectId;
236
- } & {
237
- __v: number;
238
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/refund").IAttributes & {
239
- id: string;
240
- } & {
241
- seller?: any;
242
- } & {
243
- _id: import("mongoose").Types.ObjectId;
244
- } & {
245
- __v: number;
246
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/reserve").IAttributes & {
247
- id: string;
248
- } & {
249
- seller?: any;
250
- } & {
251
- _id: import("mongoose").Types.ObjectId;
252
- } & {
253
- __v: number;
254
- })>;
255
- /**
256
- * 互換性維持対応専用
257
- */
258
- fixReservedTicketIdentifier(params: {
259
- project: {
260
- id: string;
261
- };
262
- transactionNumber: string;
263
- object: {
264
- paymentMethod: {
265
- movieTickets: factory.action.trade.pay.IMovieTicket[];
266
- };
267
- };
268
- }): Promise<void>;
269
- findByIdAndDelete(params: {
270
- id: string;
271
- }): Promise<void>;
272
- getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & ((import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").IAttributes & {
273
- id: string;
274
- } & {
275
- seller?: any;
276
- } & {
277
- _id: import("mongoose").Types.ObjectId;
278
- } & {
279
- __v: number;
280
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/pay").IAttributes & {
281
- id: string;
282
- } & {
283
- seller?: any;
284
- } & {
285
- _id: import("mongoose").Types.ObjectId;
286
- } & {
287
- __v: number;
288
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/refund").IAttributes & {
289
- id: string;
290
- } & {
291
- seller?: any;
292
- } & {
293
- _id: import("mongoose").Types.ObjectId;
294
- } & {
295
- __v: number;
296
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/reserve").IAttributes & {
297
- id: string;
298
- } & {
299
- seller?: any;
300
- } & {
301
- _id: import("mongoose").Types.ObjectId;
302
- } & {
303
- __v: number;
304
- })), import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & ((import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").IAttributes & {
305
- id: string;
306
- } & {
307
- seller?: any;
308
- } & {
309
- _id: import("mongoose").Types.ObjectId;
310
- } & {
311
- __v: number;
312
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/pay").IAttributes & {
313
- id: string;
314
- } & {
315
- seller?: any;
316
- } & {
317
- _id: import("mongoose").Types.ObjectId;
318
- } & {
319
- __v: number;
320
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/refund").IAttributes & {
321
- id: string;
322
- } & {
323
- seller?: any;
324
- } & {
325
- _id: import("mongoose").Types.ObjectId;
326
- } & {
327
- __v: number;
328
- }) | (import("@chevre/factory/lib/chevre/assetTransaction/reserve").IAttributes & {
329
- id: string;
330
- } & {
331
- seller?: any;
332
- } & {
333
- _id: import("mongoose").Types.ObjectId;
334
- } & {
335
- __v: number;
336
- }))) | null>;
337
- unsetUnnecessaryFields(params: {
338
- filter: any;
339
- $unset: any;
340
- }): Promise<import("mongoose").UpdateWriteOpResult>;
341
- aggregateAssetTransaction(params: {
342
- project?: {
343
- id?: {
344
- $eq?: string;
345
- $ne?: string;
346
- };
347
- };
348
- startFrom: Date;
349
- startThrough: Date;
350
- typeOf: factory.assetTransactionType;
351
- }): Promise<IAggregateReserve>;
352
- private agggregateByStatus;
353
128
  }
354
129
  export {};