mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Fix all linting errors
This commit is contained in:
14
packages/backend/.eslintrc.json
Normal file
14
packages/backend/.eslintrc.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json",
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["./src/handlers/actions/types.ts"],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export default {
|
||||
export const CONFIG = {
|
||||
port: process.env.PORT || 4000,
|
||||
graphqlURL: process.env.GRAPHQL_URL || 'http://localhost:8080/v1/graphql',
|
||||
adminKey: process.env.HASURA_GRAPHQL_ADMIN_SECRET || 'metagame_secret',
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import express from 'express';
|
||||
|
||||
import { asyncHandlerWrapper } from '../../lib/apiHelpers';
|
||||
import { updateBoxProfileHandler } from './updateBoxProfile/handler';
|
||||
|
||||
import updateBoxProfileHandler from './updateBoxProfile/handler';
|
||||
export const actionRoutes = express.Router();
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/updateBoxProfile', asyncHandlerWrapper(updateBoxProfileHandler));
|
||||
|
||||
export default router;
|
||||
actionRoutes.post(
|
||||
'/updateBoxProfile',
|
||||
asyncHandlerWrapper(updateBoxProfileHandler),
|
||||
);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import Box from '3box';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
import { hasuraQuery } from '../../../lib/hasuraHelpers';
|
||||
import { getPlayerETHAddress } from '../../../lib/playerHelpers';
|
||||
import Box from '3box';
|
||||
|
||||
const getPlayerQuery = `
|
||||
query GetPlayer ($playerId: uuid!) {
|
||||
@@ -33,10 +34,10 @@ mutation upsert_Account($objects: [Account_insert_input!]!) {
|
||||
}
|
||||
`;
|
||||
|
||||
const handler = async (req: Request, res: Response) => {
|
||||
const { session_variables } = req.body;
|
||||
const role = session_variables['x-hasura-role'];
|
||||
const playerId = session_variables['x-hasura-user-id'];
|
||||
export const updateBoxProfileHandler = async (req: Request, res: Response) => {
|
||||
const session = req.body.session_variables;
|
||||
const role = session['x-hasura-role'];
|
||||
const playerId = session['x-hasura-user-id'];
|
||||
|
||||
if (role !== 'player') {
|
||||
throw new Error('expected role player');
|
||||
@@ -104,5 +105,3 @@ async function updateVerifiedProfiles(
|
||||
updatedProfiles,
|
||||
};
|
||||
}
|
||||
|
||||
export default handler;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { did } from '@metafam/utils';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
import { getPlayer } from './users';
|
||||
|
||||
const unauthorizedVariables = {
|
||||
@@ -7,19 +8,18 @@ const unauthorizedVariables = {
|
||||
};
|
||||
|
||||
function getHeaderToken(req: Request): string | null {
|
||||
const authHeader = req.headers['authorization'];
|
||||
const authHeader = req.headers.authorization;
|
||||
if (!authHeader) return null;
|
||||
const token = authHeader.replace('Bearer ', '');
|
||||
if (token.length === 0) return null;
|
||||
return token;
|
||||
}
|
||||
|
||||
const handler = async (req: Request, res: Response) => {
|
||||
export const authHandler = async (req: Request, res: Response) => {
|
||||
const token = getHeaderToken(req);
|
||||
|
||||
if (!token) {
|
||||
res.json(unauthorizedVariables);
|
||||
return;
|
||||
} else {
|
||||
const claim = did.verifyToken(token);
|
||||
if (!claim) {
|
||||
@@ -37,5 +37,3 @@ const handler = async (req: Request, res: Response) => {
|
||||
res.json(hasuraVariables);
|
||||
}
|
||||
};
|
||||
|
||||
export default handler;
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import express from 'express';
|
||||
|
||||
import { asyncHandlerWrapper } from '../lib/apiHelpers';
|
||||
import { actionRoutes } from './actions/routes';
|
||||
import { authHandler } from './auth-webhook/handler';
|
||||
|
||||
import actionsRoutes from './actions/routes';
|
||||
|
||||
import authHandler from './auth-webhook/handler';
|
||||
|
||||
const router = express.Router();
|
||||
export const router = express.Router();
|
||||
|
||||
router.get('/', function (_, res) {
|
||||
res.send('pong');
|
||||
});
|
||||
|
||||
router.get('/auth-webhook', asyncHandlerWrapper(authHandler));
|
||||
router.use('/actions', actionsRoutes);
|
||||
|
||||
export default router;
|
||||
router.use('/actions', actionRoutes);
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import express from 'express';
|
||||
import bodyParser from 'body-parser';
|
||||
import express from 'express';
|
||||
|
||||
import config from './config';
|
||||
|
||||
import routes from './handlers/routes';
|
||||
import { CONFIG } from './config';
|
||||
import { router } from './handlers/routes';
|
||||
import { errorMiddleware } from './lib/apiHelpers';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use(routes);
|
||||
app.use(router);
|
||||
|
||||
app.use(errorMiddleware);
|
||||
|
||||
app.listen(config.port, function () {
|
||||
console.log(`Listening on port ${config.port}`);
|
||||
app.listen(CONFIG.port, () => {
|
||||
console.log(`Listening on port ${CONFIG.port}`);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
|
||||
export function asyncHandlerWrapper(middleware: any) {
|
||||
if (middleware.length === 4) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import fetch from 'node-fetch';
|
||||
import config from '../config';
|
||||
|
||||
import { CONFIG } from '../config';
|
||||
|
||||
export async function hasuraQuery(query: string, qv: any = {}) {
|
||||
const result = await fetch(config.graphqlURL, {
|
||||
const result = await fetch(CONFIG.graphqlURL, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ query: query, variables: qv }),
|
||||
body: JSON.stringify({ query, variables: qv }),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-hasura-access-key': config.adminKey,
|
||||
'x-hasura-access-key': CONFIG.adminKey,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user