From 40122229ea8f46b9c011039d95ef11a50c072bff Mon Sep 17 00:00:00 2001 From: Joseph Zhang Date: Tue, 19 Dec 2023 18:09:03 -0500 Subject: [PATCH] Fixed --- client/src/Admin/AddDateNotesDialog.tsx | 70 +++++++++++++---- client/src/Admin/AdminNotesPage.tsx | 68 +++++++++++------ client/src/Admin/EditDateNotesDialog.tsx | 76 ++++++++++++++----- .../src/StudentProgress/ProgressSnapshot.tsx | 10 ++- client/src/StudentProgress/Updates.tsx | 6 +- server/src/controllers/student.controller.ts | 10 ++- server/src/models/student.model.ts | 22 +++++- server/src/routes/coach.route.ts | 3 +- server/src/services/student.service.ts | 22 ++++-- 9 files changed, 206 insertions(+), 81 deletions(-) diff --git a/client/src/Admin/AddDateNotesDialog.tsx b/client/src/Admin/AddDateNotesDialog.tsx index 43c52c7c..9118210a 100644 --- a/client/src/Admin/AddDateNotesDialog.tsx +++ b/client/src/Admin/AddDateNotesDialog.tsx @@ -20,8 +20,10 @@ import AlertType from '../util/types/alert'; interface IAdminNotesRow { key: string; date: string; - studentObservations: string; - studentNextSteps: string; + privateStudentObservations: string; + privateStudentNextSteps: string; + publicStudentObservations: string; + publicStudentNextSteps: string; coachObservations: string; coachNextSteps: string; } @@ -31,8 +33,10 @@ interface AddDateProps { setOpen: (newOpen: boolean) => void; addDate: ( date: number, - studentObservations: string, - studentNextSteps: string, + privateStudentObservations: string, + privateStudentNextSteps: string, + publicStudentObservations: string, + publicStudentNextSteps: string, coachObservations: string, coachNextSteps: string, ) => void; @@ -41,8 +45,12 @@ interface AddDateProps { function AddDateNotesDialog({ open, setOpen, addDate, table }: AddDateProps) { const [date, setDate] = useState(null); - const [studentObservations, setStudentObservations] = useState(''); - const [studentNextSteps, setStudentNextSteps] = useState(''); + const [privateStudentObservations, setPrivateStudentObservations] = + useState(''); + const [privateStudentNextSteps, setPrivateStudentNextSteps] = useState(''); + const [publicStudentObservations, setPublicStudentObservations] = + useState(''); + const [publicStudentNextSteps, setPublicStudentNextSteps] = useState(''); const [coachObservations, setCoachObservations] = useState(''); const [coachNextSteps, setCoachNextSteps] = useState(''); const [error, setError] = useState(false); @@ -73,14 +81,18 @@ function AddDateNotesDialog({ open, setOpen, addDate, table }: AddDateProps) { addDate( Number(date), - studentObservations, - studentNextSteps, + privateStudentObservations, + privateStudentNextSteps, + publicStudentObservations, + publicStudentNextSteps, coachObservations, coachNextSteps, ); setDate(null); - setStudentObservations(''); - setStudentNextSteps(''); + setPrivateStudentObservations(''); + setPrivateStudentNextSteps(''); + setPublicStudentObservations(''); + setPublicStudentNextSteps(''); setCoachObservations(''); setCoachNextSteps(''); setOpen(false); @@ -121,18 +133,44 @@ function AddDateNotesDialog({ open, setOpen, addDate, table }: AddDateProps) { setStudentObservations(event.target.value)} + label="Private Student Observations" + value={privateStudentObservations} + onChange={(event) => + setPrivateStudentObservations(event.target.value) + } /> setStudentNextSteps(event.target.value)} + label="Private Student Next Steps" + value={privateStudentNextSteps} + onChange={(event) => + setPrivateStudentNextSteps(event.target.value) + } + /> + + + + setPublicStudentObservations(event.target.value) + } + /> + + + + setPublicStudentNextSteps(event.target.value) + } /> diff --git a/client/src/Admin/AdminNotesPage.tsx b/client/src/Admin/AdminNotesPage.tsx index 65656e97..0a84b233 100644 --- a/client/src/Admin/AdminNotesPage.tsx +++ b/client/src/Admin/AdminNotesPage.tsx @@ -18,8 +18,10 @@ interface IAdminNotesTable { interface IAdminNotesRow { key: string; date: string; - studentObservations: string; - studentNextSteps: string; + privateStudentObservations: string; + privateStudentNextSteps: string; + publicStudentObservations: string; + publicStudentNextSteps: string; coachObservations: string; coachNextSteps: string; } @@ -45,10 +47,12 @@ function AdminSessionsPage() { const columns: TColumn[] = [ { id: 'date', label: 'Date' }, - { id: 'studentObservations', label: 'Student Observations' }, - { id: 'studentNextSteps', label: 'Student Next Steps' }, - { id: 'coachObservations', label: 'Coach Observations' }, - { id: 'coachNextSteps', label: 'Coach Next Steps' }, + { id: 'privateStudentObservations', label: 'Private Student Notes' }, + { id: 'privateStudentNextSteps', label: 'Private Student Next Steps' }, + { id: 'publicStudentObservations', label: 'Public Student Notes' }, + { id: 'publicStudentNextSteps', label: 'Public Student Next Steps' }, + { id: 'coachObservations', label: 'Private Coach Notes' }, + { id: 'coachNextSteps', label: 'Private Coach Next Steps' }, ]; async function getCoach(id: string) { @@ -72,9 +76,14 @@ function AdminSessionsPage() { useEffect(() => { const bigMap = new Map(); if (student) { - console.log(student.progress_stats); + const goodKeys = [ + 'private_student_next_steps', + 'private_student_observations', + 'public_student_next_steps', + 'public_student_observations', + ]; Object.entries(student.progress_stats).forEach(([key, innerMap]) => { - if (key === 'student_next_steps' || key === 'student_observations') { + if (goodKeys.includes(key)) { Object.entries(innerMap).forEach(([date, comments]) => { if (!bigMap.has(date)) { bigMap.set(date, {}); @@ -103,8 +112,10 @@ function AdminSessionsPage() { bigTable.push({ key: date.toString(), date: new Date(parseInt(date, 10)).toLocaleDateString(), - studentObservations: obj.student_observations || '', - studentNextSteps: obj.student_next_steps || '', + privateStudentObservations: obj.private_student_observations || '', + privateStudentNextSteps: obj.private_student_next_steps || '', + publicStudentObservations: obj.public_student_observations || '', + publicStudentNextSteps: obj.public_student_next_steps || '', coachObservations: obj.coach_observations || '', coachNextSteps: obj.coach_next_steps || '', }); @@ -116,16 +127,20 @@ function AdminSessionsPage() { function createAdminNotesRow( key: string, date: string, - studentObservations: string, - studentNextSteps: string, + privateStudentObservations: string, + privateStudentNextSteps: string, + publicStudentObservations: string, + publicStudentNextSteps: string, coachObservations: string, coachNextSteps: string, ): IAdminNotesRow { return { key, date, - studentObservations, - studentNextSteps, + privateStudentObservations, + privateStudentNextSteps, + publicStudentObservations, + publicStudentNextSteps, coachObservations, coachNextSteps, }; @@ -156,22 +171,25 @@ function AdminSessionsPage() { const addDate = async ( date: number, - studentObservations: string, - studentNextSteps: string, + privateStudentObservations: string, + privateStudentNextSteps: string, + publicStudentObservations: string, + publicStudentNextSteps: string, coachObservations: string, coachNextSteps: string, ) => { try { const studentComments = { date, - observations: studentObservations, - next_steps: studentNextSteps, + private_observations: privateStudentObservations, + private_next_steps: privateStudentNextSteps, + public_observations: publicStudentObservations, + public_next_steps: publicStudentNextSteps, }; putData( `student/progress/${student?._id}`, studentComments, ); /* eslint no-underscore-dangle: 0 */ - if (coach) { const coachComments = { date, @@ -187,8 +205,10 @@ function AdminSessionsPage() { const newData = { key: date.toString(), date: new Date(date).toLocaleDateString('en-US'), - studentObservations, - studentNextSteps, + privateStudentObservations, + privateStudentNextSteps, + publicStudentObservations, + publicStudentNextSteps, coachObservations, coachNextSteps, }; @@ -328,8 +348,10 @@ function AdminSessionsPage() { createAdminNotesRow( rowData.key, rowData.date, - rowData.studentObservations, - rowData.studentNextSteps, + rowData.privateStudentObservations, + rowData.privateStudentNextSteps, + rowData.publicStudentObservations, + rowData.publicStudentNextSteps, rowData.coachObservations, rowData.coachNextSteps, ), diff --git a/client/src/Admin/EditDateNotesDialog.tsx b/client/src/Admin/EditDateNotesDialog.tsx index 28367deb..85f26ea7 100644 --- a/client/src/Admin/EditDateNotesDialog.tsx +++ b/client/src/Admin/EditDateNotesDialog.tsx @@ -17,8 +17,10 @@ import AlertType from '../util/types/alert'; interface IAdminNotesRow { key: string; date: string; - studentObservations: string; - studentNextSteps: string; + privateStudentObservations: string; + privateStudentNextSteps: string; + publicStudentObservations: string; + publicStudentNextSteps: string; coachObservations: string; coachNextSteps: string; } @@ -29,8 +31,10 @@ interface EditDateDialogProps { options: number[]; editDate: ( date: number, - studentObservations: string, - studentNextSteps: string, + privateStudentObservations: string, + privateStudentNextSteps: string, + publicStudentObservations: string, + publicStudentNextSteps: string, coachObservations: string, coachNextSteps: string, ) => void; @@ -45,8 +49,12 @@ function EditDateDialog({ table, }: EditDateDialogProps) { const [date, setDate] = useState(null); - const [studentObservations, setStudentObservations] = useState(''); - const [studentNextSteps, setStudentNextSteps] = useState(''); + const [privateStudentObservations, setPrivateStudentObservations] = + useState(''); + const [privateStudentNextSteps, setPrivateStudentNextSteps] = useState(''); + const [publicStudentObservations, setPublicStudentObservations] = + useState(''); + const [publicStudentNextSteps, setPublicStudentNextSteps] = useState(''); const [coachObservations, setCoachObservations] = useState(''); const [coachNextSteps, setCoachNextSteps] = useState(''); const { setAlert } = useAlert(); @@ -56,8 +64,10 @@ function EditDateDialog({ const numberDate = Number(date).toString(); const row = table.find((r: IAdminNotesRow) => r.key === numberDate); if (row) { - setStudentObservations(row.studentObservations); - setStudentNextSteps(row.studentNextSteps); + setPrivateStudentObservations(row.privateStudentObservations); + setPrivateStudentNextSteps(row.privateStudentNextSteps); + setPublicStudentObservations(row.publicStudentObservations); + setPublicStudentNextSteps(row.publicStudentNextSteps); setCoachObservations(row.coachObservations); setCoachNextSteps(row.coachNextSteps); } @@ -70,14 +80,18 @@ function EditDateDialog({ } editDate( date, - studentObservations, - studentNextSteps, + privateStudentObservations, + privateStudentNextSteps, + publicStudentObservations, + publicStudentNextSteps, coachObservations, coachNextSteps, ); setDate(null); - setStudentObservations(''); - setStudentNextSteps(''); + setPrivateStudentObservations(''); + setPrivateStudentNextSteps(''); + setPublicStudentObservations(''); + setPublicStudentNextSteps(''); setCoachObservations(''); setCoachNextSteps(''); setOpen(false); @@ -120,18 +134,44 @@ function EditDateDialog({ setStudentObservations(event.target.value)} + label="Private Student Observations" + value={privateStudentObservations} + onChange={(event) => + setPrivateStudentObservations(event.target.value) + } /> setStudentNextSteps(event.target.value)} + label="Private Student Next Steps" + value={privateStudentNextSteps} + onChange={(event) => + setPrivateStudentNextSteps(event.target.value) + } + /> + + + + setPublicStudentObservations(event.target.value) + } + /> + + + + setPublicStudentNextSteps(event.target.value) + } /> diff --git a/client/src/StudentProgress/ProgressSnapshot.tsx b/client/src/StudentProgress/ProgressSnapshot.tsx index f9bb2f1c..65833ff2 100644 --- a/client/src/StudentProgress/ProgressSnapshot.tsx +++ b/client/src/StudentProgress/ProgressSnapshot.tsx @@ -17,8 +17,10 @@ interface IStudent extends mongoose.Document { coach_additional_resources: [string]; progress_stats: { attendance: Map; - student_next_steps: Map; - student_observations: Map; + private_student_next_steps: Map; + private_student_observations: Map; + public_student_next_steps: Map; + public_student_observations: Map; }; parent_name: string; parent_communication_days: string; @@ -54,12 +56,12 @@ export default function ProgressSnapshot({ studentId }: { studentId: string }) { useEffect(() => { if (student && student.progress_stats) { const observationsMap = new Map( - Object.entries(student.progress_stats.student_observations).map( + Object.entries(student.progress_stats.public_student_observations).map( ([key, value]) => [Number(key), value], ), ); const nextStepsMap = new Map( - Object.entries(student.progress_stats.student_next_steps).map( + Object.entries(student.progress_stats.public_student_next_steps).map( ([key, value]) => [Number(key), value], ), ); diff --git a/client/src/StudentProgress/Updates.tsx b/client/src/StudentProgress/Updates.tsx index a1937d2c..ce235d81 100644 --- a/client/src/StudentProgress/Updates.tsx +++ b/client/src/StudentProgress/Updates.tsx @@ -16,8 +16,10 @@ interface IStudent extends mongoose.Document { coach_additional_resources: [string]; progress_stats: { attendance: Map; - student_next_steps: Map; - student_observations: Map; + private_student_next_steps: Map; + private_student_observations: Map; + public_student_next_steps: Map; + public_student_observations: Map; }; parent_name: string; parent_communication_days: string; diff --git a/server/src/controllers/student.controller.ts b/server/src/controllers/student.controller.ts index 7371db23..d4380200 100644 --- a/server/src/controllers/student.controller.ts +++ b/server/src/controllers/student.controller.ts @@ -54,11 +54,13 @@ const updateProgress = async ( if (!date) { next(ApiError.missingFields(['date'])); } - const { observations } = req.body || ''; - const { next_steps } = req.body || ''; + const { public_observations } = req.body || ''; + const { public_next_steps } = req.body || ''; + const { private_observations } = req.body || ''; + const { private_next_steps } = req.body || ''; - const coach = await updateProgressDate(id, date, observations, next_steps); - res.status(StatusCode.OK).send(coach); + const student = await updateProgressDate(id, date, public_observations, public_next_steps, private_observations, private_next_steps); + res.status(StatusCode.OK).send(student); }; const deleteProgress = async ( diff --git a/server/src/models/student.model.ts b/server/src/models/student.model.ts index 6de2f571..e70a7cc0 100644 --- a/server/src/models/student.model.ts +++ b/server/src/models/student.model.ts @@ -45,13 +45,25 @@ const StudentSchema = new mongoose.Schema({ required: false, default: {}, }, - student_next_steps: { + private_student_observations: { type: Map, of: String, required: false, default: {}, }, - student_observations: { + private_student_next_steps: { + type: Map, + of: String, + required: false, + default: {}, + }, + public_student_observations: { + type: Map, + of: String, + required: false, + default: {}, + }, + public_student_next_steps: { type: Map, of: String, required: false, @@ -173,8 +185,10 @@ interface IStudent extends mongoose.Document { coach_additional_resources: string[]; progress_stats: { attendance: Map; - student_next_steps: Map; - student_observations: Map; + private_student_next_steps: Map; + private_student_observations: Map; + public_student_next_steps: Map; + public_student_observations: Map; }; parent_name: string; parent_communication_days: string; diff --git a/server/src/routes/coach.route.ts b/server/src/routes/coach.route.ts index 9a757f86..7a48357d 100644 --- a/server/src/routes/coach.route.ts +++ b/server/src/routes/coach.route.ts @@ -59,10 +59,9 @@ coachRouter.get( coachRouter.delete( '/progress/:id/:date', isAuthenticated, - isCoach, deleteProgress, ); -coachRouter.put('/progress/:id', isAuthenticated, isCoach, updateProgress); +coachRouter.put('/progress/:id', isAuthenticated, updateProgress); coachRouter.get('/resources/:id', isAuthenticated, getAllCoachResources); coachRouter.get('/user/:id', isAuthenticated, getCoachByUserId); diff --git a/server/src/services/student.service.ts b/server/src/services/student.service.ts index 5260df3b..af7ee22b 100644 --- a/server/src/services/student.service.ts +++ b/server/src/services/student.service.ts @@ -264,22 +264,26 @@ const addCoachToStudent = async (student_id: string, coach_id: string) => { const updateProgressDate = async ( id: string, date: string, - observations: string, - next_steps: string, + public_observations: string, + public_next_steps: string, + private_observations: string, + private_next_steps: string ) => { - const coach = await Student.findOneAndUpdate( + const student = await Student.findOneAndUpdate( { _id: id, }, { $set: { - [`progress_stats.student_observations.${date}`]: observations, - [`progress_stats.student_next_steps.${date}`]: next_steps, + [`progress_stats.public_student_observations.${date}`]: public_observations, + [`progress_stats.public_student_next_steps.${date}`]: public_next_steps, + [`progress_stats.private_student_observations.${date}`]: private_observations, + [`progress_stats.private_student_next_steps.${date}`]: private_next_steps, }, }, { new: true }, ).exec(); - return coach; + return student; }; const deleteProgressDate = async (id: string, date: string) => { @@ -289,8 +293,10 @@ const deleteProgressDate = async (id: string, date: string) => { }, { $unset: { - [`progress_stats.student_observations.${date}`]: '', - [`progress_stats.student_next_steps.${date}`]: '', + [`progress_stats.public_student_observations.${date}`]: '', + [`progress_stats.public_student_next_steps.${date}`]: '', + [`progress_stats.private_student_observations.${date}`]: '', + [`progress_stats.private_student_next_steps.${date}`]: '', }, }, { new: true },