We are building the first open-source live results and statistics platform with community involvement features for data insertion. The project includes a blockchain component that will allow participants to receive rewards based on their participation and also to stake the future Token of the platform.
This function checks in real-time whether the username is already taken. It queries the authors table for the given username within the data JSONB field.
Endpoint: POST /sportstack/validate-username
import { queryHasura } from './hasura';
export async function post(req, res) {
const { username } = req.body;
const query = `
query ValidateUsername($username: String!) {
authors(where: {data: {username: {_eq: $username}}}) {
id
}
}
`;
try {
const { authors } = await queryHasura(query, { username });
// If any result is returned, the username is already taken
if (authors.length > 0) {
return res.json({ available: false });
}
return res.json({ available: true });
} catch (error) {
console.error('Error validating username:', error);
return res.status(500).json({ message: 'Error validating username' });
}
}
3. Function to Create a Sportstack
This function inserts a new Sportstack into the authors table, including the user ID, data (with username, avatar, etc.), status, and permalink. The permalink is generated by sanitizing the username (lowercase, replacing spaces with -, and removing non-alphanumeric characters).
Retrieves all Sportstacks for a given user based on their uid.
Validate Username Availability:
POST /sportstack/validate-username
Checks if a given username is available.
Create Sportstack:
POST /sportstack/create
Creates a new Sportstack with user data, status, and permalink.
This structure ensures that you have the required endpoints to manage Sportstacks for a user, validate usernames in real-time, and create new Sportstacks while ensuring the username is sanitized and stored properly.
1. Get List of Sportstacks by User ID
This function will return a list of Sportstacks for a given user UID from the Hasura database.
Endpoint:
GET /sportstacks/:uid
2. Validation Function for Username Availability
This function checks in real-time whether the username is already taken. It queries the
authors
table for the given username within thedata
JSONB field.Endpoint:
POST /sportstack/validate-username
3. Function to Create a Sportstack
This function inserts a new Sportstack into the
authors
table, including the user ID, data (with username, avatar, etc.), status, and permalink. The permalink is generated by sanitizing the username (lowercase, replacing spaces with-
, and removing non-alphanumeric characters).Endpoint:
POST /sportstack/create
4. Helper Function: Hasura Query Execution
This helper function interacts with Hasura using its GraphQL endpoint.
hasura.js
Data Example (What Will Be Stored in Hasura)
UID:
DxsfWqabJqX3omn2mqoQns7G
data:
status:
published
permalink:
super-apostas
Summary of API Endpoints:
List Sportstacks by UID:
GET /sportstacks/:uid
uid
.Validate Username Availability:
POST /sportstack/validate-username
Create Sportstack:
POST /sportstack/create
This structure ensures that you have the required endpoints to manage Sportstacks for a user, validate usernames in real-time, and create new Sportstacks while ensuring the username is sanitized and stored properly.
ACCEPTANCE CRITERIA: