0.3.45 • Published 3 years ago

@genezis/genezis-utils-mongodb v0.3.45

Weekly downloads
46
License
MIT
Repository
github
Last release
3 years ago

genezis-utils-mongodb

RequestsUtils

A collection of functions that creates different types of requests that perform actions on a collection.

Every single function will accept the following arguments:

Setting parameter nameExpected typeRequiredDescription
collectionMongoDBCollection/Function->MongoDBCollection(req, data, sharedData)YesThe collection where the actions to be performed. It can also be a function that will return the collection. The function will receive the request object, the request data and the shared data
onBeginFunction[]->null(req, data, sharedData)NoArgument from the package @genezis/genezis-utils-router. An array of functions that will be called on the begging of the request. The functions will receive the request object, the request data and the shared data
onErrorFunction->null(error, req, data, sharedData)YesA function that will process the predefined errors from the request

createSingleGetter

Create a request that is able to fetch a single document from a collection.

Short summary of the arguments:

Setting parameter nameExpected typeRequiredDescription
getByRequestFieldNoThe possible fields to get by the document. The order of them matters
findQueryMiddlewareFunction->object(req, data, sharedData, actualFindQuery)NoA function that will be called after the query formed from getBy is created. The function must return the modified query. The function get as parameters the request object, the request data, the shared data and the actual query
customFindQueryMakerFunction->object(req, data, sharedData)NoA function that created the find one query. It must return the query. It will receive the request object, the request data and the shared data
userProjectionAllowedBooleanNoAllow the user to request specific fields. Default value is false
userProjectionInputFieldStringNoThe name of the input field where the user will specify the fields for projection. It is required if userProjectionAllowed is true
customOnSuccessFunction->null(req, data, sharedData, onSuccess, foundDoc)NoA function that will replace the actual call to onSuccess(foundDoc). It will receive the request object, the request data, the shared data, the onSuccess function and the found doc
onNoDocumentFoundFunction->boolean(req, data, sharedData, onSuccess)NoCalled when no document found. It should return true if inside the function the method onSuccess is called. It will receive the request object, the request data, the shared data and the onSuccess function.
customFindOneSettingsFunction->object(req, data, sharedData, actualFindOneSettings)NoA function that is called after user projection is calculated (if allowed) and receives the request object, the request data, the shared data and the actual findOneSettings. findOneSettings is the object that will be given to MongoDB's Collection findOne as settings.

Attention! The fields getBy and customFindQueryMaker can't go together, but at least one is expected to be given!
Attention! findQueryMiddleware works only with getBy, but not with customFindQueryMaker

Possible errors:

  • GenezisCheckerTypes.NOT_ARRAY
  • QUERY_FROM_GIVEN_FIELDS_NOT_FOUND_MATCH
0.3.45

3 years ago

0.3.44

4 years ago

0.3.43

4 years ago

0.3.41

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.2.98

4 years ago

0.2.97

4 years ago

0.2.96

4 years ago

0.2.95

4 years ago

0.2.942

4 years ago

0.2.941

4 years ago

0.2.94

4 years ago

0.2.935

4 years ago

0.2.934

4 years ago

0.2.933

4 years ago

0.2.932

4 years ago

0.2.931

4 years ago

0.2.93

4 years ago

0.2.92

4 years ago

0.2.917

4 years ago

0.2.9171

4 years ago

0.2.9163

4 years ago

0.2.9162

4 years ago

0.2.9161

4 years ago

0.2.9150

4 years ago

0.2.9160

4 years ago

0.2.9140

4 years ago

0.2.9130

4 years ago

0.2.9120

4 years ago

0.2.9101

4 years ago

0.2.9111

4 years ago

0.2.9110

4 years ago

0.2.9100

4 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago