7
7
HighTransactionTypePercentage ,
8
8
TransactionLimitHistoricAverageOptions ,
9
9
TPeerGroupTransactionAverageOptions ,
10
+ TDormantAccountOptions ,
10
11
} from './types' ;
11
12
import { AggregateType , TIME_UNITS } from './consts' ;
12
13
import { Prisma , TransactionDirection } from '@prisma/client' ;
@@ -49,6 +50,7 @@ export class DataAnalyticsService {
49
50
50
51
case 'evaluateDormantAccount' :
51
52
return await this [ inlineRule . fnName ] ( {
53
+ ...inlineRule . options ,
52
54
projectId,
53
55
} ) ;
54
56
}
@@ -220,53 +222,6 @@ export class DataAnalyticsService {
220
222
` ) ;
221
223
}
222
224
223
- // async evaluateTransactionLimitHistoricAverageInbound({
224
- // projectId,
225
- // transactionDirection,
226
- // paymentMethod,
227
- // minimumCount,
228
- // minimumTransactionAmount,
229
- // transactionFactor,
230
- // }: TransactionLimitHistoricAverageOptions) {
231
- // if (!['=', '!='].includes(paymentMethod.operator)) {
232
- // throw new Error('Invalid operator');
233
- // }
234
-
235
- // return await this._executeQuery<Array<{ counterpartyId: string }>>(Prisma.sql`
236
- // WITH transactionsData AS (
237
- // SELECT
238
- // "counterpartyBeneficiaryId" ,
239
- // count(*) AS count,
240
- // avg("transactionBaseAmount") AS avg
241
- // FROM
242
- // "TransactionRecord" tr
243
- // WHERE
244
- // "transactionDirection"::text = ${transactionDirection}
245
- // AND "paymentMethod"::text ${Prisma.raw(paymentMethod.operator)} ${paymentMethod.value}
246
- // AND "projectId" = ${projectId}
247
- // GROUP BY
248
- // "counterpartyBeneficiaryId"
249
- // HAVING COUNT(*) > ${minimumCount}
250
- // )
251
- // SELECT
252
- // tr."counterpartyBeneficiaryId" as "counterpartyId"
253
- // FROM
254
- // "TransactionRecord" tr
255
- // JOIN transactionsData td ON
256
- // tr."counterpartyBeneficiaryId" = td."counterpartyBeneficiaryId"
257
- // WHERE
258
- // tr."transactionDirection"::text = ${transactionDirection}
259
- // AND "projectId" = ${projectId}
260
- // AND "paymentMethod"::text ${Prisma.raw(paymentMethod.operator)} ${paymentMethod.value}
261
- // AND "transactionBaseAmount" > ${minimumTransactionAmount}
262
- // AND "transactionBaseAmount" > (
263
- // ${transactionFactor} * avg
264
- // )
265
- // GROUP BY
266
- // tr."counterpartyBeneficiaryId"
267
- // `);
268
- // }
269
-
270
225
async evaluatePaymentUnexpected ( {
271
226
projectId,
272
227
factor = 2 ,
@@ -291,30 +246,19 @@ export class DataAnalyticsService {
291
246
return results ;
292
247
}
293
248
294
- async evaluateDormantAccount ( { projectId } : { projectId : string } ) {
295
- // const query: Prisma.Sql = Prisma.sql`
296
- // SELECT
297
- // tr."counterpartyBeneficiaryId" as "counterpartyId",
298
- // COUNT(
299
- // CASE WHEN tr."transactionDate" >= CURRENT_DATE - INTERVAL '180 days' THEN
300
- // tr."id"
301
- // END) AS "totalTransactionWithinSixMonths",
302
- // COUNT(tr."id") AS "totalTransactionAllTime"
303
- // FROM
304
- // "TransactionRecord" AS "tr"
305
- // WHERE
306
- // tr."projectId" = '${projectId}'
307
- // AND tr."counterpartyBeneficiaryId" IS NOT NULL
308
- // GROUP BY
309
- // tr."counterpartyBeneficiaryId";
310
- // `;
249
+ async evaluateDormantAccount ( { projectId, timeAmount, timeUnit } : TDormantAccountOptions ) {
250
+ if ( ! projectId ) {
251
+ throw new Error ( 'projectId is required' ) ;
252
+ }
311
253
312
254
const query : Prisma . Sql = Prisma . sql `
313
255
WITH transactions AS (
314
256
SELECT
315
257
tr."counterpartyBeneficiaryId" AS "counterpartyId",
316
258
count(
317
- CASE WHEN tr."transactionDate" >= CURRENT_DATE - INTERVAL '180 days' THEN
259
+ CASE WHEN tr."transactionDate" >= CURRENT_DATE - INTERVAL '${ Prisma . raw (
260
+ `${ timeAmount } ${ timeUnit } ` ,
261
+ ) } ' THEN
318
262
tr."id"
319
263
END) AS "totalTransactionWithinSixMonths",
320
264
count(tr."id") AS "totalTransactionAllTime"
0 commit comments