feat: Add usage data to getBillingAndUsage graphQL query
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
import Billing from '../../helpers/billing/index.ee';
|
import Billing from '../../helpers/billing/index.ee';
|
||||||
|
import Execution from '../../models/execution';
|
||||||
|
import ExecutionStep from '../../models/execution-step';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
type Subscription = {
|
type Subscription = {
|
||||||
monthlyQuota: string;
|
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 {
|
return {
|
||||||
subscription,
|
subscription,
|
||||||
|
usage: {
|
||||||
|
task: executionStepCount.count,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -475,6 +475,7 @@ type GetAutomatischInfo {
|
|||||||
|
|
||||||
type GetBillingAndUsage {
|
type GetBillingAndUsage {
|
||||||
subscription: Subscription
|
subscription: Subscription
|
||||||
|
usage: Usage
|
||||||
}
|
}
|
||||||
|
|
||||||
type Subscription {
|
type Subscription {
|
||||||
@@ -486,6 +487,10 @@ type Subscription {
|
|||||||
nextBillDate: String
|
nextBillDate: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Usage {
|
||||||
|
task: Int
|
||||||
|
}
|
||||||
|
|
||||||
type GetUsageData {
|
type GetUsageData {
|
||||||
name: String
|
name: String
|
||||||
allowedTaskCount: Int
|
allowedTaskCount: Int
|
||||||
|
@@ -16,6 +16,7 @@ class ExecutionStep extends Base {
|
|||||||
status: 'success' | 'failure';
|
status: 'success' | 'failure';
|
||||||
step: Step;
|
step: Step;
|
||||||
execution?: Execution;
|
execution?: Execution;
|
||||||
|
count?: number;
|
||||||
|
|
||||||
static tableName = 'execution_steps';
|
static tableName = 'execution_steps';
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import Connection from './connection';
|
|||||||
import Flow from './flow';
|
import Flow from './flow';
|
||||||
import Step from './step';
|
import Step from './step';
|
||||||
import Execution from './execution';
|
import Execution from './execution';
|
||||||
|
import ExecutionStep from './execution-step';
|
||||||
import bcrypt from 'bcrypt';
|
import bcrypt from 'bcrypt';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import PaymentPlan from './payment-plan.ee';
|
import PaymentPlan from './payment-plan.ee';
|
||||||
|
Reference in New Issue
Block a user