Skip to content

Commit

Permalink
added graph and api models
Browse files Browse the repository at this point in the history
  • Loading branch information
Danijel-Enoch committed Nov 19, 2023
1 parent 8decdf1 commit cadcd02
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
38 changes: 38 additions & 0 deletions models/graph.calls.ts
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;
};
77 changes: 77 additions & 0 deletions models/supabaseApi.calls.ts
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;
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit cadcd02

Please sign in to comment.