@chevre/domain 20.2.0-alpha.4 → 20.2.0-alpha.41
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.
- package/example/src/chevre/aggregateEventReservation.ts +37 -0
- package/example/src/chevre/aggregation/aggregateSystem.ts +112 -0
- package/example/src/chevre/attendIfNotAttended.ts +22 -0
- package/example/src/chevre/findScreeningRoomsByBranchCode.ts +27 -0
- package/example/src/chevre/importEventsFromCOA.ts +8 -1
- package/example/src/chevre/migrateEventOffersItemOfferedAvailableChannel.ts +2 -1
- package/example/src/chevre/migrateProjectSubscription.ts +51 -0
- package/example/src/chevre/processReserve.ts +2 -0
- package/example/src/chevre/searchEventIds.ts +24 -0
- package/example/src/chevre/searchEventTicketOffers.ts +4 -4
- package/example/src/chevre/searchEvents.ts +20 -41
- package/example/src/chevre/searchOffersByCatalog.ts +27 -0
- package/example/src/chevre/updateTransaction.ts +38 -0
- package/lib/chevre/factory/event.d.ts +2 -0
- package/lib/chevre/factory/event.js +2 -0
- package/lib/chevre/repo/action.d.ts +67 -0
- package/lib/chevre/repo/action.js +209 -0
- package/lib/chevre/repo/aggregation.d.ts +37 -0
- package/lib/chevre/repo/aggregation.js +67 -0
- package/lib/chevre/repo/assetTransaction.d.ts +32 -0
- package/lib/chevre/repo/assetTransaction.js +148 -0
- package/lib/chevre/repo/event.d.ts +62 -16
- package/lib/chevre/repo/event.js +458 -156
- package/lib/chevre/repo/mongoose/model/aggregation.d.ts +7 -0
- package/lib/chevre/repo/mongoose/model/aggregation.js +47 -0
- package/lib/chevre/repo/mongoose/model/event.js +4 -3
- package/lib/chevre/repo/mongoose/model/offer.js +2 -1
- package/lib/chevre/repo/mongoose/model/project.js +7 -1
- package/lib/chevre/repo/mongoose/model/telemetry.js +4 -28
- package/lib/chevre/repo/offer.d.ts +10 -0
- package/lib/chevre/repo/offer.js +47 -16
- package/lib/chevre/repo/order.d.ts +2 -0
- package/lib/chevre/repo/order.js +29 -7
- package/lib/chevre/repo/place.d.ts +26 -1
- package/lib/chevre/repo/place.js +216 -12
- package/lib/chevre/repo/product.d.ts +1 -0
- package/lib/chevre/repo/product.js +5 -0
- package/lib/chevre/repo/project.d.ts +4 -1
- package/lib/chevre/repo/project.js +9 -10
- package/lib/chevre/repo/reservation.d.ts +3 -7
- package/lib/chevre/repo/reservation.js +134 -75
- package/lib/chevre/repo/task.d.ts +31 -3
- package/lib/chevre/repo/task.js +141 -27
- package/lib/chevre/repo/transaction.d.ts +45 -5
- package/lib/chevre/repo/transaction.js +187 -29
- package/lib/chevre/repo/trip.js +33 -27
- package/lib/chevre/repository.d.ts +3 -0
- package/lib/chevre/repository.js +5 -1
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +1 -1
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +86 -59
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +5 -8
- package/lib/chevre/service/aggregation/system.d.ts +93 -0
- package/lib/chevre/service/aggregation/system.js +377 -0
- package/lib/chevre/service/aggregation.d.ts +2 -0
- package/lib/chevre/service/aggregation.js +3 -1
- package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.js +5 -1
- package/lib/chevre/service/assetTransaction/pay/potentialActions.js +2 -4
- package/lib/chevre/service/assetTransaction/pay.d.ts +19 -4
- package/lib/chevre/service/assetTransaction/pay.js +65 -32
- package/lib/chevre/service/assetTransaction/registerService.js +4 -1
- package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +3 -0
- package/lib/chevre/service/assetTransaction/reserve/factory.js +33 -2
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +16 -0
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +84 -0
- package/lib/chevre/service/assetTransaction/reserve.d.ts +38 -6
- package/lib/chevre/service/assetTransaction/reserve.js +119 -94
- package/lib/chevre/service/delivery/factory.d.ts +1 -1
- package/lib/chevre/service/delivery/factory.js +1 -0
- package/lib/chevre/service/event.d.ts +2 -4
- package/lib/chevre/service/event.js +35 -14
- package/lib/chevre/service/offer/event/authorize.d.ts +4 -7
- package/lib/chevre/service/offer/event/authorize.js +26 -87
- package/lib/chevre/service/offer/event/cancel.js +0 -1
- package/lib/chevre/service/offer/event/factory.d.ts +3 -2
- package/lib/chevre/service/offer/event/factory.js +25 -5
- package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +13 -7
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +81 -45
- package/lib/chevre/service/offer/event/voidTransaction.js +0 -2
- package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
- package/lib/chevre/service/offer/eventServiceByCOA.js +10 -2
- package/lib/chevre/service/offer/factory.js +10 -3
- package/lib/chevre/service/offer/product/searchProductOffers.d.ts +1 -0
- package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
- package/lib/chevre/service/offer/product.d.ts +1 -0
- package/lib/chevre/service/offer/product.js +6 -2
- package/lib/chevre/service/offer.d.ts +5 -1
- package/lib/chevre/service/offer.js +67 -46
- package/lib/chevre/service/order/onOrderStatusChanged/factory.js +2 -1
- package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
- package/lib/chevre/service/order/placeOrder.js +16 -0
- package/lib/chevre/service/order/returnOrder.js +1 -1
- package/lib/chevre/service/order/sendOrder.js +4 -2
- package/lib/chevre/service/payment/any.d.ts +5 -0
- package/lib/chevre/service/payment/any.js +1 -1
- package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
- package/lib/chevre/service/payment/movieTicket.js +8 -2
- package/lib/chevre/service/reserve/confirmReservation.js +7 -10
- package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +2 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +32 -35
- package/lib/chevre/service/reserve/useReservation.d.ts +0 -3
- package/lib/chevre/service/reserve/useReservation.js +43 -25
- package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
- package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
- package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
- package/lib/chevre/service/task/returnPayTransaction.js +5 -1
- package/lib/chevre/service/task.js +6 -9
- package/lib/chevre/service/transaction/orderProgramMembership.js +2 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +42 -27
- package/lib/chevre/service/transaction/placeOrderInProgress.js +7 -7
- package/lib/chevre/service/transaction/returnOrder.js +3 -3
- package/lib/chevre/settings.d.ts +2 -0
- package/lib/chevre/settings.js +20 -12
- package/package.json +3 -3
- package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
- package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
package/lib/chevre/repo/task.js
CHANGED
|
@@ -29,29 +29,24 @@ class MongoRepository {
|
|
|
29
29
|
}
|
|
30
30
|
// tslint:disable-next-line:max-func-body-length
|
|
31
31
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
33
|
-
const andConditions = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/* istanbul ignore else */
|
|
38
|
-
if (params.project !== undefined) {
|
|
39
|
-
if (params.project.id !== undefined && params.project.id !== null) {
|
|
40
|
-
if (typeof params.project.id.$eq === 'string') {
|
|
41
|
-
andConditions.push({
|
|
42
|
-
'project.id': {
|
|
43
|
-
$eq: params.project.id.$eq
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
33
|
+
const andConditions = [];
|
|
34
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
35
|
+
if (typeof projectIdEq === 'string') {
|
|
36
|
+
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
48
37
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
if (typeof params.name === 'string') {
|
|
39
|
+
andConditions.push({ name: { $eq: params.name } });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const nameIn = (_c = params.name) === null || _c === void 0 ? void 0 : _c.$in;
|
|
43
|
+
if (Array.isArray(nameIn)) {
|
|
44
|
+
andConditions.push({ name: { $in: nameIn } });
|
|
45
|
+
}
|
|
46
|
+
const nameNin = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$nin;
|
|
47
|
+
if (Array.isArray(nameNin)) {
|
|
48
|
+
andConditions.push({ name: { $nin: nameNin } });
|
|
49
|
+
}
|
|
55
50
|
}
|
|
56
51
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
57
52
|
/* istanbul ignore else */
|
|
@@ -94,7 +89,7 @@ class MongoRepository {
|
|
|
94
89
|
}
|
|
95
90
|
});
|
|
96
91
|
}
|
|
97
|
-
const dateAbortedGte = (
|
|
92
|
+
const dateAbortedGte = (_e = params.dateAborted) === null || _e === void 0 ? void 0 : _e.$gte;
|
|
98
93
|
if (dateAbortedGte instanceof Date) {
|
|
99
94
|
andConditions.push({
|
|
100
95
|
dateAborted: {
|
|
@@ -103,7 +98,7 @@ class MongoRepository {
|
|
|
103
98
|
}
|
|
104
99
|
});
|
|
105
100
|
}
|
|
106
|
-
const dateAbortedLte = (
|
|
101
|
+
const dateAbortedLte = (_f = params.dateAborted) === null || _f === void 0 ? void 0 : _f.$lte;
|
|
107
102
|
if (dateAbortedLte instanceof Date) {
|
|
108
103
|
andConditions.push({
|
|
109
104
|
dateAborted: {
|
|
@@ -112,7 +107,7 @@ class MongoRepository {
|
|
|
112
107
|
}
|
|
113
108
|
});
|
|
114
109
|
}
|
|
115
|
-
const objectTransactionNumberEq = (
|
|
110
|
+
const objectTransactionNumberEq = (_j = (_h = (_g = params.data) === null || _g === void 0 ? void 0 : _g.object) === null || _h === void 0 ? void 0 : _h.transactionNumber) === null || _j === void 0 ? void 0 : _j.$eq;
|
|
116
111
|
if (typeof objectTransactionNumberEq === 'string') {
|
|
117
112
|
andConditions.push({
|
|
118
113
|
'data.object.transactionNumber': {
|
|
@@ -121,7 +116,7 @@ class MongoRepository {
|
|
|
121
116
|
}
|
|
122
117
|
});
|
|
123
118
|
}
|
|
124
|
-
const objectPurposeIdEq = (
|
|
119
|
+
const objectPurposeIdEq = (_m = (_l = (_k = params.data) === null || _k === void 0 ? void 0 : _k.purpose) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$eq;
|
|
125
120
|
if (typeof objectPurposeIdEq === 'string') {
|
|
126
121
|
andConditions.push({
|
|
127
122
|
'data.purpose.id': {
|
|
@@ -130,7 +125,7 @@ class MongoRepository {
|
|
|
130
125
|
}
|
|
131
126
|
});
|
|
132
127
|
}
|
|
133
|
-
const objectPurposeOrderNumberEq = (
|
|
128
|
+
const objectPurposeOrderNumberEq = (_q = (_p = (_o = params.data) === null || _o === void 0 ? void 0 : _o.purpose) === null || _p === void 0 ? void 0 : _p.orderNumber) === null || _q === void 0 ? void 0 : _q.$eq;
|
|
134
129
|
if (typeof objectPurposeOrderNumberEq === 'string') {
|
|
135
130
|
andConditions.push({
|
|
136
131
|
'data.purpose.orderNumber': {
|
|
@@ -312,5 +307,124 @@ class MongoRepository {
|
|
|
312
307
|
.exec();
|
|
313
308
|
});
|
|
314
309
|
}
|
|
310
|
+
aggregateTask(params) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
const statuses = yield Promise.all([
|
|
313
|
+
factory.taskStatus.Executed,
|
|
314
|
+
factory.taskStatus.Aborted
|
|
315
|
+
].map((taskStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
const matchConditions = Object.assign({ runsAt: {
|
|
318
|
+
$gte: params.runsFrom,
|
|
319
|
+
$lte: params.runsThrough
|
|
320
|
+
}, status: { $eq: taskStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
321
|
+
? { 'project.id': { $ne: params.project.id.$ne } }
|
|
322
|
+
: undefined);
|
|
323
|
+
return this.agggregateByStatus({ matchConditions, status: taskStatus });
|
|
324
|
+
})));
|
|
325
|
+
return { statuses };
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
// tslint:disable-next-line:max-func-body-length
|
|
329
|
+
agggregateByStatus(params) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
const matchConditions = params.matchConditions;
|
|
332
|
+
const taskStatus = params.status;
|
|
333
|
+
const aggregations = yield this.taskModel.aggregate([
|
|
334
|
+
{
|
|
335
|
+
$match: matchConditions
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
$project: {
|
|
339
|
+
latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
|
|
340
|
+
status: '$status',
|
|
341
|
+
runsAt: '$runsAt',
|
|
342
|
+
lastTriedAt: '$lastTriedAt'
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
$group: {
|
|
347
|
+
_id: '$status',
|
|
348
|
+
taskCount: { $sum: 1 },
|
|
349
|
+
maxLatency: { $max: '$latency' },
|
|
350
|
+
minLatency: { $min: '$latency' },
|
|
351
|
+
avgLatency: { $avg: '$latency' }
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
$project: {
|
|
356
|
+
_id: 0,
|
|
357
|
+
taskCount: '$taskCount',
|
|
358
|
+
avgLatency: '$avgLatency',
|
|
359
|
+
maxLatency: '$maxLatency',
|
|
360
|
+
minLatency: '$minLatency'
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
])
|
|
364
|
+
.exec();
|
|
365
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
366
|
+
const percents = [50, 95, 99];
|
|
367
|
+
if (aggregations.length === 0) {
|
|
368
|
+
return {
|
|
369
|
+
status: taskStatus,
|
|
370
|
+
aggregation: {
|
|
371
|
+
taskCount: 0,
|
|
372
|
+
avgLatency: 0,
|
|
373
|
+
maxLatency: 0,
|
|
374
|
+
minLatency: 0,
|
|
375
|
+
percentilesLatency: percents.map((percent) => {
|
|
376
|
+
return {
|
|
377
|
+
name: String(percent),
|
|
378
|
+
value: 0
|
|
379
|
+
};
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
385
|
+
return {
|
|
386
|
+
percentile,
|
|
387
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
388
|
+
rank: Math.floor(aggregations[0].taskCount * percentile / 100)
|
|
389
|
+
};
|
|
390
|
+
});
|
|
391
|
+
const aggregations2 = yield this.taskModel.aggregate([
|
|
392
|
+
{
|
|
393
|
+
$match: matchConditions
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
$project: {
|
|
397
|
+
latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
|
|
398
|
+
status: '$status',
|
|
399
|
+
runsAt: '$runsAt',
|
|
400
|
+
lastTriedAt: '$lastTriedAt'
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
{ $sort: { latency: 1 } },
|
|
404
|
+
{
|
|
405
|
+
$group: {
|
|
406
|
+
_id: '$status',
|
|
407
|
+
latencies: { $push: '$latency' }
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
$project: {
|
|
412
|
+
_id: 0,
|
|
413
|
+
percentilesLatency: ranks4percentile.map((rank) => {
|
|
414
|
+
return {
|
|
415
|
+
name: String(rank.percentile),
|
|
416
|
+
value: { $arrayElemAt: ['$latencies', rank.rank] }
|
|
417
|
+
};
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
])
|
|
422
|
+
.exec();
|
|
423
|
+
return {
|
|
424
|
+
status: taskStatus,
|
|
425
|
+
aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
}
|
|
315
429
|
}
|
|
316
430
|
exports.MongoRepository = MongoRepository;
|
|
@@ -2,6 +2,29 @@ import { Connection } from 'mongoose';
|
|
|
2
2
|
import * as factory from '../factory';
|
|
3
3
|
import { modelName } from './mongoose/model/transaction';
|
|
4
4
|
export { modelName };
|
|
5
|
+
interface IAggregationByStatus {
|
|
6
|
+
transactionCount: number;
|
|
7
|
+
avgDuration: number;
|
|
8
|
+
maxDuration: number;
|
|
9
|
+
minDuration: number;
|
|
10
|
+
percentilesDuration: {
|
|
11
|
+
name: string;
|
|
12
|
+
value: number;
|
|
13
|
+
}[];
|
|
14
|
+
acceptedOfferCount: number;
|
|
15
|
+
avgAcceptedOfferCount: number;
|
|
16
|
+
totalPrice: number;
|
|
17
|
+
maxPrice: number;
|
|
18
|
+
minPrice: number;
|
|
19
|
+
avgPrice: number;
|
|
20
|
+
}
|
|
21
|
+
interface IStatus {
|
|
22
|
+
status: factory.transactionStatusType;
|
|
23
|
+
aggregation: IAggregationByStatus;
|
|
24
|
+
}
|
|
25
|
+
export interface IAggregatePlaceOrder {
|
|
26
|
+
statuses: IStatus[];
|
|
27
|
+
}
|
|
5
28
|
/**
|
|
6
29
|
* 取引リポジトリ
|
|
7
30
|
*/
|
|
@@ -66,7 +89,7 @@ export declare class MongoRepository {
|
|
|
66
89
|
authorizeActions: factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>>[];
|
|
67
90
|
result: factory.transaction.IResult<T>;
|
|
68
91
|
potentialActions: factory.transaction.IPotentialActions<T>;
|
|
69
|
-
}): Promise<
|
|
92
|
+
}): Promise<void>;
|
|
70
93
|
/**
|
|
71
94
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
72
95
|
*/
|
|
@@ -105,7 +128,7 @@ export declare class MongoRepository {
|
|
|
105
128
|
cancel<T extends factory.transactionType>(params: {
|
|
106
129
|
typeOf: T;
|
|
107
130
|
id: string;
|
|
108
|
-
}): Promise<
|
|
131
|
+
}): Promise<void>;
|
|
109
132
|
count<T extends factory.transactionType>(params: factory.transaction.ISearchConditions<T>): Promise<number>;
|
|
110
133
|
/**
|
|
111
134
|
* 取引を検索する
|
|
@@ -114,10 +137,15 @@ export declare class MongoRepository {
|
|
|
114
137
|
/**
|
|
115
138
|
* 特定の取引を更新する(汎用)
|
|
116
139
|
*/
|
|
117
|
-
findByIdAndUpdate
|
|
140
|
+
findByIdAndUpdate(params: {
|
|
118
141
|
id: string;
|
|
119
|
-
update:
|
|
120
|
-
|
|
142
|
+
update: {
|
|
143
|
+
$set?: any;
|
|
144
|
+
$unset?: any;
|
|
145
|
+
$pull?: any;
|
|
146
|
+
$push?: any;
|
|
147
|
+
};
|
|
148
|
+
}): Promise<void>;
|
|
121
149
|
saveOrderNumberIfNotExist(params: {
|
|
122
150
|
id: string;
|
|
123
151
|
orderNumber: string;
|
|
@@ -129,4 +157,16 @@ export declare class MongoRepository {
|
|
|
129
157
|
findByIdAndDelete(params: {
|
|
130
158
|
id: string;
|
|
131
159
|
}): Promise<void>;
|
|
160
|
+
aggregatePlaceOrder(params: {
|
|
161
|
+
project?: {
|
|
162
|
+
id?: {
|
|
163
|
+
$ne?: string;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
startFrom: Date;
|
|
167
|
+
startThrough: Date;
|
|
168
|
+
typeOf: factory.transactionType;
|
|
169
|
+
clientId?: string;
|
|
170
|
+
}): Promise<IAggregatePlaceOrder>;
|
|
171
|
+
private agggregateByStatus;
|
|
132
172
|
}
|
|
@@ -313,6 +313,8 @@ class MongoRepository {
|
|
|
313
313
|
status: factory.transactionStatusType.InProgress
|
|
314
314
|
}, {
|
|
315
315
|
$set: Object.assign(Object.assign({ 'agent.id': params.agent.id }, (typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined), (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { 'object.customer': params.object.customer } : undefined)
|
|
316
|
+
}, {
|
|
317
|
+
projection: { _id: 1 }
|
|
316
318
|
})
|
|
317
319
|
.exec();
|
|
318
320
|
if (doc === null) {
|
|
@@ -333,6 +335,8 @@ class MongoRepository {
|
|
|
333
335
|
$set: {
|
|
334
336
|
expires: params.expires
|
|
335
337
|
}
|
|
338
|
+
}, {
|
|
339
|
+
projection: { _id: 1 }
|
|
336
340
|
})
|
|
337
341
|
.exec();
|
|
338
342
|
if (doc === null) {
|
|
@@ -353,6 +357,8 @@ class MongoRepository {
|
|
|
353
357
|
status: factory.transactionStatusType.InProgress
|
|
354
358
|
}, {
|
|
355
359
|
$set: Object.assign({}, (typeof ((_a = params.object) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? { 'object.name': params.object.name } : undefined)
|
|
360
|
+
}, {
|
|
361
|
+
projection: { _id: 1 }
|
|
356
362
|
})
|
|
357
363
|
.exec();
|
|
358
364
|
if (doc === null) {
|
|
@@ -375,7 +381,10 @@ class MongoRepository {
|
|
|
375
381
|
'object.authorizeActions': params.authorizeActions,
|
|
376
382
|
result: params.result,
|
|
377
383
|
potentialActions: params.potentialActions // resultを更新
|
|
378
|
-
}, {
|
|
384
|
+
}, {
|
|
385
|
+
new: true,
|
|
386
|
+
projection: { _id: 1 }
|
|
387
|
+
})
|
|
379
388
|
.exec();
|
|
380
389
|
// NotFoundであれば取引状態確認
|
|
381
390
|
if (doc === null) {
|
|
@@ -384,7 +393,7 @@ class MongoRepository {
|
|
|
384
393
|
/* istanbul ignore next */
|
|
385
394
|
if (transaction.status === factory.transactionStatusType.Confirmed) {
|
|
386
395
|
// すでに確定済の場合
|
|
387
|
-
return
|
|
396
|
+
return;
|
|
388
397
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
389
398
|
/* istanbul ignore next */
|
|
390
399
|
}
|
|
@@ -402,7 +411,7 @@ class MongoRepository {
|
|
|
402
411
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
403
412
|
}
|
|
404
413
|
}
|
|
405
|
-
return doc.toObject();
|
|
414
|
+
// return doc.toObject();
|
|
406
415
|
});
|
|
407
416
|
}
|
|
408
417
|
/**
|
|
@@ -485,7 +494,10 @@ class MongoRepository {
|
|
|
485
494
|
}, {
|
|
486
495
|
status: factory.transactionStatusType.Canceled,
|
|
487
496
|
endDate: endDate
|
|
488
|
-
}, {
|
|
497
|
+
}, {
|
|
498
|
+
new: true,
|
|
499
|
+
projection: { _id: 1 }
|
|
500
|
+
})
|
|
489
501
|
.exec();
|
|
490
502
|
// NotFoundであれば取引状態確認
|
|
491
503
|
if (doc === null) {
|
|
@@ -494,7 +506,7 @@ class MongoRepository {
|
|
|
494
506
|
/* istanbul ignore next */
|
|
495
507
|
if (transaction.status === factory.transactionStatusType.Canceled) {
|
|
496
508
|
// すでに中止済の場合
|
|
497
|
-
return
|
|
509
|
+
return;
|
|
498
510
|
}
|
|
499
511
|
else if (transaction.status === factory.transactionStatusType.Expired) {
|
|
500
512
|
throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
|
|
@@ -506,7 +518,7 @@ class MongoRepository {
|
|
|
506
518
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
507
519
|
}
|
|
508
520
|
}
|
|
509
|
-
return doc.toObject();
|
|
521
|
+
// return doc.toObject();
|
|
510
522
|
});
|
|
511
523
|
}
|
|
512
524
|
count(params) {
|
|
@@ -542,43 +554,26 @@ class MongoRepository {
|
|
|
542
554
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
543
555
|
});
|
|
544
556
|
}
|
|
545
|
-
// public stream<T extends factory.transactionType>(
|
|
546
|
-
// params: factory.transaction.ISearchConditions<T>
|
|
547
|
-
// ): QueryCursor<Document> {
|
|
548
|
-
// const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
549
|
-
// const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
|
|
550
|
-
// .select({ __v: 0, createdAt: 0, updatedAt: 0 });
|
|
551
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
552
|
-
// /* istanbul ignore else */
|
|
553
|
-
// if (params.limit !== undefined && params.page !== undefined) {
|
|
554
|
-
// query.limit(params.limit)
|
|
555
|
-
// .skip(params.limit * (params.page - 1));
|
|
556
|
-
// }
|
|
557
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
558
|
-
// /* istanbul ignore else */
|
|
559
|
-
// if (params.sort !== undefined) {
|
|
560
|
-
// query.sort(params.sort);
|
|
561
|
-
// }
|
|
562
|
-
// return query.cursor();
|
|
563
|
-
// }
|
|
564
557
|
/**
|
|
565
558
|
* 特定の取引を更新する(汎用)
|
|
566
559
|
*/
|
|
567
560
|
findByIdAndUpdate(params) {
|
|
568
561
|
return __awaiter(this, void 0, void 0, function* () {
|
|
569
|
-
|
|
562
|
+
yield this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, {
|
|
563
|
+
// new: true,
|
|
564
|
+
projection: { _id: 1 }
|
|
565
|
+
})
|
|
570
566
|
.exec()
|
|
571
567
|
.then((doc) => {
|
|
572
568
|
if (doc === null) {
|
|
573
569
|
throw new factory.errors.ArgumentNull(this.transactionModel.modelName);
|
|
574
570
|
}
|
|
575
|
-
return doc.toObject();
|
|
576
571
|
});
|
|
577
572
|
});
|
|
578
573
|
}
|
|
579
574
|
saveOrderNumberIfNotExist(params) {
|
|
580
575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
581
|
-
yield this.transactionModel.
|
|
576
|
+
yield this.transactionModel.updateOne({
|
|
582
577
|
_id: params.id,
|
|
583
578
|
'object.orderNumber': { $exists: false }
|
|
584
579
|
}, { 'object.orderNumber': params.orderNumber })
|
|
@@ -587,7 +582,7 @@ class MongoRepository {
|
|
|
587
582
|
}
|
|
588
583
|
saveConfirmationNumberIfNotExist(params) {
|
|
589
584
|
return __awaiter(this, void 0, void 0, function* () {
|
|
590
|
-
yield this.transactionModel.
|
|
585
|
+
yield this.transactionModel.updateOne({
|
|
591
586
|
_id: params.id,
|
|
592
587
|
'object.confirmationNumber': { $exists: false }
|
|
593
588
|
}, { 'object.confirmationNumber': params.confirmationNumber })
|
|
@@ -600,5 +595,168 @@ class MongoRepository {
|
|
|
600
595
|
.exec();
|
|
601
596
|
});
|
|
602
597
|
}
|
|
598
|
+
aggregatePlaceOrder(params) {
|
|
599
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
600
|
+
const statuses = yield Promise.all([
|
|
601
|
+
factory.transactionStatusType.Confirmed,
|
|
602
|
+
factory.transactionStatusType.Canceled,
|
|
603
|
+
factory.transactionStatusType.Expired
|
|
604
|
+
].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
605
|
+
var _a, _b;
|
|
606
|
+
const matchConditions = Object.assign(Object.assign({ startDate: {
|
|
607
|
+
$gte: params.startFrom,
|
|
608
|
+
$lte: params.startThrough
|
|
609
|
+
}, typeOf: { $eq: params.typeOf }, status: { $eq: transactionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
610
|
+
? { 'project.id': { $ne: params.project.id.$ne } }
|
|
611
|
+
: undefined), (typeof params.clientId === 'string')
|
|
612
|
+
// customerIdentifierAll.push();
|
|
613
|
+
? {
|
|
614
|
+
'agent.identifier': {
|
|
615
|
+
$exists: true,
|
|
616
|
+
$all: [{ name: 'clientId', value: params.clientId }]
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
: undefined);
|
|
620
|
+
return this.agggregateByStatus({ matchConditions, status: transactionStatus });
|
|
621
|
+
})));
|
|
622
|
+
return { statuses };
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
// tslint:disable-next-line:max-func-body-length
|
|
626
|
+
agggregateByStatus(params) {
|
|
627
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
628
|
+
const matchConditions = params.matchConditions;
|
|
629
|
+
const transactionStatus = params.status;
|
|
630
|
+
const aggregations = yield this.transactionModel.aggregate([
|
|
631
|
+
{
|
|
632
|
+
$match: matchConditions
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
$project: {
|
|
636
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
637
|
+
status: '$status',
|
|
638
|
+
startDate: '$startDate',
|
|
639
|
+
endDate: '$endDate',
|
|
640
|
+
typeOf: '$typeOf'
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
$group: {
|
|
645
|
+
_id: '$typeOf',
|
|
646
|
+
transactionCount: { $sum: 1 },
|
|
647
|
+
maxDuration: { $max: '$duration' },
|
|
648
|
+
minDuration: { $min: '$duration' },
|
|
649
|
+
avgDuration: { $avg: '$duration' }
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
$project: {
|
|
654
|
+
_id: 0,
|
|
655
|
+
transactionCount: '$transactionCount',
|
|
656
|
+
avgDuration: '$avgDuration',
|
|
657
|
+
maxDuration: '$maxDuration',
|
|
658
|
+
minDuration: '$minDuration'
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
])
|
|
662
|
+
.exec();
|
|
663
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
664
|
+
const percents = [50, 95, 99];
|
|
665
|
+
if (aggregations.length === 0) {
|
|
666
|
+
return {
|
|
667
|
+
status: transactionStatus,
|
|
668
|
+
aggregation: {
|
|
669
|
+
transactionCount: 0,
|
|
670
|
+
avgDuration: 0,
|
|
671
|
+
maxDuration: 0,
|
|
672
|
+
minDuration: 0,
|
|
673
|
+
percentilesDuration: percents.map((percent) => {
|
|
674
|
+
return {
|
|
675
|
+
name: String(percent),
|
|
676
|
+
value: 0
|
|
677
|
+
};
|
|
678
|
+
}),
|
|
679
|
+
acceptedOfferCount: 0,
|
|
680
|
+
avgAcceptedOfferCount: 0,
|
|
681
|
+
totalPrice: 0,
|
|
682
|
+
maxPrice: 0,
|
|
683
|
+
minPrice: 0,
|
|
684
|
+
avgPrice: 0
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
689
|
+
return {
|
|
690
|
+
percentile,
|
|
691
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
692
|
+
rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
|
|
693
|
+
};
|
|
694
|
+
});
|
|
695
|
+
const aggregations2 = yield this.transactionModel.aggregate([
|
|
696
|
+
{
|
|
697
|
+
$match: matchConditions
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
$project: {
|
|
701
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
702
|
+
status: '$status',
|
|
703
|
+
startDate: '$startDate',
|
|
704
|
+
endDate: '$endDate',
|
|
705
|
+
typeOf: '$typeOf',
|
|
706
|
+
// result: '$result',
|
|
707
|
+
acceptedOffers: {
|
|
708
|
+
$cond: {
|
|
709
|
+
if: { $isArray: '$result.order.acceptedOffers' },
|
|
710
|
+
then: '$result.order.acceptedOffers',
|
|
711
|
+
else: []
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
price: {
|
|
715
|
+
$cond: {
|
|
716
|
+
if: { $isNumber: '$result.order.price' },
|
|
717
|
+
then: '$result.order.price',
|
|
718
|
+
else: 0
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
{ $sort: { duration: 1 } },
|
|
724
|
+
{
|
|
725
|
+
$group: {
|
|
726
|
+
_id: '$typeOf',
|
|
727
|
+
durations: { $push: '$duration' },
|
|
728
|
+
acceptedOfferCount: { $sum: { $size: '$acceptedOffers' } },
|
|
729
|
+
avgAcceptedOfferCount: { $avg: { $size: '$acceptedOffers' } },
|
|
730
|
+
totalPrice: { $sum: '$price' },
|
|
731
|
+
maxPrice: { $max: '$price' },
|
|
732
|
+
minPrice: { $min: '$price' },
|
|
733
|
+
avgPrice: { $avg: '$price' }
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
$project: {
|
|
738
|
+
_id: 0,
|
|
739
|
+
percentilesDuration: ranks4percentile.map((rank) => {
|
|
740
|
+
return {
|
|
741
|
+
name: String(rank.percentile),
|
|
742
|
+
value: { $arrayElemAt: ['$durations', rank.rank] }
|
|
743
|
+
};
|
|
744
|
+
}),
|
|
745
|
+
acceptedOfferCount: '$acceptedOfferCount',
|
|
746
|
+
avgAcceptedOfferCount: '$avgAcceptedOfferCount',
|
|
747
|
+
totalPrice: '$totalPrice',
|
|
748
|
+
maxPrice: '$maxPrice',
|
|
749
|
+
minPrice: '$minPrice',
|
|
750
|
+
avgPrice: '$avgPrice'
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
])
|
|
754
|
+
.exec();
|
|
755
|
+
return {
|
|
756
|
+
status: transactionStatus,
|
|
757
|
+
aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
|
|
758
|
+
};
|
|
759
|
+
});
|
|
760
|
+
}
|
|
603
761
|
}
|
|
604
762
|
exports.MongoRepository = MongoRepository;
|