Here we are! It's time to implement our Teams Rest controller. To do this, we will start decoupling the Team model that has all the logic to communicate with the MongoDB database. Once the Team model is refactored, we will start implementing the code in the Team Rest Controller to implement the CRUD operations to do the following:
- List all the teams
- Create new teams
- Update the existing teams
- Delete teams
Let's get our hands dirty!
We have created a models
folder in the root project directory. In this folder, we will create all the models for our application. Start creating the team.js
file in the src
/models
folders:
$ touch src/models/team.js
Remember that we use the touch
command to create a new file. Then, open this file, and from the src/config/mongoose-connection.js
file, cut the following lines and copy them into the src/models/team.js
file, as follows:
const mongoose = require('mongoose') const TeamSchema = new mongoose.Schema({ ...