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: aba de cosulta v1 #27

Merged
merged 4 commits into from
Nov 4, 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
66 changes: 66 additions & 0 deletions functions/src/controller/consultation/forwardedForConsultation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as functions from 'firebase-functions';
import { fetchSchoolsData, SchoolData } from '../school/fetchSchool';
import { fetchClassroomData, ClassroomData } from '../classroom/fetchClassroom';
import { fetchStudentData, StudentData } from '../student/fetchStudent';

interface StudentReport {
school: string | undefined;
classroom_id: string | undefined;
classroom: string | undefined;
student_name: string;
student_id: string;
birthday: string;
points: number;
}

//todo: fazer offset limit para firebase

// buscar alunos por escola e com pontos > 5

const getStudent = async (schools: SchoolData[], classrooms: ClassroomData[], student: StudentData): Promise<StudentReport | null> => {

const classroom = classrooms.find(classroom => classroom.id === student.object.classroom_fk);

let school: SchoolData | undefined;
if (classroom) {
school = schools.find(school => school.id === classroom.object.school_fk);
}
if (student.object.points < 5) {
return null;
}

const studentReport: StudentReport = {
school: school?.object.name,
classroom_id: classroom?.id,
classroom: classroom?.object.name,
student_id: student.id,
student_name: student.object.name,
birthday: student.object.birthday,
points: student.object.points,
};

return studentReport;
};

export const forConsultation = (cors: any) => functions.https.onRequest(async (req, res) => {
cors(req, res, async () => {
try {

const [schools, classrooms, students] = await Promise.all([fetchSchoolsData(), fetchClassroomData(), fetchStudentData()]);

// Gerar relatórios apenas para estudantes com pontos > 5
const totalForwardedPromises = students.map((student: StudentData) =>
getStudent(schools, classrooms, student)
);

const totalForwarded = await Promise.all(totalForwardedPromises);
const filteredTotalForwarded = totalForwarded.filter(report => report !== null);


res.status(200).send(filteredTotalForwarded);
} catch (err: any) {
res.status(500).send(err.message);
}
});
});

6 changes: 6 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { generateForConsultationReport } from "./controller/report/fetchForConsu

import { deleteClassroom } from "./controller/classroom/deleteClassroom";

import { forConsultation } from "./controller/consultation/forwardedForConsultation";

import { listUsers } from "./controller/users/listUsers";
import { deleteUserData } from "./controller/users/deleteUser";
import { createUserData } from "./controller/users/createUser";
Expand All @@ -29,13 +31,17 @@ export const consultationReport = generateForConsultationReport(corsMiddleware);

export const classroomDelete = deleteClassroom(corsMiddleware);

export const fowardedForConsultation = forConsultation(corsMiddleware);

export const usersList = listUsers(corsMiddleware);
export const userDelete = deleteUserData(corsMiddleware);
export const userCreate = createUserData(corsMiddleware);
export const userUpdate = updateUserData(corsMiddleware);

export const addPointsStud = addPointsStudent(corsMiddleware);

//export const fowardedGet


export const helloWorld = functions.https.onRequest((request, response) => {
corsMiddleware(request, response, () => {
Expand Down
73 changes: 73 additions & 0 deletions src/components/Boxes/BoxConsultation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

import { makeStyles } from "@material-ui/core/styles";

import React from "react";
import { useHistory } from "react-router-dom";

import Grid from "@material-ui/core/Grid";
import { Clear } from "@material-ui/icons";
import Swal from "sweetalert2";
import image from "../../assets/images/Atenção-img.png";
import IconActive from "../../assets/images/activeRegistration.svg";
import IconNotActive from "../../assets/images/notactiveRegistration.svg";
import IconClasMedia from "../../assets/images/iconClasMedia.svg"
import styled from "../../styles";
import styles from "./styles";
import { deleteRegistration } from "../../controller/registration/deleteRegistration";

const useStyles = makeStyles(styles);

const BoxConsultation = props => {
const { name, link, md, sm, xs, turma, id, points, birthday } = props;

const classes = useStyles();
const history = useHistory();

const toLink = (e) => {
history.push(link)
}

const deletePreRegistration = (e, id) => {
e.stopPropagation()
if (id) {

return Swal.fire({
title: "Excluir pré matricula?",
text: "Essa ação é irreversível não pode ser desfeita",
imageUrl: image,
imageHeight: 250,
showCancelButton: true,
confirmButtonColor: styled.colors.colorsBaseProductNormal,
cancelButtonColor: styled.colors.colorsBaseCloudNormal,
confirmButtonText: 'Aceitar',
reverseButtons: true,
cancelButtonText: `<div style="color:black" >Cancelar</div>`
}).then((result) => {
if (result.isConfirmed) {
deleteRegistration(id)
// requestDeletePreRegistrationMutation.mutate(id)
}
})
}
}

return (
<Grid item md={md ? md : 4} sm={sm ? sm : 4} xs={xs ? xs : 12}>
<Grid onClick={toLink} className={`${classes.boxStudentConfirmation}`}>
<div className={`${classes.floatLeft} ${classes.nameStudent}`}>
<span className={classes.subtitleStudent}>Aluno - {turma}</span>
<Clear onClick={e => deletePreRegistration(e, id)} style={{ cursor: 'pointer' }} />
</div>
<div className={classes.iconStudent}>
<img src={points < 5 ? IconActive : (points >= 5 && points < 9) ? IconClasMedia : points >= 10 ? IconNotActive : ""} alt="Icone de aluno" />
<div title={name} style={{ margin: "auto 10px" }} className={`${classes.title}`}>
{name}
</div>
<p birthday={birthday} > Nascimento: {birthday} </p>
</div>
</Grid>
</Grid>
);
};

export default BoxConsultation;
2 changes: 2 additions & 0 deletions src/components/Boxes/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import BoxBig from "./BoxBig";
import BoxConsultation from "./BoxConsultation";
import BoxDiscriptionClassroom from "./BoxDiscriptionClassroom";
import BoxDiscriptionSchedule from "./BoxDiscriptionSchedule";
import BoxVacancies from "./BoxVacancies";
import BoxRegistration from "./BoxRegistration";
import BoxStatus from "./BoxStatus";
export {
BoxBig,
BoxConsultation,
BoxDiscriptionClassroom,
BoxDiscriptionSchedule,
BoxVacancies,
Expand Down
21 changes: 10 additions & 11 deletions src/components/Layouts/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import turmaGraySvg from "../../assets/images/classroom-gray.svg";
import usersBlueSvg from "../../assets/images/usuarios-blue.svg";
import usersGraySvg from "../../assets/images/usuarios-grey.svg";

// import estetoscopioBlueSvg from "../../assets/images/estetoscopio-blue.svg";
// import estetoscopioGraySvg from "../../assets/images/estetoscopio-grey.svg";
import estetoscopioBlueSvg from "../../assets/images/stethoscope-blue.svg";
import estetoscopioGraySvg from "../../assets/images/stethoscope-grey.svg";

import { useMediaQuery } from "@material-ui/core";
import styles from "./styles";
Expand Down Expand Up @@ -42,28 +42,27 @@ const Sidebar = ({isSidebar}) => {
Icon: <img src={turmaGraySvg} alt="icone de turma em cinza"></img>
},
{
to: "/Consultas",
name: "Consultas",
exact: false,
IconActive: <img src={estetoscopioBlueSvg} alt="estetoscopio em azul" />,
Icon: <img src={estetoscopioGraySvg} alt="estetoscopio em cinza" />
},
user?.role === 1 && {
to: "/relatorios",
name: "Relatórios",
exact: false,
IconActive: <img src={turmaBlueSvg} alt="icone de relatórios em azul"></img>,
Icon: <img src={turmaGraySvg} alt="icone de relatórios em cinza"></img>
},

user?.role === 1 && {
to: "/usuarios",
name: "Usuários",
exact: false,
IconActive: <img src={usersBlueSvg} alt="icone de usuários em azul" />,
Icon: <img src={usersGraySvg} alt="icone de usuários em cinza" />
},

// user?.role === 3 && {
// to: "/areaMedica",
// name: "Area Médica",
// exact: false,
// IconActive: <img src={estetoscopioBlueSvg} alt="estetoscopio em azul" />,
// Icon: <img src={estetoscopioGraySvg} alt="estetoscopio em cinza" />
// },


];

Expand Down
31 changes: 31 additions & 0 deletions src/containers/Consultation/Consultation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useEffect, useState } from "react";
import fetchClassroom from "../../controller/classroom/fetchClassroom";
import Consultation from "../../screens/Consultation/Consultation";
import { getIdSchool } from "../../services/auth";

const Home = props => {

const [classroom, setClassroom] = useState([])

const [idSchool, setIdSchool] = useState()

useEffect(() => {
fetchClassroom()
.then((testDataList) => {
const classroomSchool = testDataList.filter(props => props.object.school_fk === getIdSchool())
setClassroom(classroomSchool)
})
.catch((err) => {
// Trate erros, se ocorrerem
console.error(err)
})
}, [idSchool])

return (
<>
<Consultation classroom={classroom} setIdSchool={setIdSchool} idSchool={idSchool} />
</ >
);
};

export default Home;
4 changes: 4 additions & 0 deletions src/containers/Consultation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Consultation from "./Consultation";


export { Consultation };
5 changes: 4 additions & 1 deletion src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import CreateUserScreen from "./screens/Users/CreateUser";
import PrivateRouterProvider from "./context/PrivateRouter/context";
import CreateRegistration from "./screens/Classroom/CreateRegistration";
import {Report} from "./containers/Report"
import {Consultation} from "./containers/Consultation"


// PDFs
Expand Down Expand Up @@ -73,8 +74,10 @@ const Routes = () => (
<PrivateRoute exact path="/escolas/:id" component={SchoolClassrooms} />
<PrivateRoute exact path="/criar/escolas" component={SchoolCreate} />
<PrivateRoute exact path="/turmas" component={Classroom} />
<PrivateRoute exact path="/relatorios" component={Report} />

<PrivateRoute exact path="/consultas" component={Consultation} />

<PrivateRoute exact path="/relatorios" component={Report} />
<PrivateRoute exact path="/relatorios/pdfrelatorio" component={PdfRelatorioGeral} />
<PrivateRoute exact path="/relatorios/pdfestudantesparaconsulta" component={PdfForConsultation} />

Expand Down
34 changes: 20 additions & 14 deletions src/screens/Classroom/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Swal from "sweetalert2";
import styles from "../../styles";
import image from "../../assets/images/Atenção-img.png";


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

Expand All @@ -30,10 +29,8 @@ const Create = (props) => {
const { id } = useParams();

const deletePreRegistration = (e, id) => {
e.stopPropagation()
e.stopPropagation();
if (id) {


return Swal.fire({
title: "Excluir turma?",
text: "Essa ação é irreversível não pode ser desfeita",
Expand All @@ -42,16 +39,16 @@ const Create = (props) => {
showCancelButton: true,
confirmButtonColor: styles.colors.colorsBaseProductNormal,
cancelButtonColor: styles.colors.colorsBaseCloudNormal,
confirmButtonText: 'Aceitar',
confirmButtonText: "Aceitar",
reverseButtons: true,
cancelButtonText: `<div style="color:black" >Cancelar</div>`
cancelButtonText: `<div style="color:black" >Cancelar</div>`,
}).then((result) => {
if (result.isConfirmed) {
deleteItem(id, history)
deleteItem(id, history);
}
})
});
}
}
};

const registrations = () => {
const registrationList = data ?? [];
Expand Down Expand Up @@ -174,7 +171,7 @@ const Create = (props) => {
return count;
};

console.log(registration)
console.log(registration);
return (
<BoxRegistration
link={`${baseLink}/${registration?.id}`}
Expand All @@ -183,7 +180,11 @@ const Create = (props) => {
sex={registration?.sex}
id={registration?.id}
points={points()}
triagem={(registration.object.testCover || registration.object.testManchaBranca || registration.object.testMovimentoOcular)}
triagem={
registration.object.testCover ||
registration.object.testManchaBranca ||
registration.object.testMovimentoOcular
}
md={4}
sm={4}
unavailable={registration?.unavailable}
Expand All @@ -200,11 +201,16 @@ const Create = (props) => {
}}
style={{ cursor: "pointer" }}
/>
<Row id="space-between" style={{ width: "100%", justifyContent: "space-between" }}>
<Row
id="space-between"
style={{ width: "100%", justifyContent: "space-between" }}
>
<h1>{classroom && classroom?.object?.name}</h1>
<Column id="center">
<Delete style={{ cursor: "pointer" }} onClick={e => deletePreRegistration(e, classroom.id)} />

<Delete
style={{ cursor: "pointer" }}
onClick={(e) => deletePreRegistration(e, classroom.id)}
/>
</Column>
</Row>
<h2>Alunos</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ const Home = (props) => {
receitaEsfericoOlhoDireito: Yup.string().required("Campo obrigatório"),
receitaCilindricoOlhoDireito: Yup.string().required("Campo obrigatório"),
receitaEixoOlhoDireito: Yup.string().required("Campo obrigatório"),
receitaDpOlhoDireito: Yup.string().required("Campo obrigatório"),
receitaEsfericoOlhoEsquerdo: Yup.string().required("Campo obrigatório"),
receitaCilindricoOlhoEsquerdo: Yup.string().required("Campo obrigatório"),
receitaEixoOlhoEsquerdo: Yup.string().required("Campo obrigatório"),
receitaDpOlhoEsquerdo: Yup.string().required("Campo obrigatório"),
});

const validationSchemaOculos = Yup.object().shape({
Expand Down
Loading
Loading