Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat meuben #30

Merged
merged 11 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,423 changes: 1,325 additions & 98 deletions functions/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"main": "lib/index.js",
"dependencies": {
"@firebase/firestore": "^4.6.4",
"axios": "^1.7.3",
"axios": "^1.7.7",
"firebase": "^11.0.1",
"firebase-admin": "^12.1.0",
"firebase-functions": "^5.0.0"
"firebase-functions": "^5.1.1"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fetchClassroomData, ClassroomData } from '../classroom/fetchClassroom';
import { fetchStudentData, StudentData } from '../student/fetchStudent';

interface StudentReport {
school_id: string | undefined;
school: string | undefined;
classroom_id: string | undefined;
classroom: string | undefined;
Expand All @@ -30,6 +31,7 @@ const getStudent = async (schools: SchoolData[], classrooms: ClassroomData[], st
}

const studentReport: StudentReport = {
school_id: school?.id,
school: school?.object.name,
classroom_id: classroom?.id,
classroom: classroom?.object.name,
Expand Down
21 changes: 21 additions & 0 deletions functions/src/controller/migrationMeuBen/getProjetos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as functions from "firebase-functions";
import axios from "axios";


export const getProjetos = (cors: any) => functions.https.onRequest((request, response) => {
cors(request, response, async () => {
try {

const url = `https://br-ipti-beneficiarios.azurewebsites.net/aviste-bff?token=${process.env.TOKEN}`;

// Requisição GET para a API usando Axios
const result = await axios.get(url);
const data = result.data;

response.send(data);
} catch (error) {
console.error("Erro ao buscar dados:", error);
response.status(500).send("Erro ao buscar dados.");
}
});
});
77 changes: 77 additions & 0 deletions functions/src/controller/migrationMeuBen/postProjetos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as functions from "firebase-functions";
import axios from "axios";
import { fetchStudentData } from '../student/fetchStudent';

interface StudentData {
name: string;
birthday: string;
cpf: string;
sex: number | undefined;
color_race: number | undefined;
deficiency: boolean | undefined;
zone: number | undefined;
}

interface BodyMigrationData {
project: number | undefined;
name: string | undefined;
year: number | undefined;
registration: StudentData[];
}

export function converterData(data: string) {
const partes = data.split('/');

const dia = partes[0];
const mes = partes[1];
const ano = partes[2];

const dataFormatada = `${ano}-${mes}-${dia}`;
return dataFormatada;
}

const getStudentData = async (id: string) => {

const students = await fetchStudentData();
const studentData = students.filter(student => student.object.classroom_fk === id);

const studentMigrationData = studentData.map((student) => {
return {
name: student.object.name,
birthday: converterData(student.object.birthday),
cpf: (student.object.cpf).replace(/[^a-zA-Z0-9]/g, ''),
sex: parseInt(student.object.sex) ?? undefined,
color_race: parseInt(student.object.colorRace) ?? undefined,
deficiency: student.object.deficiency ?? false,
zone: parseInt(student.object.zone) ?? undefined,
}
});
return studentMigrationData;
};

export const postProjetos = (cors: any) =>
functions.https.onRequest((request, response) => {
cors(request, response, async () => {
try {
const url = `https://br-ipti-beneficiarios.azurewebsites.net/aviste-bff?token=${process.env.TOKEN}`;

const studentData = await getStudentData(request.body.id);

const body: BodyMigrationData = {
project: request.body.project,
name: request.body.name,
year: request.body.year,
registration: studentData,
};

let res = await axios.post(url, body).catch((error) => {
console.error("Erro ao enviar dados:", error);
return error.response;
});

response.send(res.data);
} catch (error:any) {
response.status(500).send("Erro ao enviar dados.");
}
});
});
11 changes: 8 additions & 3 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as functions from "firebase-functions";
import * as cors from "cors"
import * as cors from "cors";

import { generateReport } from "./controller/report/fetchReport";
import { generateStudentsReport } from "./controller/report/fetchStudents";
import { generateForConsultationReport } from "./controller/report/fetchForConsultation";
Expand All @@ -15,8 +16,10 @@ import { updateUserData } from "./controller/users/updateUser";

import { addPointsStudent } from "./controller/addPointsStudents/addPointsStudents";

// import { fetchUsersData } from "./controller/users/fetchUsers";
import { getProjetos } from "./controller/migrationMeuBen/getProjetos";
import { postProjetos } from "./controller/migrationMeuBen/postProjetos";

// import { fetchUsersData } from "./controller/users/fetchUsers";
// admin.initializeApp();

const corsOptions = {
Expand All @@ -40,7 +43,9 @@ export const userUpdate = updateUserData(corsMiddleware);

export const addPointsStud = addPointsStudent(corsMiddleware);

//export const fowardedGet
export const getProjetosMigration = getProjetos(corsMiddleware);
export const postProjetosMigration = postProjetos(corsMiddleware);



export const helloWorld = functions.https.onRequest((request, response) => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Layouts/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ const Header = ({ setIsSidebar, isSidebar }) => {

};


return (
<AppBar classes={{ root: classes.root }} position="static">

<Column>
<Row>
{matches ? <Column id="center">
Expand Down Expand Up @@ -119,6 +119,7 @@ const Header = ({ setIsSidebar, isSidebar }) => {
>
<MenuItem value="sair" onClick={handleLogout}>Sair</MenuItem>
</Menu>

</>
)}
</>
Expand Down
49 changes: 41 additions & 8 deletions src/screens/Classroom/Form.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from "react";
import React, { useEffect, useState } from "react";

// Material UI
import Grid from "@material-ui/core/Grid";
import Alert from "@material-ui/lab/Alert";

// Third party

// Components
import { useParams } from "react-router-dom";
import { BoxRegistration } from "../../components/Boxes";
Expand All @@ -20,14 +18,34 @@ import { deleteItem } from "../../controller/classroom/deleteClassroom";
import Swal from "sweetalert2";
import styles from "../../styles";
import image from "../../assets/images/Atenção-img.png";
import api from "../../services/api";

import MigrationDialog from "./MigrationDialog";

const Create = (props) => {
const history = useHistory();

const { data, baseLink, classroom } = props;

const { id } = useParams();

const [projects, setProjects] = useState([]);
const [dialogVisible, setDialogVisible] = useState(false);


useEffect(() => {
const callFunction = async () => {
try {
const result = await api.get(
"http://127.0.0.1:5001/br-ipti-visao/us-central1/getProjetosMigration"
);
setProjects(result.data);
} catch (error) {
console.error("Error calling function:", error);
}
};
callFunction();
}, []);

const deletePreRegistration = (e, id) => {
e.stopPropagation();
if (id) {
Expand Down Expand Up @@ -171,7 +189,6 @@ const Create = (props) => {
return count;
};

console.log(registration);
return (
<BoxRegistration
link={`${baseLink}/${registration?.id}`}
Expand Down Expand Up @@ -221,7 +238,7 @@ const Create = (props) => {
direction="row"
style={{ marginBottom: "16px" }}
>
<Grid item md={3} sm={2}>
<Grid item md={2} sm={3}>
<ButtonPurple
className="t-button-primary"
onClick={() => history.push(`/turmas/${id}/pdf`)}
Expand All @@ -230,21 +247,37 @@ const Create = (props) => {
</Grid>

<Padding />
<Grid item md={3} sm={2}>
<Grid item md={2} sm={3}>
<ButtonPurple
className="t-button-primary"
onClick={() => history.push(`/turmas/${id}/pdfreceita`)}
title={"Gerar receitas"}
/>
</Grid>
<Padding />
<Grid item md={3} sm={2}>
<Grid item md={2} sm={3}>
<ButtonPurple
className="t-button-primary"
onClick={() => history.push(`/turmas/${id}/criar-aluno`)}
title={"Adicionar alunos"}
/>
</Grid>
<Padding />
<Grid item md={2} sm={3}>
<ButtonPurple
className="t-button-primary"
onClick={() => setDialogVisible(true)} // Abre o dialog ao clicar
title={"Migrar turma para MeuBen"}
aria-controls={dialogVisible ? "dlg" : null}
aria-expanded={dialogVisible ? true : false}
/>

<MigrationDialog
visible={dialogVisible}
setVisible={setDialogVisible}
projects={projects}
/>
</Grid>
</Grid>
<Grid container direction="row" spacing={4}>
<List items={registrations()}>
Expand Down
Loading
Loading