-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
project-mongo-api -Books - Kathinka #483
base: master
Are you sure you want to change the base?
Conversation
…, updated error messages, rewrote the endpoints to use async/await
…D , with adding CUD to the functionality
…th create, update, and delete operations
…ameters function to pagination.js and used it where it seemed to be handy in selected routes.
… the server will restart on its own if an unhandledRejection or uncaughtException shuts down my server
…ibility with Babel
… before deploy anymore
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.
Hello Kathinka, your code looks well-structured and organised, you pushed yourself creating many endpoints and they all work well. The api meets the requirements and also goes beyond using solutions not even suggested in our course material, impressive! ⭐
|
||
// Define the schema for the Book model | ||
const BookSchema = new Schema({ | ||
bookID: Number, |
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.
You can remove bookId
from the Schema: Mongoose automatically assigns a unique _id
field to each document, so you don't need to define the field in your schema, you can even remove it from the data object :)
class ValidationError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "ValidationError"; | ||
this.status = 400; | ||
} | ||
} | ||
|
||
class NotFoundError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "NotFoundError"; | ||
this.status = 404; | ||
} | ||
} |
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.
custom error classes is a great way to handle specific error types in your application and keep the code DRY!
Netlify link
view it here
(nb: ignore dist folder)