Skip to content

Commit

Permalink
Merge pull request #9 from hack4impact-upenn/joseph-and-caroline/stud…
Browse files Browse the repository at this point in the history
…ent-edits

Updated student.controller.ts for teacher page
  • Loading branch information
annabay04 authored Oct 3, 2023
2 parents 47703e5 + 7d17aec commit 74cfd48
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 58 deletions.
63 changes: 32 additions & 31 deletions client/src/TeacherDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,40 @@ function SplitGrid() {
console.log(studentData);

return (
<Box display="flex" flexDirection="column" width="100%" height="100vh">
<Box>
<PageHeader />
<Box display="flex" flexDirection="column" width="100%" height="100vh">
<Box display="flex" flexGrow={5}>
<Paper
sx={{
width: '30%',
overflowY: 'auto',
maxHeight: 'calc(100vh - 64px)', // Subtract the Toolbar height (default is 64px)
bgcolor: 'white',
p: 2,
}}
elevation={0}
square
>
<h2>Students</h2>
{createData(studentData)}
</Paper>

<Box display="flex" flexGrow={5}>
<Paper
sx={{
width: '30%',
overflowY: 'auto',
maxHeight: 'calc(100vh - 64px)', // Subtract the Toolbar height (default is 64px)
bgcolor: 'white',
p: 2,
}}
elevation={0}
square
>
<h2>Students</h2>
{createData(studentData)}
</Paper>

<Paper
sx={{
width: '70%',
overflowY: 'auto',
maxHeight: 'calc(100vh - 64px)', // Subtract the Toolbar height (default is 64px)
bgcolor: '#EDEDED',
p: 2,
paddingX: 4,
}}
elevation={0}
square
>
<h2>Class Progress</h2>
</Paper>
<Paper
sx={{
width: '70%',
overflowY: 'auto',
maxHeight: 'calc(100vh - 64px)', // Subtract the Toolbar height (default is 64px)
bgcolor: '#EDEDED',
p: 2,
paddingX: 4,
}}
elevation={0}
square
>
<h2>Class Progress</h2>
</Paper>
</Box>
</Box>
</Box>
);
Expand Down
48 changes: 45 additions & 3 deletions server/src/controllers/student.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import express from 'express';
import ApiError from '../util/apiError';
import StatusCode from '../util/statusCode';
import { getAllStudentsFromDB } from '../services/student.service';
import {
getAllStudentsFromDB,
getStudentByID,
} from '../services/student.service';
import { IStudent } from '../models/student.model';

/**
* Get students by teacher_id
Expand All @@ -21,12 +25,27 @@ const getStudentsFromTeacherId = async (
next(ApiError.internal('Request must include a valid teacher_id param'));
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function hasTeacher(student: IStudent) {
const teachers = student.teacher_id;
for (let i = 0; i < teachers.length; i += 1) {
const teacher = teachers[i];
if (teacher === id) {
return true;
}
}
return false;
}

return (
getAllStudentsFromDB()
.then((studentList) => {
return studentList.filter((student) => student.teacher_id === id);
console.log('made it');
// console.log(studentList.filter((student) => hasTeacher(student)));
return studentList;
})
.then((filteredList) => {
console.log('made it to filtered');
res.status(StatusCode.OK).send(filteredList);
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -36,4 +55,27 @@ const getStudentsFromTeacherId = async (
);
};

export { getStudentsFromTeacherId };
// get a specific student
const getStudent = async (
req: express.Request,
res: express.Response,
next: express.NextFunction,
) => {
const { id } = req.params;
if (!id) {
next(ApiError.internal('Request must include a valid student id param'));
}

return (
getStudentByID(id)
.then((user) => {
res.status(StatusCode.OK).send(user);
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((e) => {
next(ApiError.internal('Unable to retrieve specified student'));
})
);
};

export { getStudentsFromTeacherId, getStudent };
23 changes: 0 additions & 23 deletions server/src/models/student.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,6 @@ const StudentSchema = new mongoose.Schema({
type: String,
required: false,
},
parent_name: {
type: String,
required: true,
},
parent_commmunication_days: {
type: String,
enum: ['weekends', 'weekdays', 'any'],
required: false,
},
parent_communication_times: {
type: String,
enum: ['morning', 'afternoon', 'evening'],
required: false,
},
media_waiver: {
type: Boolean,
required: true,
default: false,
},
work_habits: {
type: String,
required: false,
},
});

interface IStudent extends mongoose.Document {
Expand Down
32 changes: 31 additions & 1 deletion server/src/services/student.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
*/
import { Student } from '../models/student.model';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const passwordHashSaltRounds = 10;
const removeSensitiveDataQuery = [
'-password',
'-verificationToken',
'-resetPasswordToken',
'-resetPasswordTokenExpiryDate',
];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const removeSensitiveDataQueryKeepPassword = [
'-verificationToken',
'-resetPasswordToken',
'-resetPasswordTokenExpiryDate',
];

/**
* @returns All the {@link Student}s in the database.
*/
Expand All @@ -11,4 +27,18 @@ const getAllStudentsFromDB = async () => {
return studentList;
};

export { getAllStudentsFromDB };
/**
* Gets a student from the database by their id.
* @param id The id of the user to get.
* @returns The {@link Student} or null if the user was not found.
*/
const getStudentByID = async (id: string) => {
// const user = await Student.findById(id).select(removeSensitiveDataQuery).exec();
// return user;
const user = await Student.findOne({ id })
.select(removeSensitiveDataQuery)
.exec();
return user;
};

export { getAllStudentsFromDB, getStudentByID };

0 comments on commit 74cfd48

Please sign in to comment.