feat: Add usage data to getBillingAndUsage graphQL query
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import Context from '../../types/express/context';
|
||||
import Billing from '../../helpers/billing/index.ee';
|
||||
import Execution from '../../models/execution';
|
||||
import ExecutionStep from '../../models/execution-step';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
type Subscription = {
|
||||
monthlyQuota: string;
|
||||
@@ -45,8 +48,27 @@ const getBillingAndUsage = async (
|
||||
};
|
||||
}
|
||||
|
||||
const executionIds = (
|
||||
await context.currentUser
|
||||
.$relatedQuery('executions')
|
||||
.select('executions.id')
|
||||
).map((execution: Execution) => execution.id);
|
||||
|
||||
const executionStepCount = await ExecutionStep.query()
|
||||
.whereIn('execution_id', executionIds)
|
||||
.andWhere(
|
||||
'created_at',
|
||||
'>=',
|
||||
DateTime.now().minus({ days: 30 }).toFormat('D')
|
||||
)
|
||||
.count()
|
||||
.first();
|
||||
|
||||
return {
|
||||
subscription,
|
||||
usage: {
|
||||
task: executionStepCount.count,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user