Skip to content

Commit

Permalink
fix planned course sections not appearing
Browse files Browse the repository at this point in the history
  • Loading branch information
jxjj committed Sep 16, 2024
1 parent 2718a75 commit 6a1d53e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
3 changes: 2 additions & 1 deletion app/Contracts/EnrollmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
interface EnrollmentInterface {
public function getApiId(): string;
public function getDBId(): int | null;
public function getEmplid(): string;
public function getEmplid(): int;
public function getSectionApiId(): string;
public function getSectionDBId(): int | null;
public function getRole(): string;
public function getSource(): string;
}
7 changes: 6 additions & 1 deletion app/DTOs/SISEnrollmentDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getDBId(): ?int
return null;
}

public function getEmplid(): string
public function getEmplid(): int
{
return $this->emplid;
}
Expand All @@ -71,4 +71,9 @@ public function getSource(): string
{
return 'sis';
}

public function getSectionDBId(): ?int
{
return null;
}
}
7 changes: 6 additions & 1 deletion app/Enrollment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getDBId(): ?int
return $this->id;
}

public function getEmplid(): string
public function getEmplid(): int
{
return $this->user->emplid;
}
Expand All @@ -57,4 +57,9 @@ public function getSource(): string
{
return 'local';
}

public function getSectionDBId(): ?int
{
return $this->courseSection->id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function store(Request $request, Group $group) {
// create new section
$section = $group->courseSections()->create($validated);

$section->refresh();

return new CourseSectionResource($section);
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/EnrollmentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function toArray($request) {
'dbId' => $enrollment->getDBId(),
'emplid' => $enrollment->getEmplid(),
'sectionId' => $enrollment->getSectionApiId(),
'sectionDbId' => $enrollment->getSectionDBId(),
'role' => $enrollment->getRole(),
'source' => $enrollment->getSource(),
];
Expand Down
14 changes: 1 addition & 13 deletions resources/js/api/coursePlanningApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,14 @@ export async function deleteEnrollmentFromGroup(
return res.data;
}

function parseDbIdFromSectionId(sectionId: T.Enrollment["sectionId"]) {
// enrollment id is in the form: db-1234
const [source, dbId] = sectionId.split("-");

if (source !== "db") {
throw new Error(`Section id ${sectionId} does not have a dbId`);
}
return dbId;
}

export async function updateEnrollmentInGroup(
enrollment: T.Enrollment,
groupId: T.Group["id"],
) {
const sectionDbId = parseDbIdFromSectionId(enrollment.sectionId);

const res = await axios.put<T.Enrollment>(
`/api/course-planning/groups/${groupId}/enrollments/${enrollment.dbId}`,
{
course_section_id: sectionDbId,
course_section_id: enrollment.sectionDbId,
emplid: enrollment.emplid,
role: enrollment.role,
},
Expand Down
28 changes: 9 additions & 19 deletions resources/js/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,12 @@ export interface Person {
sslApplyEligible: boolean;
}

/**
* a person in a course section with a particular role
* like "primary instructor" or "teaching assistant"
*/

type DBEnrollmentId = `db-${NonNullable<Enrollment["dbId"]>}`;
type SISEnrollmentId = `sis-${NonNullable<
Enrollment["sectionId"]
>}-${NonNullable<Enrollment["emplid"]>}`;

export interface Enrollment {
id: DBEnrollmentId | SISEnrollmentId;
id: `${Person["emplid"]}_${CourseSection["id"]}`;
dbId: number | null;
emplid: Person["emplid"];
sectionId: CourseSection["id"];
sectionDbId: CourseSection["dbId"];
role: EnrollmentRole;
}

Expand All @@ -272,14 +263,8 @@ export interface AcademicDepartment {
abbreviation: string;
}

// these courses come from the bandaid api and are all considered published
export type SISSectionId = `sis-${NonNullable<CourseSection["classNumber"]>}`;

// these courses come from the app db and are likely unpublished
export type DbSectionId = `db-${NonNullable<CourseSection["dbId"]>}`;

export interface CourseSection {
id: SISSectionId | DbSectionId;
id: `${Course["id"]}-${CourseSection["classSection"]}-${Term["id"]}`;
classNumber: ApiCourseSectionRecord["classNumber"];
dbId: ApiCourseSectionRecord["dbId"];
courseId: Course["id"]; // short code like "HIST-1001W"
Expand All @@ -292,6 +277,7 @@ export interface CourseSection {
isCancelled: boolean;
isPublished: boolean; // true if from bandaid, false if from app DB
groupId: Group["id"];
source: "sis" | "local";
}

export interface CourseSectionWithEnrollments extends CourseSection {
Expand All @@ -311,8 +297,11 @@ export interface Course {
source: "sis" | "local";
}

type CourseSectionId =
`${Course["id"]}-${CourseSection["classSection"]}-${Term["id"]}`;

export interface ApiCourseSectionRecord {
id: SISSectionId | DbSectionId;
id: CourseSectionId;
classNumber: number | null; // null if from db
dbId: number | null; // null if from sis (bandaid)
termId: number;
Expand Down Expand Up @@ -394,6 +383,7 @@ export interface SerializedCoursePlanningFilters {
excludedAcadAppts: string[];
minSectionEnrollment: number;
includedEnrollmentRoles: EnrollmentRole[];
onlyActiveAppointments: boolean;
search: string;
inPlanningMode: boolean;
}
Expand Down

0 comments on commit 6a1d53e

Please sign in to comment.