Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.2 kB
1
Indexable
Never
const prisma = require('../../prisma/index.js');
const {
    CreatePopularTeams,
    GetAllTeams,
    GetSingleTeam,
    DeleteTeam,
    CreatePopularPlayers,
    GetAllPlayers,
    GetSinglePlayer,
    DeletePlayer,
    CreatePopularLeagues,
    GetAllLeagues,
    GetSingleLeague,
    DeleteLeague
} = require('../services/popular-services.js');
const { SignUp, SignIn, GetProfile, GetAllUsers, UpdateUserRole } = require('../services/user-service.js');
const { userAuth, userAuthorization, verifyApiKey } = require('./middleware/userAuth');

module.exports = app => {
    // Popular Teams
    // Create team
    app.post('/popular_team', async (req, res, next) => {
        const teamData = req.body;
        const data = await CreatePopularTeams({ teamData });
        res.json({
            message: 'Team created successfully',
            data: data
        });
    });

    //Get all teams
    app.post('/popular_teams', async (req, res, next) => {
        const data = await GetAllTeams();
        res.json({
            message: 'All teams fetched successfully',
            data: data
        });
    });

    //Get a single team
    app.post('/popular_team/:teamId', async (req, res) => {
        const id = req.params.teamId;
        const data = await GetSingleTeam(id);
        res.json({
            status: true,
            message: 'team fetched successfully',
            data: data
        });
    });

    //Delete a team
    app.delete('/popular_team/:teamId', async (req, res) => {
        const id = req.params.teamId;
        const data = await DeleteTeam(id);
        res.json({
            message: 'team deleted successfully',
            data: data
        });
    });

    // Popular Players
    // Create player
    app.post('/popular_player', async (req, res, next) => {
        const playerData = req.body;
        const data = await CreatePopularPlayers({ playerData });
        res.json({
            message: 'Player created successfully',
            data: data
        });
    });

    //Get all players
    app.post('/popular_players', async (req, res, next) => {
        const data = await GetAllPlayers();
        res.json({
            message: 'All players fetched successfully',
            data: data
        });
    });

    //Get a single player
    app.post('/popular_player/:playerId', async (req, res) => {
        const id = req.params.playerId;
        const data = await GetSinglePlayer(id);
        res.json({
            status: true,
            message: 'player fetched successfully',
            data: data
        });
    });

    //Delete a player
    app.delete('/popular_player/:playerId', async (req, res) => {
        const id = req.params.playerId;
        const data = await DeletePlayer(id);
        res.json({
            message: 'player deleted successfully',
            data: data
        });
    });

    // Popular leagues
    // Create league
    app.post('/popular_league', async (req, res, next) => {
        const leagueData = req.body;
        const data = await CreatePopularLeagues({ leagueData });
        res.json({
            message: 'league created successfully',
            data: data
        });
    });

    //Get all leagues
    app.post('/popular_leagues', async (req, res, next) => {
        const data = await GetAllLeagues();
        res.json({
            message: 'All leagues fetched successfully',
            data: data
        });
    });

    //Get a single league
    app.post('/popular_league/:leagueId', async (req, res) => {
        const id = req.params.leagueId;
        const data = await GetSingleLeague(id);
        res.json({
            status: true,
            message: 'league fetched successfully',
            data: data
        });
    });

    //Delete a league
    app.delete('/popular_league/:leagueId', async (req, res) => {
        const id = req.params.leagueId;
        const data = await DeleteLeague(id);
        res.json({
            message: 'league deleted successfully',
            data: data
        });
    });
};