From the course: Databases for Node.js Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implement all database methods

Implement all database methods

From the course: Databases for Node.js Developers

Start my 1-month free trial

Implement all database methods

- [Tutor] After lots of preparation, we are finally ready to implement the service that is responsible for all the database logic for items. Put it I'm in server services, itemService. I start with first bring in the model that we created before. So add const itemModel equals require and it's one level up, models, mongoose and there. It's called item. Next let's start with implementing a class to class, should be named class ItemService. And in the end, just add module.exports equals itemService, so that we don't forget that. So itemService will just contain static methods. This means we will only call methods on the class itself and never on the instance. So I start with adding static async, maybe you remember, we need a getAll method that gives us all items that we have in the catalog. So here I now return, and that's really easy now with the model mongoose gives us ItemModel.find. And here I put in curly brackets,…

Contents