Skip to content

Commit

Permalink
Merge pull request #31 from HackYourFuture-CPH/implementIndexPage
Browse files Browse the repository at this point in the history
validate team code
  • Loading branch information
nishadipri committed Apr 24, 2024
2 parents 93de3b0 + 9a46ffc commit a85d4a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function App() {
<Navbar />
<Routes>
<Route path="/" element={<IndexPage />} />
<Route path="/:teamId/retro" element={<RetroPage />} />
<Route path="/CreateNewTeamPage" element={<CreateTeam />} />
<Route path="/joinretro" element={<JoinRetroPage />} />
<Route path="/retro" element={<RetroPage />} />
Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/containers/IndexPage/IndexPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function IndexPage() {

if (inputValue.trim() !== '') {
try {
const response = await fetch(`${apiURL}/validateTeamCode`, {
const response = await fetch(`${apiURL()}/teams/validateTeamCode`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -30,7 +30,9 @@ function IndexPage() {
if (response.ok) {
// Navigate to retroPage

navigate('/retroPage');
const body = await response.json();

navigate(`${body.id}/retro`);
} else {
setErrorMessage(
'Invalid team code. Please try again or make sure you entered the correct team code.',
Expand Down
13 changes: 13 additions & 0 deletions packages/server/api/controllers/teamsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ const createTeam = async (body) => {
};
};

const validateTeamCode = async (body) => {
const { teamCode } = body;

const results = await knex('Teams').where({ team_code: teamCode });

if (results.length === 0) {
throw new Error('Team not found');
}

return results[0];
};

module.exports = {
createTeam,
validateTeamCode,
};
7 changes: 7 additions & 0 deletions packages/server/api/routes/teams.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ router.post('/', (req, res, next) => {
.catch(next);
});

router.post('/validateTeamCode', (req, res, next) => {
teamsController
.validateTeamCode(req.body)
.then((result) => res.json(result))
.catch(next);
});

module.exports = router;

0 comments on commit a85d4a8

Please sign in to comment.