Skip to content

Commit

Permalink
Bugfix/finalchanges (#111)
Browse files Browse the repository at this point in the history
* basic implementation

* completed UI

* basic backend connection

* view calendar

* preliminary calendar complete

* fixed issue with program enrollment

* remove unnecssary logs

* fix student form requirements

* add incident form to student profile

* fix medication field in student profile

* fix enrollments

* fix build

* add log messages to see deployment

* change cards to UTC date
  • Loading branch information
adhi0331 authored Feb 3, 2025
1 parent ca89496 commit 4f5d30a
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 165 deletions.
5 changes: 4 additions & 1 deletion backend/src/controllers/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export const getAllStudents: RequestHandler = async (req, res, next) => {
// Ensure that documents that are marked admin are not returned to non-admin users
if (accountType !== "admin") {
students.forEach((student) => {
if (!student.documents) {
return;
}
student.documents = student.documents.filter(
(doc) => !doc.markedAdmin,
) as typeof student.documents;
Expand Down Expand Up @@ -155,7 +158,7 @@ export const getStudent: RequestHandler = async (req, res, next) => {
}

// Ensure that documents that are marked admin are not returned to non-admin users
if (accountType !== "admin") {
if (studentData.documents && accountType !== "admin") {
studentData.documents = studentData.documents.filter(
(doc) => !doc.markedAdmin,
) as typeof studentData.documents;
Expand Down
7 changes: 4 additions & 3 deletions backend/src/models/enrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ const enrollmentSchema = new mongoose.Schema({
schedule: { type: [String], required: true },
sessionTime: {
type: {
start_time: { type: String, required: true },
end_time: { type: String, required: true },
start_time: { type: String, required: false, default: "00:00" },
end_time: { type: String, required: false, default: "00:00" },
},
required: true,
required: false,
default: { start_time: "00:00", end_time: "00:00" },
},
startDate: { type: Date, required: true },
renewalDate: { type: Date, required: true },
Expand Down
41 changes: 21 additions & 20 deletions backend/src/models/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ const studentSchema = new Schema({
student: {
lastName: { type: String, required: true },
firstName: { type: String, required: true },
email: { type: String, required: true },
phoneNumber: { type: String, required: true },
email: { type: String, required: false, default: "" },
phoneNumber: { type: String, required: false, default: "" },
},

emergency: {
lastName: { type: String, required: true },
firstName: { type: String, required: true },
email: { type: String, required: true },
phoneNumber: { type: String, required: true },
lastName: { type: String, required: false, default: "" },
firstName: { type: String, required: false, default: "" },
email: { type: String, required: false, default: "" },
phoneNumber: { type: String, required: false, default: "" },
},

serviceCoordinator: {
lastName: { type: String, required: true },
firstName: { type: String, required: true },
email: { type: String, required: true },
phoneNumber: { type: String, required: true },
lastName: { type: String, required: false, default: "" },
firstName: { type: String, required: false, default: "" },
email: { type: String, required: false, default: "" },
phoneNumber: { type: String, required: false, default: "" },
},

enrollments: {
Expand All @@ -33,18 +33,18 @@ const studentSchema = new Schema({
},

//Address of student
location: { type: String, required: true },
location: { type: String, required: false, default: "" },

//String list of medications
medication: { type: String, required: true },
medication: { type: String, required: false, default: "" },

birthday: { type: Date, required: true },
intakeDate: { type: Date, required: true },
tourDate: { type: Date, required: true },
birthday: { type: Date, required: false, default: null },
intakeDate: { type: Date, required: false, default: null },
tourDate: { type: Date, required: false, default: null },

conservation: { type: Boolean, required: true },
UCINumber: { type: String, required: true },
incidentForm: { type: String, required: true },
conservation: { type: Boolean, required: false, default: false },
UCINumber: { type: String, required: false, default: "" },
incidentForm: { type: String, required: false, default: "" },
documents: {
type: [
{
Expand All @@ -53,7 +53,8 @@ const studentSchema = new Schema({
markedAdmin: { type: Boolean, required: true, default: false },
},
],
required: true,
required: false,
default: [],
},
profilePicture: { type: String, ref: "Image", required: false, default: "default" },

Expand All @@ -65,7 +66,7 @@ const studentSchema = new Schema({
},

//Will contain list of all dietary restrictions
dietary: { type: [String] },
dietary: { type: [String], required: false, default: [] },
});

type Student = InferSchemaType<typeof studentSchema>;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/util/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const programValidatorUtil = async (enrollments: Enrollment[]) => {
"status",
"hoursLeft",
"schedule",
"sessionTime",
"startDate",
"renewalDate",
"authNumber",
];

enrollments.forEach((enrollment: Enrollment) => {
requiredFields.forEach((field) => {
if (!enrollment[field as keyof Enrollment])
Expand Down
107 changes: 41 additions & 66 deletions backend/src/validators/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { programValidatorUtil } from "../util/student";

//designed these to use the globstar operator from express-validator to more cleanly

const isValidDateTimeString = (value: string) => {
return !isNaN(Date.parse(value));
};

const makeIdValidator = () =>
body("**._id")
.exists()
Expand Down Expand Up @@ -63,76 +67,59 @@ const makePhoneNumbersValidator = () =>

//validate location
const makeLocationValidator = () =>
body("location")
.exists()
.withMessage("Location field fequired")
.bail()
.isString()
.withMessage("Location must be a string")
.bail()
.notEmpty()
.withMessage("Location field required");
body("location").optional().isString().withMessage("Location must be a string").bail();

//medication
const makeMedicationValidator = () =>
body("medication")
.exists()
.withMessage("Medication field required")
.bail()
.isString()
.withMessage("Medication must be a string")
.bail()
.notEmpty()
.withMessage("Medication field required");
body("medication").optional().isString().withMessage("Medication must be a string").bail();

//birthday
const makeBirthdayValidator = () =>
body("birthday")
.exists()
.withMessage("Birthday field required")
.bail()
.isISO8601()
.toDate()
.withMessage("Birthday string must be a valid date-time string");
.custom((value) => {
if (!value) {
return true;
}
if (!isValidDateTimeString(value as string)) {
throw new Error("Intake Date string must be a valid date-time string");
}
return true;
})
.toDate();

//intake date
const makeIntakeDateValidator = () =>
body("intakeDate")
.exists()
.withMessage("Intake Date field required")
.bail()
.isISO8601()
.toDate()
.withMessage("Intake Date string must be a valid date-time string");
.custom((value) => {
if (!value) {
return true;
}
if (!isValidDateTimeString(value as string)) {
throw new Error("Intake Date string must be a valid date-time string");
}
return true;
})
.toDate();

//tour date
const makeTourDateValidator = () =>
body("tourDate")
.exists()
.withMessage("Tour Date field required")
.bail()
.isISO8601()
.toDate()
.withMessage("Tour Date string must be a valid date-time string");
.custom((value) => {
if (!value) {
return true;
}
if (!isValidDateTimeString(value as string)) {
throw new Error("Intake Date string must be a valid date-time string");
}
return true;
})
.toDate();

const makeConservationValidator = () =>
body("conservation")
.exists()
.withMessage("Conservation field required")
.bail()
.isBoolean()
.withMessage("Conservation must be a boolean");
body("conservation").optional().isBoolean().withMessage("Conservation must be a boolean");

const makeUCINumberValidator = () =>
body("UCINumber")
.exists()
.withMessage("UCI Number field required")
.bail()
.isString()
.withMessage("UCI Number must be a string")
.bail()
.notEmpty()
.withMessage("UCI Number field required");
body("UCINumber").optional().isString().withMessage("UCI Number must be a string").bail();

type DocumentItem = {
name: string;
Expand All @@ -141,21 +128,11 @@ type DocumentItem = {
};

const makeIncidentFormValidator = () =>
body("incidentForm")
.exists()
.withMessage("Incident Form field required")
.bail()
.isString()
.withMessage("Incident Form must be a string")
.bail()
.notEmpty()
.withMessage("Incident Form field required");
body("incidentForm").optional().isString().withMessage("Incident Form must be a string").bail();

const makeDocumentsValidator = () =>
body("documents")
.exists()
.withMessage("Documents field required")
.bail()
.optional()
.isArray()
.withMessage("Documents must be an array")
.bail()
Expand Down Expand Up @@ -187,9 +164,7 @@ const makeProfilePictureValidator = () =>

const makeEnrollments = () =>
body("enrollments")
.exists()
.withMessage("Enrollments field required")
.bail()
.optional()
.isArray()
.withMessage("Enrollments must be a non-empty array")
.bail()
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/AttendanceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function AttendanceTable({
const _errors = errors;

const dateObj = new Date(session.date.toString());
console.log(session.date.toString());
console.log(dateObj);
console.log(dateObj.getDay());

const daysOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const monthsOfYear = [
"Jan",
Expand Down Expand Up @@ -136,7 +140,7 @@ export function AttendanceTable({
</h1>
<h1 className="ml-5 mt-1 text-gray-400">
{daysOfWeek[dateObj.getUTCDay()]}, {monthsOfYear[dateObj.getMonth()]}{" "}
{dateObj.getDate()}{" "}
{dateObj.getUTCDate()}{" "}
{program.type === "regular" &&
"from " + session.sessionTime.start_time + "to " + session.sessionTime.end_time}
</h1>
Expand Down
Loading

0 comments on commit 4f5d30a

Please sign in to comment.