-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8decdf1
commit cadcd02
Showing
4 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { request, gql, GraphQLClient } from "graphql-request"; | ||
|
||
const graphQLClient = new GraphQLClient( | ||
"https://api.studio.thegraph.com/query/51321/cric-bot-graph/1.0.0" | ||
); | ||
const queryAll = gql` | ||
query MyQuery { | ||
betPlaceds { | ||
id | ||
pool | ||
user | ||
eventId | ||
} | ||
} | ||
`; | ||
|
||
const singleUserQuery = () => gql` | ||
query MyQuery($address: String!) { | ||
betPlaceds(where: { user: $address }) { | ||
id | ||
user | ||
eventId | ||
pool | ||
blockNumber | ||
blockTimestamp | ||
transactionHash | ||
} | ||
} | ||
`; | ||
export const getUserData = async (address: string) => { | ||
const variables = { | ||
address: address, | ||
}; | ||
let results; | ||
results = await graphQLClient.request(singleUserQuery(), variables); | ||
console.log(results); | ||
return results.betPlaceds; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require("dotenv").config(); | ||
import { createClient } from "@supabase/supabase-js"; | ||
import { GenericError } from "../errors"; | ||
const supabaseUrl = process.env.SUPABASE_URL || ""; | ||
const supabaseKey = process.env.SUPABASE_KEY || ""; | ||
|
||
const supabase = createClient(supabaseUrl, supabaseKey); | ||
|
||
class apiCalls { | ||
async fetchUserByTgId(userID: string) { | ||
let { data: BettingBotUser, error } = await supabase | ||
.from("BettingBotUser") | ||
.select("*") | ||
.eq("tg_id", userID); | ||
if (error?.message) { | ||
GenericError(`fetch error` + error.message + `${error.details}`); | ||
return "error Occured"; | ||
} | ||
return BettingBotUser; | ||
} | ||
|
||
async createUser(props: any) { | ||
const { data, error } = await supabase | ||
.from("BettingBotUser") | ||
.insert([props]) | ||
.select(); | ||
if (error?.message) { | ||
GenericError(`create error` + error.message + `${error.details}`); | ||
return error; | ||
} | ||
return data; | ||
} | ||
|
||
async updateUser(props: any) { | ||
const { data, error } = await supabase | ||
.from("BettingBotUser") | ||
.update(props) | ||
.eq("tg_id", props.tg_id) | ||
.select(); | ||
if (error?.message) { | ||
GenericError(`update error` + error.message + `${error.details}`); | ||
return error; | ||
} | ||
return data; | ||
} | ||
async createPool(props: any) { | ||
const { data, error } = await supabase | ||
.from("bettingPools") | ||
.insert([props]) | ||
.select(); | ||
if (error?.message) { | ||
GenericError( | ||
`create betting pool error` + | ||
error.message + | ||
`${error.details}` | ||
); | ||
return error; | ||
} | ||
return data; | ||
} | ||
async updatePool(props: any) {} | ||
async getOnePool(props: any) { | ||
let { data: bettingPools, error } = await supabase | ||
.from("bettingPools") | ||
.select("*") | ||
.eq("tg_id", props.eventId); | ||
if (error?.message) { | ||
GenericError(`fetch error` + error.message + `${error.details}`); | ||
return "error Occured"; | ||
} | ||
return bettingPools; | ||
} | ||
async createPoolTransaction(props: any) {} | ||
async updatePoolTransaction(props: any) {} | ||
} | ||
|
||
export default apiCalls; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters