Skip to content

Commit

Permalink
Progress Notes Frontend & Backend (#102)
Browse files Browse the repository at this point in the history
* 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
aaronchan32 and adhi0331 authored May 21, 2024
1 parent 0b133b8 commit b8865a7
Show file tree
Hide file tree
Showing 76 changed files with 4,879 additions and 487 deletions.
161 changes: 161 additions & 0 deletions backend/src/controllers/progressNote.ts
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);
}
};
37 changes: 37 additions & 0 deletions backend/src/controllers/types/progressNoteTypes.ts
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;
};
7 changes: 7 additions & 0 deletions backend/src/controllers/types/types.ts
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;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Request } from "express";

import { UserId } from "./types";

export type CreateUserRequestBody = {
name: string;
accountType: "admin" | "team";
Expand All @@ -11,13 +13,7 @@ export type LoginUserRequestBody = {
uid: string;
};

type UserId = {
userId: string;
};

export type UserIdRequest = Request & UserId;

export type EditNameRequestBody = {
export type EditNameRequestBody = UserId & {
newName: string;
};

Expand All @@ -42,7 +38,6 @@ export type SaveImageRequest = {
};
};

export type EditPhotoRequest = Request &
UserId & {
rawBody?: Buffer;
};
export type EditPhotoRequestBody = Request<Record<string, never>, Record<string, never>, UserId> & {
rawBody?: Buffer;
};
Loading

0 comments on commit b8865a7

Please sign in to comment.