v3.1
This commit is contained in:
parent
28025099a6
commit
aa77177631
File diff suppressed because one or more lines are too long
@ -17,6 +17,9 @@ const pexelsRoutes = require('./routes/pexels');
|
|||||||
|
|
||||||
const organizationForAuthRoutes = require('./routes/organizationLogin');
|
const organizationForAuthRoutes = require('./routes/organizationLogin');
|
||||||
|
|
||||||
|
const adminOnboardingRoutes = require('./routes/adminOnboarding');
|
||||||
|
const checkPermissions = require('./middlewares/check-permissions');
|
||||||
|
|
||||||
const openaiRoutes = require('./routes/openai');
|
const openaiRoutes = require('./routes/openai');
|
||||||
|
|
||||||
const contactFormRoutes = require('./routes/contactForm');
|
const contactFormRoutes = require('./routes/contactForm');
|
||||||
@ -196,6 +199,15 @@ app.use(
|
|||||||
searchRoutes,
|
searchRoutes,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Admin Onboarding endpoint
|
||||||
|
app.use(
|
||||||
|
'/api/admin/onboarding',
|
||||||
|
passport.authenticate('jwt', { session: false }),
|
||||||
|
checkPermissions(['CREATE_LEAGUES']),
|
||||||
|
adminOnboardingRoutes,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
app.use('/api/org-for-auth', organizationForAuthRoutes);
|
app.use('/api/org-for-auth', organizationForAuthRoutes);
|
||||||
|
|
||||||
const publicDir = path.join(__dirname, '../public');
|
const publicDir = path.join(__dirname, '../public');
|
||||||
|
|||||||
39
backend/src/routes/adminOnboarding.js
Normal file
39
backend/src/routes/adminOnboarding.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const LeaguesService = require('../services/leagues');
|
||||||
|
const UsersService = require('../services/users');
|
||||||
|
const { authenticateJWT } = require('../auth/auth');
|
||||||
|
const checkPermissions = require('../middlewares/check-permissions');
|
||||||
|
|
||||||
|
// POST /api/admin/onboarding
|
||||||
|
router.post(
|
||||||
|
'/',
|
||||||
|
authenticateJWT,
|
||||||
|
checkPermissions('CREATE_LEAGUES'),
|
||||||
|
async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { leagueName, adminFirstName, adminLastName, adminEmail, adminPassword } = req.body;
|
||||||
|
// Create new league
|
||||||
|
const league = await LeaguesService.create({ name: leagueName }, req.currentUser);
|
||||||
|
// Create league administrator linked to the new league
|
||||||
|
const user = await UsersService.create(
|
||||||
|
{
|
||||||
|
firstName: adminFirstName,
|
||||||
|
lastName: adminLastName,
|
||||||
|
email: adminEmail,
|
||||||
|
password: adminPassword,
|
||||||
|
leagueId: league.id,
|
||||||
|
role: 'League Administrator',
|
||||||
|
},
|
||||||
|
req.currentUser,
|
||||||
|
false,
|
||||||
|
req.get('host'),
|
||||||
|
);
|
||||||
|
res.status(201).json({ league, user });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@ -2,7 +2,7 @@ import axios from 'axios';
|
|||||||
|
|
||||||
export async function getPexelsImage() {
|
export async function getPexelsImage() {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/pexels/image`);
|
const response = await axios.get('/api/pexels-image');
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching image:', error);
|
console.error('Error fetching image:', error);
|
||||||
@ -12,7 +12,7 @@ export async function getPexelsImage() {
|
|||||||
|
|
||||||
export async function getPexelsVideo() {
|
export async function getPexelsVideo() {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/pexels/video`);
|
const response = await axios.get('/api/pexels-video');
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching video:', error);
|
console.error('Error fetching video:', error);
|
||||||
|
|||||||
@ -121,6 +121,14 @@ const menuAside: MenuAsideItem[] = [
|
|||||||
label: 'Profile',
|
label: 'Profile',
|
||||||
icon: icon.mdiAccountCircle,
|
icon: icon.mdiAccountCircle,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
href: '/admin',
|
||||||
|
label: 'Onboarding',
|
||||||
|
icon: icon.mdiAccountPlusOutline,
|
||||||
|
permissions: 'CREATE_LEAGUES',
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
href: '/home',
|
href: '/home',
|
||||||
|
|||||||
16
frontend/src/pages/admin.tsx
Normal file
16
frontend/src/pages/admin.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import type { ReactElement } from 'react';
|
||||||
|
import LayoutAuthenticated from '../layouts/Authenticated';
|
||||||
|
|
||||||
|
export default function OnboardingPage() {
|
||||||
|
return (
|
||||||
|
<div style={{ padding: '2rem' }}>
|
||||||
|
<h1>Admin Onboarding</h1>
|
||||||
|
<p>This is a placeholder for the admin onboarding form.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
OnboardingPage.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return <LayoutAuthenticated>{page}</LayoutAuthenticated>;
|
||||||
|
};
|
||||||
13
frontend/src/pages/api/pexels-image.ts
Normal file
13
frontend/src/pages/api/pexels-image.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { baseURLApi } from '../../../config';
|
||||||
|
|
||||||
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
try {
|
||||||
|
const { data } = await axios.get(`${baseURLApi}/pexels/image`);
|
||||||
|
res.status(200).json(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error proxying pexels image:', error);
|
||||||
|
res.status(500).json({ error: 'Error fetching image' });
|
||||||
|
}
|
||||||
|
}
|
||||||
13
frontend/src/pages/api/pexels-video.ts
Normal file
13
frontend/src/pages/api/pexels-video.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { baseURLApi } from '../../../config';
|
||||||
|
|
||||||
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
try {
|
||||||
|
const { data } = await axios.get(`${baseURLApi}/pexels/video`);
|
||||||
|
res.status(200).json(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error proxying pexels video:', error);
|
||||||
|
res.status(500).json({ error: 'Error fetching video' });
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user