new Service( _model )

Description
Service class to handle all database/api calls.
Parameters
Name Type Description
_model mongoose.Model Mongoose model for the MongoDB collection.
Examples
const { Service } = require("emfrest/services")

Usage

class CustomService extends Service{
  usefulServiceFunction = (options) => {
    return somethingUseful;
  }
}
Details

Methods


getAll( query )

Description
Database query to fetch all documents of a collection.
Parameters
Name Type Description
query object | void MongoDB query
Details

createResource( data )

Description
Database query to create a document.
Parameters
Name Type Description
data object Data to be saved as a document.
Details

getOneById( id )

Description
Database query to find a document by ID.
Parameters
Name Type Description
id mongoose.ObjectId MongoDB document ObjectId.
Details

updateOneByIdService( id, newData )

Description
Database query to update a document by ID.
Parameters
Name Type Description
id mongoose.ObjectId MongoDB document ObjectId.
newData object Object with fields to be updated in the document.
Details

deleteById( id )

Description
Database query to delete a document by ID.
Parameters
Name Type Description
id mongoose.ObjectId MongoDB document ObjectId.
Details