diff --git a/api/src/db/dbConnection.ts b/api/src/db/dbConnection.ts index 0cd8abed3..f3f9796cd 100644 --- a/api/src/db/dbConnection.ts +++ b/api/src/db/dbConnection.ts @@ -6,13 +6,17 @@ import { chainModels, getChainModels, userModels } from "@shared/dbSchemas"; import { Template, TemplateFavorite, UserAddressName, UserSetting } from "@shared/dbSchemas/user"; import { chainDefinitions } from "@shared/chainDefinitions"; -const csMap: { [key: string]: string } = { +function isValidNetwork(network: string): network is keyof typeof csMap { + return network in csMap; +} + +const csMap = { mainnet: env.AkashDatabaseCS, testnet: env.AkashTestnetDatabaseCS, sandbox: env.AkashSandboxDatabaseCS }; -if (!(env.Network in csMap)) { +if (!isValidNetwork(env.Network)) { throw new Error(`Invalid network: ${env.Network}`); } diff --git a/api/src/routes/v1/graphData.ts b/api/src/routes/v1/graphData.ts index fbeb90f43..51e63da42 100644 --- a/api/src/routes/v1/graphData.ts +++ b/api/src/routes/v1/graphData.ts @@ -7,7 +7,7 @@ const route = createRoute({ tags: ["Analytics"], request: { params: z.object({ - dataName: z.string().openapi({ example: "dailyUAktSpent", enum: Array.from(AuthorizedGraphDataNames) }) + dataName: z.string().openapi({ example: "dailyUAktSpent", enum: AuthorizedGraphDataNames }) }) }, responses: { diff --git a/api/src/services/db/statsService.ts b/api/src/services/db/statsService.ts index 6ef437ec4..71d09c5f1 100644 --- a/api/src/services/db/statsService.ts +++ b/api/src/services/db/statsService.ts @@ -75,7 +75,22 @@ export const getDashboardData = async () => { }; }; -export const AuthorizedGraphDataNames = [ +type AuthorizedGraphDataName = + | "dailyUAktSpent" + | "dailyUUsdcSpent" + | "dailyUUsdSpent" + | "dailyLeaseCount" + | "totalUAktSpent" + | "totalUUsdcSpent" + | "totalUUsdSpent" + | "activeLeaseCount" + | "totalLeaseCount" + | "activeCPU" + | "activeGPU" + | "activeMemory" + | "activeStorage"; + +export const AuthorizedGraphDataNames: AuthorizedGraphDataName[] = [ "dailyUAktSpent", "dailyUUsdcSpent", "dailyUUsdSpent", @@ -89,9 +104,7 @@ export const AuthorizedGraphDataNames = [ "activeGPU", "activeMemory", "activeStorage" -] as const; - -type AuthorizedGraphDataName = (typeof AuthorizedGraphDataNames)[number]; +]; export function isValidGraphDataName(x: string): x is AuthorizedGraphDataName { return AuthorizedGraphDataNames.includes(x as AuthorizedGraphDataName); diff --git a/indexer/src/indexers/akashStatsIndexer.ts b/indexer/src/indexers/akashStatsIndexer.ts index 1725fd895..06000be86 100644 --- a/indexer/src/indexers/akashStatsIndexer.ts +++ b/indexer/src/indexers/akashStatsIndexer.ts @@ -23,8 +23,7 @@ import { ProviderSnapshotNodeGPU } from "@shared/dbSchemas/akash"; import { AkashBlock as Block, AkashMessage as Message } from "@shared/dbSchemas/akash"; -import { Op, Transaction as DbTransaction, QueryTypes } from "sequelize"; -import { sequelize } from "@src/db/dbConnection"; +import { Op, Transaction as DbTransaction } from "sequelize"; class ITotalResources { count: number;