@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,132 @@
1
+ import type { Connection, FilterQuery } from 'mongoose';
2
+ import { IDocType } from './mongoose/schemas/assetTransaction';
3
+ import { factory } from '../factory';
4
+ type AvailableAssetTransactionType = factory.assetTransactionType.CancelReservation | factory.assetTransactionType.Pay | factory.assetTransactionType.Refund | factory.assetTransactionType.Reserve;
5
+ /**
6
+ * 資産取引管理リポジトリ
7
+ */
8
+ export declare class AdminAssetTransactionRepo {
9
+ private readonly transactionModel;
10
+ constructor(connection: Connection);
11
+ 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
+ countPotentiallyExportTasks(params: {
13
+ endDate: {
14
+ $lt: Date;
15
+ };
16
+ limit?: number;
17
+ }): Promise<{
18
+ count: number;
19
+ }>;
20
+ /**
21
+ * tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
22
+ * PotentialActionStatusに変更する
23
+ * 2025-03-10~
24
+ */
25
+ reExportAction(params: {
26
+ startDate: {
27
+ $lt: Date;
28
+ };
29
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
30
+ /**
31
+ * add(2025-03-17~)
32
+ */
33
+ countPotentiallyExpired(params: {
34
+ expires: {
35
+ $lt: Date;
36
+ };
37
+ limit?: number;
38
+ }): Promise<{
39
+ count: number;
40
+ }>;
41
+ /**
42
+ * add(2025-03-12~)
43
+ */
44
+ makeOneExpiredIfExists(params: {
45
+ expires: {
46
+ $lt: Date;
47
+ };
48
+ }): Promise<Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'id' | 'typeOf'> | undefined>;
49
+ countAssetTransactions<T extends factory.assetTransactionType>(params: factory.assetTransaction.ISearchConditions<T>): Promise<{
50
+ count: number;
51
+ }>;
52
+ /**
53
+ * 取引を検索する
54
+ */
55
+ findAssetTransactions<T extends AvailableAssetTransactionType>(params: factory.assetTransaction.ISearchConditions<T>, inclusion?: string[], exclusion?: string[]): Promise<factory.assetTransaction.ITransaction<T>[]>;
56
+ /**
57
+ * 終了日時を一定期間過ぎたアクションを削除する
58
+ */
59
+ deleteEndDatePassedCertainPeriod(params: {
60
+ $lt: Date;
61
+ }): Promise<import("mongodb").DeleteResult>;
62
+ 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 & {
63
+ id: string;
64
+ } & {
65
+ seller?: any;
66
+ } & {
67
+ _id: import("mongoose").Types.ObjectId;
68
+ } & {
69
+ __v: number;
70
+ }) | (import("@chevre/factory/lib/chevre/assetTransaction/pay").IAttributes & {
71
+ id: string;
72
+ } & {
73
+ seller?: any;
74
+ } & {
75
+ _id: import("mongoose").Types.ObjectId;
76
+ } & {
77
+ __v: number;
78
+ }) | (import("@chevre/factory/lib/chevre/assetTransaction/refund").IAttributes & {
79
+ id: string;
80
+ } & {
81
+ seller?: any;
82
+ } & {
83
+ _id: import("mongoose").Types.ObjectId;
84
+ } & {
85
+ __v: number;
86
+ }) | (import("@chevre/factory/lib/chevre/assetTransaction/reserve").IAttributes & {
87
+ id: string;
88
+ } & {
89
+ seller?: any;
90
+ } & {
91
+ _id: import("mongoose").Types.ObjectId;
92
+ } & {
93
+ __v: number;
94
+ })), import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & ((import("@chevre/factory/lib/chevre/assetTransaction/cancelReservation").IAttributes & {
95
+ id: string;
96
+ } & {
97
+ seller?: any;
98
+ } & {
99
+ _id: import("mongoose").Types.ObjectId;
100
+ } & {
101
+ __v: number;
102
+ }) | (import("@chevre/factory/lib/chevre/assetTransaction/pay").IAttributes & {
103
+ id: string;
104
+ } & {
105
+ seller?: any;
106
+ } & {
107
+ _id: import("mongoose").Types.ObjectId;
108
+ } & {
109
+ __v: number;
110
+ }) | (import("@chevre/factory/lib/chevre/assetTransaction/refund").IAttributes & {
111
+ id: string;
112
+ } & {
113
+ seller?: any;
114
+ } & {
115
+ _id: import("mongoose").Types.ObjectId;
116
+ } & {
117
+ __v: number;
118
+ }) | (import("@chevre/factory/lib/chevre/assetTransaction/reserve").IAttributes & {
119
+ id: string;
120
+ } & {
121
+ seller?: any;
122
+ } & {
123
+ _id: import("mongoose").Types.ObjectId;
124
+ } & {
125
+ __v: number;
126
+ }))) | null>;
127
+ unsetUnnecessaryFields(params: {
128
+ filter: any;
129
+ $unset: any;
130
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
131
+ }
132
+ export {};
@@ -0,0 +1,504 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminAssetTransactionRepo = void 0;
4
+ const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
5
+ const factory_1 = require("../factory");
6
+ const assetTransaction_2 = require("../eventEmitter/assetTransaction");
7
+ const settings_1 = require("../settings");
8
+ /**
9
+ * 資産取引管理リポジトリ
10
+ */
11
+ class AdminAssetTransactionRepo {
12
+ transactionModel;
13
+ constructor(connection) {
14
+ this.transactionModel = connection.model(assetTransaction_1.modelName, (0, assetTransaction_1.createSchema)());
15
+ }
16
+ static CREATE_MONGO_CONDITIONS(params) {
17
+ const andConditions = [
18
+ { typeOf: { $eq: params.typeOf } }
19
+ ];
20
+ const projectIdEq = params.project?.id?.$eq;
21
+ /* istanbul ignore else */
22
+ if (typeof projectIdEq === 'string') {
23
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
24
+ }
25
+ /* istanbul ignore else */
26
+ if (params.startFrom !== undefined) {
27
+ andConditions.push({
28
+ startDate: { $gte: params.startFrom }
29
+ });
30
+ }
31
+ /* istanbul ignore else */
32
+ if (params.startThrough !== undefined) {
33
+ andConditions.push({
34
+ startDate: { $lte: params.startThrough }
35
+ });
36
+ }
37
+ /* istanbul ignore else */
38
+ if (params.endFrom !== undefined) {
39
+ andConditions.push({
40
+ endDate: {
41
+ $exists: true,
42
+ $gte: params.endFrom
43
+ }
44
+ });
45
+ }
46
+ /* istanbul ignore else */
47
+ if (params.endThrough !== undefined) {
48
+ andConditions.push({
49
+ endDate: {
50
+ $exists: true,
51
+ $lt: params.endThrough
52
+ }
53
+ });
54
+ }
55
+ /* istanbul ignore else */
56
+ if (Array.isArray(params.ids)) {
57
+ andConditions.push({
58
+ _id: { $in: params.ids }
59
+ });
60
+ }
61
+ /* istanbul ignore else */
62
+ if (Array.isArray(params.statuses)) {
63
+ andConditions.push({ status: { $in: params.statuses } });
64
+ }
65
+ /* istanbul ignore else */
66
+ const statusIn = params.status?.$in;
67
+ if (Array.isArray(statusIn)) {
68
+ andConditions.push({ status: { $in: statusIn } });
69
+ }
70
+ /* istanbul ignore else */
71
+ if (params.agent !== undefined) {
72
+ if (Array.isArray(params.agent.ids)) {
73
+ andConditions.push({
74
+ 'agent.id': { $in: params.agent.ids }
75
+ });
76
+ }
77
+ }
78
+ const transactionNumberEq = params.transactionNumber?.$eq;
79
+ if (typeof transactionNumberEq === 'string') {
80
+ andConditions.push({ transactionNumber: { $eq: transactionNumberEq } });
81
+ }
82
+ const transactionNumberIn = params.transactionNumber?.$in;
83
+ if (Array.isArray(transactionNumberIn)) {
84
+ andConditions.push({ transactionNumber: { $in: transactionNumberIn } });
85
+ }
86
+ const tasksExportActionStatusIn = params.tasksExportAction?.actionStatus?.$in;
87
+ /* istanbul ignore else */
88
+ if (Array.isArray(tasksExportActionStatusIn)) {
89
+ andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $in: tasksExportActionStatusIn } });
90
+ }
91
+ const tasksExportActionStatusEq = params.tasksExportAction?.actionStatus?.$eq;
92
+ /* istanbul ignore else */
93
+ if (typeof tasksExportActionStatusEq === 'string') {
94
+ andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $eq: tasksExportActionStatusEq } });
95
+ }
96
+ switch (params.typeOf) {
97
+ case factory_1.factory.assetTransactionType.Pay: {
98
+ const objectAccountIdEq = params.object?.accountId?.$eq;
99
+ if (typeof objectAccountIdEq === 'string') {
100
+ andConditions.push({ 'object.accountId': { $exists: true, $eq: objectAccountIdEq } });
101
+ }
102
+ const objectTypeOfEq = params.object?.typeOf?.$eq;
103
+ if (typeof objectTypeOfEq === 'string') {
104
+ andConditions.push({ 'object.typeOf': { $exists: true, $eq: objectTypeOfEq } });
105
+ }
106
+ break;
107
+ }
108
+ case factory_1.factory.assetTransactionType.Refund: {
109
+ const objectAccountIdEq4refund = params.object?.accountId?.$eq;
110
+ if (typeof objectAccountIdEq4refund === 'string') {
111
+ andConditions.push({
112
+ 'object.accountId': {
113
+ $exists: true,
114
+ $eq: objectAccountIdEq4refund
115
+ }
116
+ });
117
+ }
118
+ const objectPaymentMethodIdEq4refund = params.object?.paymentMethodId?.$eq;
119
+ if (typeof objectPaymentMethodIdEq4refund === 'string') {
120
+ andConditions.push({
121
+ 'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq4refund }
122
+ });
123
+ }
124
+ const objectPaymentMethodIdIn4refund = params.object?.paymentMethodId?.$in;
125
+ if (Array.isArray(objectPaymentMethodIdIn4refund)) {
126
+ andConditions.push({
127
+ 'object.paymentMethodId': { $exists: true, $in: objectPaymentMethodIdIn4refund }
128
+ });
129
+ }
130
+ break;
131
+ }
132
+ case factory_1.factory.assetTransactionType.CancelReservation: {
133
+ const objectReservationNumberIn4cancelReservation = params.object?.reservationNumber?.$in;
134
+ if (Array.isArray(objectReservationNumberIn4cancelReservation)) {
135
+ andConditions.push({
136
+ 'object.reservationNumber': { $exists: true, $in: objectReservationNumberIn4cancelReservation }
137
+ });
138
+ }
139
+ const objectReservationNumberEq4cancelReservation = params.object?.reservationNumber?.$eq;
140
+ if (typeof objectReservationNumberEq4cancelReservation === 'string') {
141
+ andConditions.push({
142
+ 'object.reservationNumber': { $exists: true, $eq: objectReservationNumberEq4cancelReservation }
143
+ });
144
+ }
145
+ break;
146
+ }
147
+ case factory_1.factory.assetTransactionType.Reserve: {
148
+ // discontinue(2026-08-10~)
149
+ // const objectProviderIdEq = params.object?.provider?.id?.$eq;
150
+ // if (typeof objectProviderIdEq === 'string') {
151
+ // andConditions.push({ 'object.provider.id': { $exists: true, $eq: objectProviderIdEq } });
152
+ // }
153
+ const objectReservationForIdEq = params.object?.reservationFor?.id?.$eq;
154
+ if (typeof objectReservationForIdEq === 'string') {
155
+ andConditions.push({
156
+ 'object.reservationFor.id': {
157
+ $exists: true,
158
+ $eq: objectReservationForIdEq
159
+ }
160
+ });
161
+ }
162
+ const objectReservationNumberIn = params.object?.reservationNumber?.$in;
163
+ if (Array.isArray(objectReservationNumberIn)) {
164
+ andConditions.push({
165
+ 'object.reservationNumber': { $exists: true, $in: objectReservationNumberIn }
166
+ });
167
+ }
168
+ const objectReservationNumberEq = params.object?.reservationNumber?.$eq;
169
+ if (typeof objectReservationNumberEq === 'string') {
170
+ andConditions.push({
171
+ 'object.reservationNumber': { $exists: true, $eq: objectReservationNumberEq }
172
+ });
173
+ }
174
+ const objectSubReservationIdIn = params.object?.reservations?.id?.$in;
175
+ if (Array.isArray(objectSubReservationIdIn)) {
176
+ andConditions.push({
177
+ 'object.subReservation.id': {
178
+ $exists: true,
179
+ $in: objectSubReservationIdIn
180
+ }
181
+ });
182
+ }
183
+ if (params.object !== undefined) {
184
+ if (params.object.reservations !== undefined) {
185
+ // discontinue(2026-08-10~)
186
+ // if (params.object.reservations.reservationNumber !== undefined) {
187
+ // if (Array.isArray(params.object.reservations.reservationNumber.$in)) {
188
+ // andConditions.push({
189
+ // 'object.subReservation.reservationNumber': {
190
+ // $exists: true,
191
+ // $in: params.object.reservations.reservationNumber.$in
192
+ // }
193
+ // });
194
+ // }
195
+ // }
196
+ // discontinue(2026-08-10~)
197
+ // if (params.object.reservations.reservationFor !== undefined) {
198
+ // if (params.object.reservations.reservationFor.id !== undefined) {
199
+ // if (Array.isArray(params.object.reservations.reservationFor.id.$in)) {
200
+ // andConditions.push({
201
+ // 'object.subReservation.reservationFor.id': {
202
+ // $exists: true,
203
+ // $in: params.object.reservations.reservationFor.id.$in
204
+ // }
205
+ // });
206
+ // }
207
+ // }
208
+ // }
209
+ }
210
+ }
211
+ // discontinue(2026-08-10~)
212
+ // const objectUnderNameIdEq = params.object?.underName?.id?.$eq;
213
+ // if (typeof objectUnderNameIdEq === 'string') {
214
+ // andConditions.push({
215
+ // 'object.underName.id': {
216
+ // $exists: true,
217
+ // $eq: objectUnderNameIdEq
218
+ // }
219
+ // });
220
+ // }
221
+ const objectSubReservationSeatNumberEq = params.object?.reservations?.reservedTicket?.ticketedSeat?.seatNumber?.$eq;
222
+ if (typeof objectSubReservationSeatNumberEq === 'string') {
223
+ andConditions.push({
224
+ 'object.subReservation.reservedTicket.ticketedSeat.seatNumber': {
225
+ $exists: true,
226
+ $eq: objectSubReservationSeatNumberEq
227
+ }
228
+ });
229
+ }
230
+ break;
231
+ }
232
+ default:
233
+ }
234
+ return andConditions;
235
+ }
236
+ async countPotentiallyExportTasks(params) {
237
+ const { endDate, limit } = params;
238
+ const endDateLt = endDate?.$lt;
239
+ if (!(endDateLt instanceof Date)) {
240
+ throw new factory_1.factory.errors.Argument('endDate.$lt', 'must be Date');
241
+ }
242
+ const query = this.transactionModel.countDocuments({
243
+ status: {
244
+ $in: [
245
+ factory_1.factory.transactionStatusType.Canceled,
246
+ factory_1.factory.transactionStatusType.Confirmed,
247
+ factory_1.factory.transactionStatusType.Expired
248
+ ]
249
+ },
250
+ 'tasksExportAction.actionStatus': {
251
+ $exists: true,
252
+ $eq: factory_1.factory.actionStatusType.PotentialActionStatus
253
+ },
254
+ endDate: { $exists: true, $lt: endDateLt }
255
+ });
256
+ if (typeof limit === 'number' && limit >= 0) {
257
+ query.limit(limit);
258
+ }
259
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
260
+ .exec();
261
+ return { count };
262
+ }
263
+ /**
264
+ * tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
265
+ * PotentialActionStatusに変更する
266
+ * 2025-03-10~
267
+ */
268
+ async reExportAction(params) {
269
+ const { startDate } = params;
270
+ if (!(startDate.$lt instanceof Date)) {
271
+ throw new factory_1.factory.errors.Argument('startDate.$lt', 'must be Date');
272
+ }
273
+ return this.transactionModel.updateMany({
274
+ 'tasksExportAction.actionStatus': {
275
+ $exists: true,
276
+ $eq: factory_1.factory.actionStatusType.ActiveActionStatus
277
+ },
278
+ 'tasksExportAction.startDate': {
279
+ $exists: true,
280
+ $lt: startDate.$lt
281
+ }
282
+ }, {
283
+ $set: {
284
+ tasksExportAction: {
285
+ actionStatus: factory_1.factory.actionStatusType.PotentialActionStatus
286
+ }
287
+ }
288
+ })
289
+ .exec();
290
+ }
291
+ // /**
292
+ // * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
293
+ // */
294
+ // public async exportTasksMany(params: {
295
+ // now: Date;
296
+ // delayInSeconds: number;
297
+ // status: {
298
+ // $in: factory.transactionStatusType[];
299
+ // };
300
+ // limit: number;
301
+ // }) {
302
+ // const delayedTransactions = await this.transactionModel.find({
303
+ // status: { $in: params.status.$in },
304
+ // 'tasksExportAction.actionStatus': {
305
+ // $exists: true,
306
+ // $eq: factory.actionStatusType.PotentialActionStatus
307
+ // },
308
+ // endDate: {
309
+ // $exists: true,
310
+ // $lt: moment(params.now)
311
+ // .add(-params.delayInSeconds, 'seconds')
312
+ // .toDate()
313
+ // }
314
+ // })
315
+ // .select({
316
+ // _id: 0,
317
+ // id: { $toString: '$_id' },
318
+ // typeOf: 1,
319
+ // status: 1
320
+ // })
321
+ // .limit(params.limit)
322
+ // .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
323
+ // .lean<Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'id' | 'status' | 'typeOf'>[]>()
324
+ // .exec();
325
+ // if (delayedTransactions.length > 0) {
326
+ // delayedTransactions.forEach((delayedTransaction) => {
327
+ // assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
328
+ // id: delayedTransaction.id,
329
+ // typeOf: delayedTransaction.typeOf,
330
+ // status: delayedTransaction.status
331
+ // });
332
+ // });
333
+ // }
334
+ // return delayedTransactions;
335
+ // }
336
+ /**
337
+ * add(2025-03-17~)
338
+ */
339
+ async countPotentiallyExpired(params) {
340
+ const { expires, limit } = params;
341
+ const query = this.transactionModel.countDocuments({
342
+ status: { $eq: factory_1.factory.transactionStatusType.InProgress },
343
+ expires: { $lt: expires.$lt }
344
+ });
345
+ if (typeof limit === 'number' && limit >= 0) {
346
+ query.limit(limit);
347
+ }
348
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
349
+ .exec();
350
+ return { count };
351
+ }
352
+ /**
353
+ * add(2025-03-12~)
354
+ */
355
+ async makeOneExpiredIfExists(params) {
356
+ const endDate = new Date();
357
+ const sort = {
358
+ expires: factory_1.factory.sortType.Ascending
359
+ };
360
+ const doc = await this.transactionModel.findOneAndUpdate({
361
+ status: { $eq: factory_1.factory.transactionStatusType.InProgress },
362
+ expires: { $lt: params.expires.$lt }
363
+ }, {
364
+ status: factory_1.factory.transactionStatusType.Expired,
365
+ endDate
366
+ }, {
367
+ new: true,
368
+ projection: {
369
+ _id: 0,
370
+ id: { $toString: '$_id' },
371
+ typeOf: 1
372
+ }
373
+ })
374
+ .sort(sort)
375
+ .lean()
376
+ .exec();
377
+ if (doc === null) {
378
+ // no op
379
+ return;
380
+ }
381
+ else {
382
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
383
+ id: doc.id,
384
+ typeOf: doc.typeOf,
385
+ status: factory_1.factory.transactionStatusType.Expired
386
+ });
387
+ return doc;
388
+ }
389
+ }
390
+ // /**
391
+ // * 取引を期限切れにする
392
+ // */
393
+ // public async makeExpired(params: {
394
+ // expires: { $lt: Date };
395
+ // }): Promise<void> {
396
+ // // IDをemitしたいのでまずリスト検索(2023-04-27~)
397
+ // const expiringTransactions: Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'id' | 'typeOf'>[] =
398
+ // await this.transactionModel.find({
399
+ // status: { $eq: factory.transactionStatusType.InProgress },
400
+ // expires: { $lt: params.expires.$lt }
401
+ // })
402
+ // .select({
403
+ // _id: 1,
404
+ // typeOf: 1
405
+ // })
406
+ // .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
407
+ // .exec();
408
+ // if (expiringTransactions.length > 0) {
409
+ // // ステータスと期限を見て更新
410
+ // await this.transactionModel.updateMany(
411
+ // {
412
+ // _id: { $in: expiringTransactions.map((t) => t.id) },
413
+ // status: { $eq: factory.transactionStatusType.InProgress },
414
+ // expires: { $lt: params.expires.$lt }
415
+ // },
416
+ // {
417
+ // status: factory.transactionStatusType.Expired,
418
+ // endDate: new Date()
419
+ // }
420
+ // )
421
+ // .exec();
422
+ // expiringTransactions.forEach((expiringTransaction) => {
423
+ // assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
424
+ // id: expiringTransaction.id,
425
+ // typeOf: expiringTransaction.typeOf,
426
+ // status: factory.transactionStatusType.Expired
427
+ // });
428
+ // });
429
+ // }
430
+ // }
431
+ async countAssetTransactions(params) {
432
+ const { limit } = params;
433
+ const conditions = AdminAssetTransactionRepo.CREATE_MONGO_CONDITIONS(params);
434
+ const query = this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
435
+ if (typeof limit === 'number' && limit >= 0) {
436
+ query.limit(limit);
437
+ }
438
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
439
+ .exec();
440
+ return { count };
441
+ }
442
+ /**
443
+ * 取引を検索する
444
+ */
445
+ async findAssetTransactions(params, inclusion, exclusion) {
446
+ const conditions = AdminAssetTransactionRepo.CREATE_MONGO_CONDITIONS(params);
447
+ let projection = {};
448
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
449
+ inclusion.forEach((field) => {
450
+ projection[field] = 1;
451
+ });
452
+ }
453
+ else {
454
+ projection = {
455
+ __v: 0,
456
+ createdAt: 0,
457
+ updatedAt: 0
458
+ };
459
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
460
+ exclusion.forEach((field) => {
461
+ projection[field] = 0;
462
+ });
463
+ }
464
+ }
465
+ const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
466
+ .select(projection);
467
+ if (typeof params.limit === 'number' && params.limit > 0) {
468
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
469
+ query.limit(params.limit)
470
+ .skip(params.limit * (page - 1));
471
+ }
472
+ /* istanbul ignore else */
473
+ if (params.sort?.startDate !== undefined) {
474
+ query.sort({ startDate: params.sort.startDate });
475
+ }
476
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
477
+ .exec()
478
+ .then((docs) => docs.map((doc) => doc.toObject()));
479
+ }
480
+ /**
481
+ * 終了日時を一定期間過ぎたアクションを削除する
482
+ */
483
+ async deleteEndDatePassedCertainPeriod(params) {
484
+ return this.transactionModel.deleteMany({
485
+ // 終了日時を一定期間過ぎたもの
486
+ endDate: {
487
+ $exists: true,
488
+ $lt: params.$lt
489
+ }
490
+ })
491
+ .exec();
492
+ }
493
+ getCursor(conditions, projection) {
494
+ return this.transactionModel.find(conditions, projection)
495
+ // .sort({ startDate: factory.sortType.Ascending })
496
+ .sort({ startDate: factory_1.factory.sortType.Descending })
497
+ .cursor();
498
+ }
499
+ async unsetUnnecessaryFields(params) {
500
+ return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
501
+ .exec();
502
+ }
503
+ }
504
+ exports.AdminAssetTransactionRepo = AdminAssetTransactionRepo;
@@ -0,0 +1,43 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ interface IAggregationByStatus {
4
+ transactionCount: number;
5
+ avgDuration: number;
6
+ maxDuration: number;
7
+ minDuration: number;
8
+ percentilesDuration: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ reservationCount: number;
13
+ avgGraceTime: number;
14
+ maxGraceTime: number;
15
+ minGraceTime: number;
16
+ }
17
+ interface IStatus {
18
+ status: factory.transactionStatusType;
19
+ aggregation: IAggregationByStatus;
20
+ }
21
+ export interface IAggregateReserve {
22
+ statuses: IStatus[];
23
+ }
24
+ /**
25
+ * 資産取引集計リポジトリ
26
+ */
27
+ export declare class AggregateAssetTransactionRepo {
28
+ private readonly transactionModel;
29
+ constructor(connection: Connection);
30
+ aggregateAssetTransaction(params: {
31
+ project?: {
32
+ id?: {
33
+ $eq?: string;
34
+ $ne?: string;
35
+ };
36
+ };
37
+ startFrom: Date;
38
+ startThrough: Date;
39
+ typeOf: factory.assetTransactionType;
40
+ }): Promise<IAggregateReserve>;
41
+ private agggregateByStatus;
42
+ }
43
+ export {};