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,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -475,6 +475,7 @@ type GetAutomatischInfo {
|
||||
|
||||
type GetBillingAndUsage {
|
||||
subscription: Subscription
|
||||
usage: Usage
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
@@ -486,6 +487,10 @@ type Subscription {
|
||||
nextBillDate: String
|
||||
}
|
||||
|
||||
type Usage {
|
||||
task: Int
|
||||
}
|
||||
|
||||
type GetUsageData {
|
||||
name: String
|
||||
allowedTaskCount: Int
|
||||
|
@@ -16,6 +16,7 @@ class ExecutionStep extends Base {
|
||||
status: 'success' | 'failure';
|
||||
step: Step;
|
||||
execution?: Execution;
|
||||
count?: number;
|
||||
|
||||
static tableName = 'execution_steps';
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import Connection from './connection';
|
||||
import Flow from './flow';
|
||||
import Step from './step';
|
||||
import Execution from './execution';
|
||||
import ExecutionStep from './execution-step';
|
||||
import bcrypt from 'bcrypt';
|
||||
import crypto from 'crypto';
|
||||
import PaymentPlan from './payment-plan.ee';
|
||||
|
Reference in New Issue
Block a user