module:BaseController(Model)

new module:BaseController(Model)

Controllers Common Object. Controller Objects could extends this Abstract Object Controller (\Controllers\BaseController) wich means that Controller Object will must be interact with some Object Model, so, this Abstract Object Controller handles with basics CRUD Controller methods aside Model Objects for us. Specific Controller operation shouldnt be implemented here.
Parameters:
Name Type Description
Model object Model Object(eg.: \models\StudentModel\).

Members

Model

This property its contains the Model Methods(eg.: Model().persist() -> save data on mongodb)
Properties:
Name Type Description
Model object Database Collection Object (eg.: \models\StudentModel\)

Methods

inner getById(req, res) → {json}

Generic GetById Method. Responds to GET /{GenericResource}/. Simple query this.Model by id. If Success returns 200 status code and a json with this.Model data. If error return 400 status code and a json => { errors }. 500 status code only will be returned if the method generates some unexpected error.
Parameters:
Name Type Description
req object Express requisition object.
res object Express response object.
Returns:
json - status and return object.
To Do:
  • Write comments

inner removeById(req, res) → {json}

Generic RemoveById Method. Responds to DELETE /{GenericResource}/. Simple delete this.Model by id. If Success returns 200 status code and a json with this.Model number of rows affected. If error return 400 status code and a json => { errors }. 500 status code only will be returned if the method generates some unexpected error.
Parameters:
Name Type Description
req object Express requisition object.
res object Express response object.
Returns:
json - status and return object.
To Do:
  • Write comments

inner removeByIdList(list) → {json}

Remove list of model IDs
Parameters:
Name Type Description
list Array
Returns:
json - status and deleted number of rows as result.

inner save(req, res) → {json}

Generic Save Method. Responds to POST /{GenericResource}. If Success returns 200 status code and a json with this.Model saved data. If error return 400 status code and a json => { errors }. 500 status code only will be returned if the method generates some unexpected error.
Parameters:
Name Type Description
req object Express requisition object.
res object Express response object.
Returns:
json - status and return object.
To Do:
  • Write comments

inner updateById(req, res) → {json}

Generic UpdateById Method. Responds to PUT /{GenericResource}/. Simple update this.Model by id. If Success returns 200 status code and a json with this.Model modified data. If error return 400 status code and a json => { errors }. 500 status code only will be returned if the method generates some unexpected error.
Parameters:
Name Type Description
req object Express requisition object.
res object Express response object.
Returns:
json - status and return object.
To Do:
  • Write comments