-
Notifications
You must be signed in to change notification settings - Fork 0
Course and Course Item API Rewrite #19
base: DatabaseAPIRewrite
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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!
src/operations/course.ts
Outdated
if (!course) { | ||
throw new Error('Course not found'); | ||
} |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this 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).
src/operations/course.ts
Outdated
} catch (e) { | ||
throw new Error('Course not found'); | ||
} | ||
}; |
There was a problem hiding this comment.
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
src/operations/course.ts
Outdated
if (!course) { | ||
throw new Error('Course not found'); | ||
} |
There was a problem hiding this comment.
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
src/operations/course.ts
Outdated
if (!courses) { | ||
throw new Error('Courses not found'); | ||
} |
There was a problem hiding this comment.
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.
src/operations/course.ts
Outdated
export const getCoursesByOwnerId = async ( | ||
ownerId: string | ||
): Promise<Course[]> => { |
There was a problem hiding this comment.
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.
src/operations/course.ts
Outdated
} | ||
}; | ||
|
||
export const getCoursesByOwnerId = async ( |
There was a problem hiding this comment.
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
src/operations/course.ts
Outdated
return db.course.create({ data: course }); | ||
}; | ||
|
||
export const getCourseById = async ( |
There was a problem hiding this comment.
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
src/operations/courseItem.ts
Outdated
return db.courseItem.create({ data: courseItem }); | ||
}; | ||
|
||
export const getCourseItemById = async ( |
There was a problem hiding this comment.
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.
src/operations/courseItem.ts
Outdated
}; | ||
|
||
export const getCourseItemsByOwnerId = async ( | ||
ownerId: string |
There was a problem hiding this comment.
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
No description provided.