Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 committed Nov 8, 2023
1 parent 5428416 commit 041f180
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
20 changes: 20 additions & 0 deletions api/src/db/providerDataProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Provider, ProviderAttribute } from "@shared/dbSchemas/akash";
import { getProviderAttributesSchema } from "@src/providers/githubProvider";

export async function getProviderRegions() {
const providerAttributesSchema = await getProviderAttributesSchema();
const regions = providerAttributesSchema["location-region"].values;

const providerRegions = await Provider.findAll({
attributes: ["owner"],
include: [{ model: ProviderAttribute, attributes: [["value", "location_region"]], where: { key: "location-region" } }],
raw: true
});

const result = regions.map((region) => {
const providers = providerRegions.filter((x) => x["providerAttributes.location_region"] === region.key).map((x) => x.owner);
return { ...region, providers };
});

return result;
}
26 changes: 1 addition & 25 deletions api/src/providers/githubProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Octokit } from "@octokit/rest";
import { cacheKeys, cacheResponse } from "@src/caching/helpers";
import { chainDb } from "@src/db/dbConnection";
import { ProviderAttributesSchema } from "@src/types/provider";
import { env } from "@src/utils/env";
import axios from "axios";
import { QueryTypes } from "sequelize";

export function getOctokit() {
const githubPAT = env.AkashlyticsGithubPAT;
Expand Down Expand Up @@ -38,26 +36,4 @@ export async function getAuditors() {
});

return response;
}

export async function getProviderRegions() {
const providerAttributesSchema = await getProviderAttributesSchema();
const regions = providerAttributesSchema["location-region"].values;

let result: { owner: string; location_region: string }[] = await chainDb.query(
`SELECT p.owner, pa.value AS location_region
FROM public."provider" p
JOIN public."providerAttribute" pa ON p.owner = pa.provider
WHERE pa.key = 'location-region';`,
{
type: QueryTypes.SELECT
}
);

const res = regions.map((region) => {
const providers = result.filter((provider) => provider.location_region === region.key).map((provider) => provider.owner);
return { ...region, providers };
});

return res;
}
}
11 changes: 2 additions & 9 deletions api/src/routers/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { ProviderStatsKey } from "@src/types/graph";
import { cacheKeys, cacheResponse } from "@src/caching/helpers";
import axios from "axios";
import { getMarketData } from "@src/providers/marketDataProvider";
import { getAuditors, getProviderAttributesSchema, getProviderRegions } from "@src/providers/githubProvider";
import { getAuditors, getProviderAttributesSchema } from "@src/providers/githubProvider";
import { getProviderRegions } from "@src/db/providerDataProvider";

export const apiRouter = express.Router();

Expand Down Expand Up @@ -389,14 +390,6 @@ apiRouter.get(
})
);

apiRouter.get(
"/regions",
asyncHandler(async (req, res) => {
const regions = await getProviderRegions();
res.send(regions);
})
);

apiRouter.get(
"/getAuditors",
asyncHandler(async (req, res) => {
Expand Down

0 comments on commit 041f180

Please sign in to comment.