feat: Add usage data to getBillingAndUsage graphQL query

This commit is contained in:
Faruk AYDIN
2023-03-25 02:16:17 +03:00
parent b5524b18cf
commit f07d9dd813
4 changed files with 29 additions and 0 deletions

View File

@@ -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,
},
};
};

View File

@@ -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

View File

@@ -16,6 +16,7 @@ class ExecutionStep extends Base {
status: 'success' | 'failure';
step: Step;
execution?: Execution;
count?: number;
static tableName = 'execution_steps';

View File

@@ -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';