-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress Notes Frontend & Backend (#102)
* feat: add create program notes backend * fix: THead unique key prop warning * feat: add edited by field to notes * fix: fix styling issues * feat: add edit and delete functionality to progress notes and change userId to uid for backend * fix: fix calendar styling * feat: add download progress notes functionality using react-pdf * feat: add mobile responsiveness * feat: create program context provider shared across Home, Programs, and Notes page * fix: fix styling to be consistent across pages * feat: add progress note filtering and add loading spinner to pages * feat: add account type authorization checks on frontend and backend * refactor: refactor notes logic and fix styling * feat: add logic to check for no students and refactor filter * feat: add shadows using overflow clip * fix: fix styling for search filter * fix: fix small style inconsistencies * fix: update poppins font url to use https * fix: fix modal close button styling to be more consistent * fix: fix escape key overriding dialog close * Squashed commit of the following: commit 0b133b8 Author: Michael Sullivan <[email protected]> Date: Tue May 14 09:09:16 2024 -0700 Feature/mraysu/program form v2 (#100) * Update Backend Program Schema * V2 UI * Disabled Editing Program Type * Frontend-backend integration * Lint fixes --------- Co-authored-by: mraysu <[email protected]> Co-authored-by: Adhithya Ananthan <[email protected]> commit e17b509 Author: parth4apple <[email protected]> Date: Tue May 14 09:01:15 2024 -0700 Student and Enrollment Schema modifications (#101) * feat: initial schema * feat: edit routes * feat: test and fix routes --------- Co-authored-by: Adhithya Ananthan <[email protected]>
- Loading branch information
1 parent
0b133b8
commit b8865a7
Showing
76 changed files
with
4,879 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { validationResult } from "express-validator"; | ||
|
||
import { ValidationError } from "../errors"; | ||
import ProgressNote from "../models/progressNote"; | ||
import StudentModel from "../models/student"; | ||
import UserModel from "../models/user"; | ||
import validationErrorParser from "../util/validationErrorParser"; | ||
|
||
import { | ||
CreateProgressNoteRequestBody, | ||
DeleteProgressNoteRequestBody, | ||
EditProgressNoteRequestBody, | ||
ExistingProgressNoteType, | ||
ProgressNoteType, | ||
} from "./types/progressNoteTypes"; | ||
import { LoginUserRequestBody } from "./types/userTypes"; | ||
|
||
export const createProgressNote = async ( | ||
req: Request<Record<string, never>, Record<string, never>, CreateProgressNoteRequestBody>, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
try { | ||
const { uid, studentId } = req.body; | ||
|
||
const user = await UserModel.findById(uid); | ||
if (!user) { | ||
throw ValidationError.USER_NOT_FOUND; | ||
} | ||
|
||
const student = await StudentModel.findById(studentId); | ||
if (!student) { | ||
throw ValidationError.STUDENT_NOT_FOUND; | ||
} | ||
|
||
const errors = validationResult(req); | ||
validationErrorParser(errors); | ||
|
||
const newProgressNote = { | ||
...req.body, | ||
lastEditedBy: user.name, | ||
userId: uid, | ||
} as ProgressNoteType; | ||
|
||
const createdProgressNote = await ProgressNote.create(newProgressNote); | ||
|
||
// Add the progress note to the student | ||
await StudentModel.findOneAndUpdate( | ||
{ _id: newProgressNote.studentId }, | ||
{ $push: { progressNotes: createdProgressNote._id } }, | ||
); | ||
|
||
res.status(201).json(createdProgressNote); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const editProgressNote = async ( | ||
req: Request<Record<string, never>, Record<string, never>, EditProgressNoteRequestBody>, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
try { | ||
const { uid } = req.body; | ||
|
||
const user = await UserModel.findById(uid); | ||
if (!user) { | ||
throw ValidationError.USER_NOT_FOUND; | ||
} | ||
|
||
if (user.accountType !== "admin") { | ||
throw ValidationError.UNAUTHORIZED_USER; | ||
} | ||
|
||
const errors = validationResult(req); | ||
validationErrorParser(errors); | ||
|
||
const newProgressNote = { | ||
...req.body, | ||
lastEditedBy: user.name, | ||
userId: uid, | ||
} as ExistingProgressNoteType; | ||
|
||
const editedProgressNote = await ProgressNote.findOneAndUpdate( | ||
{ _id: newProgressNote._id }, | ||
newProgressNote, | ||
{ new: true }, //returns updated document | ||
); | ||
|
||
if (!editedProgressNote) { | ||
throw ValidationError.PROGRESS_NOTE_NOT_FOUND; | ||
} | ||
|
||
res.status(200).json(editedProgressNote); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const deleteProgressNote = async ( | ||
req: Request<Record<string, never>, Record<string, never>, DeleteProgressNoteRequestBody>, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
try { | ||
const { noteId, studentId, uid } = req.body; | ||
|
||
const user = await UserModel.findById(uid); | ||
if (!user) { | ||
throw ValidationError.USER_NOT_FOUND; | ||
} | ||
|
||
if (user.accountType !== "admin") { | ||
throw ValidationError.UNAUTHORIZED_USER; | ||
} | ||
|
||
const errors = validationResult(req); | ||
validationErrorParser(errors); | ||
|
||
const deletedProgressNote = await ProgressNote.findOneAndDelete({ _id: noteId }); | ||
|
||
if (!deletedProgressNote) { | ||
throw ValidationError.PROGRESS_NOTE_NOT_FOUND; | ||
} | ||
|
||
const student = await StudentModel.findOneAndUpdate( | ||
{ _id: studentId }, | ||
{ $pull: { progressNotes: noteId } }, | ||
); | ||
|
||
if (!student) { | ||
throw ValidationError.STUDENT_NOT_FOUND; | ||
} | ||
|
||
res.status(200).json(deletedProgressNote); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const getAllProgressNotes = async ( | ||
req: Request<Record<string, never>, Record<string, never>, LoginUserRequestBody>, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
try { | ||
const { uid } = req.body; | ||
const user = await UserModel.findById(uid); | ||
if (!user) { | ||
throw ValidationError.USER_NOT_FOUND; | ||
} | ||
|
||
const allNotes = await ProgressNote.find(); | ||
|
||
res.status(200).json(allNotes); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Schema } from "mongoose"; | ||
|
||
export type ProgressNoteType = { | ||
studentId: Schema.Types.ObjectId; | ||
userId: string; | ||
lastEditedBy: string; | ||
dateLastUpdated: Date; | ||
content: string; | ||
}; | ||
|
||
export type ExistingProgressNoteType = { | ||
_id: Schema.Types.ObjectId; | ||
userId: string; | ||
lastEditedBy: string; | ||
dateLastUpdated: Date; | ||
content: string; | ||
}; | ||
|
||
export type CreateProgressNoteRequestBody = { | ||
studentId: Schema.Types.ObjectId; | ||
uid: string; | ||
dateLastUpdated: Date; | ||
content: string; | ||
}; | ||
|
||
export type EditProgressNoteRequestBody = { | ||
_id: Schema.Types.ObjectId; | ||
uid: string; | ||
dateLastUpdated: Date; | ||
content: string; | ||
}; | ||
|
||
export type DeleteProgressNoteRequestBody = { | ||
uid: string; | ||
noteId: Schema.Types.ObjectId; | ||
studentId: Schema.Types.ObjectId; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Request } from "express"; | ||
|
||
export type UserId = { | ||
uid: string; | ||
}; | ||
|
||
export type UserIdRequestBody = Request & UserId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.