From c15424f7fb1bb5b34c036c6fca07491d7df7be41 Mon Sep 17 00:00:00 2001 From: Chef Huan Date: Tue, 28 May 2024 00:52:15 +0700 Subject: [PATCH] chore(profile): Get subgraph by function --- api/users/search.ts | 4 ++-- utils/index.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/users/search.ts b/api/users/search.ts index 28744197..d2893f67 100644 --- a/api/users/search.ts +++ b/api/users/search.ts @@ -1,7 +1,7 @@ import { VercelRequest, VercelResponse } from "@vercel/node"; import { gql, request } from "graphql-request"; import { Parser } from "json2csv"; -import { PROFILE_SUBGRAPH } from "../../utils"; +import { getProfileSubgraph } from "../../utils"; type User = { id: string; @@ -35,7 +35,7 @@ const getUsersFirstPage = async ( const isActiveBool = isActive && isActive.toLowerCase() === "true"; const { users } = await request( - PROFILE_SUBGRAPH, + getProfileSubgraph(), gql` query getUsersQuery($pageSize: Int, $team: String, $totalPointGT: String, $totalPointLT: String, $totalPointGTE: String, $totalPointLTE: String, $nftAddress: String, $lastUserId: String, $isActiveBool: Boolean) { diff --git a/utils/index.ts b/utils/index.ts index bfca01a3..af20f8d5 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,8 +1,13 @@ import blacklist from "./blacklist.json"; import { getModel } from "./mongo"; -export const PROFILE_SUBGRAPH = - process.env.PROFILE_SUBGRAPH_URL || "https://api.thegraph.com/subgraphs/name/pancakeswap/profile"; +export const getProfileSubgraph = (): string => { + const profileSubgraphUrl = process.env.PROFILE_SUBGRAPH_URL; + if (profileSubgraphUrl) { + return profileSubgraphUrl; + } + throw Error(`Profile subgraph URL is not set ${profileSubgraphUrl}`); +}; /** * Check for the validity of a username based on rules (see documentation).