Skip to content

Commit

Permalink
integração criar eletiva e trilha
Browse files Browse the repository at this point in the history
  • Loading branch information
yaskisoba committed Nov 23, 2023
1 parent 7fe16b7 commit b5a3322
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 58 deletions.
4 changes: 2 additions & 2 deletions backend/config/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"development": {
"username": "root",
"password": "123456",
"database": "banch",
"password": "password",
"database": "matriculai_development",
"host": "localhost",
"dialect": "mysql"
},
Expand Down
68 changes: 21 additions & 47 deletions frontend/src/pages/CreateEletivas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,29 @@ const CreateEletivas = () => {
const [error, setError] = useState("");

const handleCadastro = async () => {
if (!nomeEletiva || !descricao || !serie || !professor || !vagas || !horario) {

setError("Preencha todos os campos");
return;
};
console.log(nomeEletiva);
console.log(descricao);
console.log(serie);
console.log(professor);
console.log(vagas);
console.log(horario);

try {
const response = await axios.post('localhost:3000', {nomeEletiva, descricao, serie, professor, vagas, horario });

if (response.status === 200) {

toast({
title: 'Account created.',
description: "We've created your account for you.",
status: 'success',
duration: 2800,
isClosable: true,
position: 'top'
})

// Sucesso, redirecionar ou realizar outras ações necessárias
navigate("/home");
} else {
// Exibir mensagem de erro
setError(response.data.message);
}
} catch (error) {
if (axios.isAxiosError(error)) {
// Imprime informações detalhadas sobre o erro Axios
console.error("Erro ao fazer cadastro - Status:", error.response?.status);
console.error("Erro ao fazer cadastro - Data:", error.response?.data);
} else {
console.error("Erro ao cadastrar:", error);
}

setError("Erro ao cadastrar. Tente novamente mais tarde.");
try{
const data = {
name: nomeEletiva,
description: descricao,
school_year: parseInt(serie),
teacher: professor,
vacancies: parseInt(vagas),
schedules: parseInt(horario)
};

const response = await axios.post('http://localhost:3001/elective/createElective', data)
console.log(response.data);
navigate('/home')

}catch(err) {
console.error('Erro no cadastro:', err);
}
};

}

return (
<ChakraProvider>


<C.Container>
<C.Content>

Expand Down Expand Up @@ -132,9 +106,9 @@ const CreateEletivas = () => {
value={serie}
onChange={(e)=>[setSerie(e.target.value), setError("")]}
>
<option value='option1'> 1</option>
<option value='option2'> 2</option>
<option value='option3'> 3</option>
<option value={1}>1</option>
<option value={2}>2</option>
<option value={3}>3</option>
</Select>

<FormLabel color= '#243A69'>Professor Responsável</FormLabel>
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/pages/CreateTrilhas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ const CreateTrilhas = () => {
setError("Preencha todos os campos");
return;
};
console.log(nomeTrilha);
console.log(descricao);
console.log(serie);
console.log(eletivas);

try {
const response = await axios.post('localhost:3000', {nomeTrilha, descricao, serie, eletivas });
const response = await axios.post('http://localhost:3001/learningpath/createLearningPaths', {name: nomeTrilha, description: descricao, school_year: parseInt(serie), electives: eletivas });

if (response.status === 200) {
console.log(response)
if (response.status === 201) {

toast({
title: 'Trilha cadastrada.',
Expand Down Expand Up @@ -128,9 +125,9 @@ const CreateTrilhas = () => {
value={serie}
onChange={(e)=>[setSerie(e.target.value), setError("")]}
>
<option value='option1'> 1</option>
<option value='option2'> 2</option>
<option value='option3'> 3</option>
<option value={1}> 1</option>
<option value={2}> 2</option>
<option value={3}> 3</option>
</Select>

<FormLabel color= '#243A69'>Eletivas relacionadas </FormLabel>
Expand Down

0 comments on commit b5a3322

Please sign in to comment.