feat: Implement getUsageData graphQL query
This commit is contained in:
29
packages/backend/src/graphql/queries/get-usage-data.ee.ts
Normal file
29
packages/backend/src/graphql/queries/get-usage-data.ee.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import appConfig from '../../config/app';
|
||||||
|
import Context from '../../types/express/context';
|
||||||
|
|
||||||
|
const getUsageData = async (
|
||||||
|
_parent: unknown,
|
||||||
|
_params: unknown,
|
||||||
|
context: Context
|
||||||
|
) => {
|
||||||
|
if (!appConfig.isCloud) return;
|
||||||
|
|
||||||
|
const usageData = await context.currentUser
|
||||||
|
.$relatedQuery('usageData')
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
const paymentPlan = await context.currentUser
|
||||||
|
.$relatedQuery('paymentPlan')
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
const computedUsageData = {
|
||||||
|
allowedTaskCount: paymentPlan.taskCount,
|
||||||
|
consumedTaskCount: usageData.consumedTaskCount,
|
||||||
|
remainingTaskCount: paymentPlan.taskCount - usageData.consumedTaskCount,
|
||||||
|
nextResetAt: usageData.nextResetAt,
|
||||||
|
};
|
||||||
|
|
||||||
|
return computedUsageData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getUsageData;
|
@@ -11,6 +11,7 @@ import getExecutionSteps from './queries/get-execution-steps';
|
|||||||
import getDynamicData from './queries/get-dynamic-data';
|
import getDynamicData from './queries/get-dynamic-data';
|
||||||
import getDynamicFields from './queries/get-dynamic-fields';
|
import getDynamicFields from './queries/get-dynamic-fields';
|
||||||
import getCurrentUser from './queries/get-current-user';
|
import getCurrentUser from './queries/get-current-user';
|
||||||
|
import getUsageData from './queries/get-usage-data.ee';
|
||||||
import getAutomatischInfo from './queries/get-automatisch-info';
|
import getAutomatischInfo from './queries/get-automatisch-info';
|
||||||
import healthcheck from './queries/healthcheck';
|
import healthcheck from './queries/healthcheck';
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ const queryResolvers = {
|
|||||||
getDynamicData,
|
getDynamicData,
|
||||||
getDynamicFields,
|
getDynamicFields,
|
||||||
getCurrentUser,
|
getCurrentUser,
|
||||||
|
getUsageData,
|
||||||
getAutomatischInfo,
|
getAutomatischInfo,
|
||||||
healthcheck,
|
healthcheck,
|
||||||
};
|
};
|
||||||
|
@@ -34,6 +34,7 @@ type Query {
|
|||||||
parameters: JSONObject
|
parameters: JSONObject
|
||||||
): [SubstepArgument]
|
): [SubstepArgument]
|
||||||
getCurrentUser: User
|
getCurrentUser: User
|
||||||
|
getUsageData: GetUsageData
|
||||||
getAutomatischInfo: GetAutomatischInfo
|
getAutomatischInfo: GetAutomatischInfo
|
||||||
healthcheck: AppHealth
|
healthcheck: AppHealth
|
||||||
}
|
}
|
||||||
@@ -467,6 +468,13 @@ type GetAutomatischInfo {
|
|||||||
isCloud: String
|
isCloud: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetUsageData {
|
||||||
|
allowedTaskCount: Int
|
||||||
|
consumedTaskCount: Int
|
||||||
|
remainingTaskCount: Int
|
||||||
|
nextResetAt: String
|
||||||
|
}
|
||||||
|
|
||||||
schema {
|
schema {
|
||||||
query: Query
|
query: Query
|
||||||
mutation: Mutation
|
mutation: Mutation
|
||||||
|
@@ -26,7 +26,7 @@ class UsageData extends Base {
|
|||||||
relation: Base.BelongsToOneRelation,
|
relation: Base.BelongsToOneRelation,
|
||||||
modelClass: User,
|
modelClass: User,
|
||||||
join: {
|
join: {
|
||||||
from: 'payment_plans.user_id',
|
from: 'usage_data.user_id',
|
||||||
to: 'users.id',
|
to: 'users.id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -7,6 +7,7 @@ import Execution from './execution';
|
|||||||
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';
|
||||||
|
import UsageData from './usage-data.ee';
|
||||||
|
|
||||||
class User extends Base {
|
class User extends Base {
|
||||||
id!: string;
|
id!: string;
|
||||||
@@ -21,6 +22,7 @@ class User extends Base {
|
|||||||
steps?: Step[];
|
steps?: Step[];
|
||||||
executions?: Execution[];
|
executions?: Execution[];
|
||||||
paymentPlan?: PaymentPlan;
|
paymentPlan?: PaymentPlan;
|
||||||
|
usageData?: UsageData;
|
||||||
|
|
||||||
static tableName = 'users';
|
static tableName = 'users';
|
||||||
|
|
||||||
@@ -86,6 +88,14 @@ class User extends Base {
|
|||||||
to: 'users.id',
|
to: 'users.id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
usageData: {
|
||||||
|
relation: Base.HasOneRelation,
|
||||||
|
modelClass: UsageData,
|
||||||
|
join: {
|
||||||
|
from: 'usage_data.user_id',
|
||||||
|
to: 'users.id',
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
login(password: string) {
|
login(password: string) {
|
||||||
|
Reference in New Issue
Block a user