Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Course and Course Item API Rewrite #19

Open
wants to merge 3 commits into
base: DatabaseAPIRewrite
Choose a base branch
from

Conversation

seiyaterada
Copy link
Contributor

No description provided.

Copy link
Contributor

@isaiahdoyle isaiahdoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!! i had to comment something, so i made a small nitpick in the getById function. feel free to ignore, great job regardless!

Comment on lines 17 to 19
if (!course) {
throw new Error('Course not found');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be removed if we were to instead use findFirstOrThrow? it sounds like then an error would be automatically thrown if the course isn't found. but this totally works!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what Isaiah says here about findFirstOrThrow might be a good choice since that is all we are doing with our check anyways

Copy link
Contributor

@BraidenCutforth BraidenCutforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some comments I made that can be repeated like changing getXById to getX and so on, the usage of the getFirstOrThrow and so on, and the result of findMany possibly never being falsey (so no null check might be needed).

} catch (e) {
throw new Error('Course not found');
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline at end of file

Comment on lines 17 to 19
if (!course) {
throw new Error('Course not found');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what Isaiah says here about findFirstOrThrow might be a good choice since that is all we are doing with our check anyways

Comment on lines 31 to 33
if (!courses) {
throw new Error('Courses not found');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check needed? My understanding of the docs is that findMany will always return a list, but this list will be empty if nothing is found.

Comment on lines 26 to 28
export const getCoursesByOwnerId = async (
ownerId: string
): Promise<Course[]> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add an optional parameter here, the semesterId. I think the API will use it always but we can make it optional to make our database operations more versatile.

}
};

export const getCoursesByOwnerId = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably rename this getCourses

return db.course.create({ data: course });
};

export const getCourseById = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably rename this getCourse and similar for all fns

return db.courseItem.create({ data: courseItem });
};

export const getCourseItemById = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar rename for the functions in this file.

};

export const getCourseItemsByOwnerId = async (
ownerId: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the optional parameter courseId

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants