Skip to content

Commit

Permalink
add apps/data-backend cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsaymoralesb committed Oct 2, 2024
1 parent c43d477 commit a872e8f
Show file tree
Hide file tree
Showing 18 changed files with 476 additions and 453 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/data-backend-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Data Backend App

on:
push:
branches:
- main
paths:
- "apps/data-backend/**"
pull_request:
branches:
- main
paths:
- "apps/data-backend/**"

jobs:
check-app:
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./apps/data-backend

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install Dependencies
run: |
if [ -f "apps/data-backend/pnpm-lock.yaml" ]; then
pnpm install --frozen-lockfile
else
pnpm install
fi
- name: Prettier Format Check
run: pnpm prettier:check

- name: TypeScript Check
run: pnpm ts:check

- name: Build
run: pnpm build
5 changes: 4 additions & 1 deletion apps/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"test": "echo \"Error: no test specified\" && exit 1",
"prisma:generate": "npx prisma generate",
"prisma:push": "npx prisma db push",
"prisma:setup": "npx prisma generate && npx prisma db push"
"prisma:setup": "npx prisma generate && npx prisma db push",
"prettier": "prettier --write \"src/**/*.{ts,tsx}\"",
"prettier:check": "prettier --check \"src/**/*.{ts,tsx}\"",
"ts:check": "tsc --noEmit"
},
"keywords": [],
"author": "",
Expand Down
20 changes: 11 additions & 9 deletions apps/data-backend/src/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApolloServer, gql } from 'apollo-server';
import { ApolloServer, gql } from "apollo-server";
const { prisma } = require("indexer-prisma");

//GraphQL schema definitions
Expand Down Expand Up @@ -48,19 +48,21 @@ const typeDefs = gql`
const resolvers = {
Query: {
buyTokens: () => prisma.buy_token.findMany(),
buyToken: (_parent, { transactionHash }) => prisma.buy_token.findUnique({
where: { transactionHash },
}),
buyToken: (_parent, { transactionHash }) =>
prisma.buy_token.findUnique({
where: { transactionHash },
}),
tokenDeploys: () => prisma.token_deploy.findMany(),
tokenDeploy: (_parent, { memecoinAddress }) => prisma.token_deploy.findUnique({
where: { memecoin_address: memecoinAddress },
}),
tokenDeploy: (_parent, { memecoinAddress }) =>
prisma.token_deploy.findUnique({
where: { memecoin_address: memecoinAddress },
}),
},
};

// Create the Apollo Server
export const server = new ApolloServer({
export const server = new ApolloServer({
typeDefs,
resolvers,
context: () => ({ prisma }),
});
});
4 changes: 2 additions & 2 deletions apps/data-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { launchBot, sendWebAppButton } from "./services/telegram-app";
* @type {import('fastify').FastifyInstance} Instance of Fastify
*/
const fastify = Fastify({
logger: true
logger: true,
});
fastify.register(fastifyCors, {
origin: "*",
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true
credentials: true,
});
declareRoutes(fastify);

Expand Down
6 changes: 3 additions & 3 deletions apps/data-backend/src/routes/indexer/buy-coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ async function buyCoinRoute(fastify: FastifyInstance, options: RouteOptions) {
memecoin_address: true,
price: true,
total_supply: true,
network: true
}
network: true,
},
});

reply.status(HTTPStatus.OK).send({
data: buyTokens
data: buyTokens,
});
} catch (error) {
console.error("Error fetching buy tokens:", error);
Expand Down
26 changes: 13 additions & 13 deletions apps/data-backend/src/routes/indexer/deploy-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async function deployLaunchRoute(
memecoin_address: true,
price: true,
total_supply: true,
network: true
}
network: true,
},
});

reply.status(HTTPStatus.OK).send({
data: launches
data: launches,
});
} catch (error) {
console.error("Error deploying launch:", error);
Expand All @@ -41,24 +41,24 @@ async function deployLaunchRoute(
if (!isValidStarknetAddress(launch)) {
reply.status(HTTPStatus.BadRequest).send({
code: HTTPStatus.BadRequest,
message: "Invalid token address"
message: "Invalid token address",
});
return;
}

const launches = await prisma.token_launch.findMany({
where:{
memecoin_address:launch
where: {
memecoin_address: launch,
},
select: {
memecoin_address: true,
price: true,
total_supply: true,
network: true
}
network: true,
},
});
reply.status(HTTPStatus.OK).send({
data: launches
data: launches,
});
} catch (error) {
console.error("Error deploying launch:", error);
Expand All @@ -76,7 +76,7 @@ async function deployLaunchRoute(
if (!isValidStarknetAddress(launch)) {
reply.status(HTTPStatus.BadRequest).send({
code: HTTPStatus.BadRequest,
message: "Invalid token address"
message: "Invalid token address",
});
return;
}
Expand All @@ -86,14 +86,14 @@ async function deployLaunchRoute(
memecoin_address: true,
price: true,
total_supply: true,
network: true
}
network: true,
},
});

let statsLaunch = launches[0];

reply.status(HTTPStatus.OK).send({
data: statsLaunch
data: statsLaunch,
});
} catch (error) {
console.error("Error deploying launch:", error);
Expand Down
18 changes: 9 additions & 9 deletions apps/data-backend/src/routes/indexer/deploy-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async function deployTokenRoute(
memecoin_address: true,
name: true,
total_supply: true,
network: true
}
network: true,
},
});

reply.status(HTTPStatus.OK).send({
data: deploys
data: deploys,
});
} catch (error) {
console.error("Error deploying launch:", error);
Expand All @@ -41,7 +41,7 @@ async function deployTokenRoute(
if (!isValidStarknetAddress(token)) {
reply.status(HTTPStatus.BadRequest).send({
code: HTTPStatus.BadRequest,
message: "Invalid token address"
message: "Invalid token address",
});
return;
}
Expand All @@ -51,14 +51,14 @@ async function deployTokenRoute(
select: {
memecoin_address: true,
name: true,
symbol:true,
initial_supply:true,
symbol: true,
initial_supply: true,
total_supply: true,
network: true
}
network: true,
},
});
reply.status(HTTPStatus.OK).send({
data: deploys
data: deploys,
});
} catch (error) {
console.error("Error deploying launch:", error);
Expand Down
8 changes: 4 additions & 4 deletions apps/data-backend/src/routes/indexer/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function graphRoute(fastify: FastifyInstance, options: RouteOptions) {
if (!isValidStarknetAddress(tokenAddress)) {
reply.status(HTTPStatus.BadRequest).send({
code: HTTPStatus.BadRequest,
message: "Invalid token address"
message: "Invalid token address",
});
return;
}
Expand All @@ -27,13 +27,13 @@ async function graphRoute(fastify: FastifyInstance, options: RouteOptions) {
select: {
price: true,
block_timestamp: true,
transaction_type: true
}
transaction_type: true,
},
});

if (transactions.length === 0) {
return reply.status(HTTPStatus.NotFound).send({
error: "No transactions found for this token address."
error: "No transactions found for this token address.",
});
}
// Hourly candles
Expand Down
16 changes: 8 additions & 8 deletions apps/data-backend/src/routes/indexer/holdings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function holdingsRoute(fastify: FastifyInstance, options: RouteOptions) {
if (!isValidStarknetAddress(tokenAddress)) {
reply.status(HTTPStatus.BadRequest).send({
code: HTTPStatus.BadRequest,
message: "Invalid token address"
message: "Invalid token address",
});
return;
}
Expand All @@ -25,11 +25,11 @@ async function holdingsRoute(fastify: FastifyInstance, options: RouteOptions) {
by: ["owner_address"],
where: { memecoin_address: tokenAddress },
_sum: {
amount: true
amount: true,
},
_count: {
owner_address: true
}
owner_address: true,
},
});

const formattedDistributions = distributions.map((entry) => {
Expand All @@ -38,22 +38,22 @@ async function holdingsRoute(fastify: FastifyInstance, options: RouteOptions) {
return {
...entry,
_sum: {
amount: amountBigInt
}
amount: amountBigInt,
},
};
});

if (distributions.length === 0) {
reply.status(HTTPStatus.NotFound).send({
message: "No holders found for this token address."
message: "No holders found for this token address.",
});
}

reply.status(HTTPStatus.OK).send({ data: formattedDistributions });
} catch (error) {
console.error("Failed to fetch token distribution:", error);
reply.status(HTTPStatus.InternalServerError).send({
message: "Internal Server Error while fetching token distribution."
message: "Internal Server Error while fetching token distribution.",
});
}
});
Expand Down
8 changes: 4 additions & 4 deletions apps/data-backend/src/routes/indexer/token_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function tokenStatsRoute(
if (!isValidStarknetAddress(tokenAddress)) {
reply.status(HTTPStatus.BadRequest).send({
code: HTTPStatus.BadRequest,
message: "Invalid token address"
message: "Invalid token address",
});
return;
}
Expand All @@ -31,19 +31,19 @@ async function tokenStatsRoute(
select: {
price: true,
liquidity_raised: true,
}
},
});

if (stats) {
reply.status(HTTPStatus.OK).send(stats);
} else {
reply.status(HTTPStatus.NotFound).send({
error: "No data found for the specified token address."
error: "No data found for the specified token address.",
});
}
} catch (error) {
reply.status(HTTPStatus.InternalServerError).send({
error: "Internal Server Error while fetching statistics."
error: "Internal Server Error while fetching statistics.",
});
}
});
Expand Down
Loading

0 comments on commit a872e8f

Please sign in to comment.