Controllers

Now that we have the models and routes, let's look at the controllers that process the API request. All the controllers are placed inside servercontrollers folder.  All the controllers that we have created so far extend (https://www.typescriptlang.org/docs/handbook/classes.html) from the BaseCtrl. BaseCtrl implements all the basic CRUD operations for a model. These operations include:

  •  getAll: Get all documents in a collection
  • count: Count of all documents in that collection
  • insert: Create a new document in that collection
  • get: Get a document by its _id
  • update: Update a document
  • delete: Delete a document by its _id

If we look at servercontrollersuser.ts, it extends BaseCtrl and then defines, the model as User. Apart from that, we have created a method of our own named login that can authenticate a user and respond accordingly. If the login is successful, we will send the user object along with a JWT; otherwise, we send back a 403 forbidden message. This concludes our walk-through of the server side code. Now lets look at the client side code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.134.154