diff --git a/models/graph.calls.ts b/models/graph.calls.ts new file mode 100644 index 0000000..f9563aa --- /dev/null +++ b/models/graph.calls.ts @@ -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; +}; diff --git a/models/supabaseApi.calls.ts b/models/supabaseApi.calls.ts new file mode 100644 index 0000000..9aeaeae --- /dev/null +++ b/models/supabaseApi.calls.ts @@ -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; diff --git a/package-lock.json b/package-lock.json index 5931233..8d9f5c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "axios": "^1.4.0", "ethers": "^6.7.0", "grammy": "^1.17.2", + "graphql-request": "^6.1.0", "ts-node-dev": "^2.0.0", "typechain": "^8.3.2" }, @@ -624,6 +625,14 @@ "resolved": "https://registry.npmjs.org/@grammyjs/types/-/types-3.1.2.tgz", "integrity": "sha512-AsSkTUfZCfSEIacUBOQ94qLbZZy3UofkschWv4uBJKEHjuEfGnjeZZgiwhDfTDjmpmW+MbcasvS+FEfD2jiSLw==" }, + "node_modules/@graphql-typed-document-node/core": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz", + "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==", + "peerDependencies": { + "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" + } + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", @@ -2676,6 +2685,35 @@ "node": "^12.20.0 || >=14.13.1" } }, + "node_modules/graphql": { + "version": "16.8.1", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", + "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", + "peer": true, + "engines": { + "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" + } + }, + "node_modules/graphql-request": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-6.1.0.tgz", + "integrity": "sha512-p+XPfS4q7aIpKVcgmnZKhMNqhltk20hfXtkaIkTfjjmiKMJ5xrt5c743cL03y/K7y1rg3WrIC49xGiEQ4mxdNw==", + "dependencies": { + "@graphql-typed-document-node/core": "^3.2.0", + "cross-fetch": "^3.1.5" + }, + "peerDependencies": { + "graphql": "14 - 16" + } + }, + "node_modules/graphql-request/node_modules/cross-fetch": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", + "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", + "dependencies": { + "node-fetch": "^2.6.12" + } + }, "node_modules/har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", diff --git a/package.json b/package.json index aeee9ac..6ffa2b9 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "axios": "^1.4.0", "ethers": "^6.7.0", "grammy": "^1.17.2", + "graphql-request": "^6.1.0", "ts-node-dev": "^2.0.0", "typechain": "^8.3.2" },