Skip to content

Commit

Permalink
PR Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Mar 19, 2024
1 parent 580d1ed commit fb9f5de
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
8 changes: 6 additions & 2 deletions api/src/db/dbConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/v1/graphData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
21 changes: 17 additions & 4 deletions api/src/services/db/statsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions indexer/src/indexers/akashStatsIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fb9f5de

Please sign in to comment.