Skip to content

chandrashekar3792/ES6

Repository files navigation

Service Layer Documentation

Functions

MySQL

Function Name:

  • Dev: cq-backend-dev-services-mysql
  • Prod:cq-backend-prod-services-mysql

Parameters:

  • query: Array of strings.

    Example:-

    {query:["SELECT net_asset_value FROM nav_hist_2018_Q1 WHERE amfi_code = '112322'"]}

Reponse:

[
 [
     {
       "net_asset_value": 24.7457
     },
     {
       "net_asset_value": 24.3017
     },
     {
       "net_asset_value": 23.9447
     },
     {
       "net_asset_value": 24.0693
     },
     {
       "net_asset_value": 24.1939
     },
     {
       "net_asset_value": 24.2331
     },
     {
       "net_asset_value": 21.4112
     },
     
   ]
]

DocumentDB

Insert

Function Name:

  • Dev: cq-backend-dev-services-insert
  • Prod:cq-backend-prod-services-insert

Parameters:

  • collection: Name of the collection(Required).

  • document: Document to be inserted(Required).

    Example:-

    {
         collection:"user",
         document:{
             name:"chandru"
             email:"[email protected]"
         }
    }

Reponse:

  {
      result:{
          _id:"5c825e0f213827c4f32dfe42"
          name:"chandru"
          email:"[email protected]"
      }
  }

Find

Function Name:

  • Dev: cq-backend-dev-services-find
  • Prod:cq-backend-prod-services-find

Parameters:

  • collection: Name of the collection(Required.).

  • query: Query to find proper document(Required)

  • id: Document Id if you need particular document when findType is findById

  • select: Specify the fields which are required

  • findType: Specify the find type(Required) [findAll,findOne,findById,count,distinct]

  • sort:Specify the sort order by field

  • limit:Speicify how many documents to get

  • skip: Specify how many documents to skip

  • uniqueField: Specify the field name when find type is distinct

    Example:-

    FindType: findAll
    {
        collection:"user",
        query:{username:"chandru",
        findType:"findAll",
        sort:{_id:-1},
        skip:10
        limit:1
    }
    Reponse:
    {
    "result": [
    {
      "_id": "5c7fa9e111d62b31b17cb4a5",
      "name": "chandru"
    },
    {
      "_id": "5c7fab6211d62b16f467dc01",
      "name": "chandru"
    }
    ]}

    findType: findOne

    {
        collection:"user",
        query:{username:"chandru",
        findType:"findOne",
    }
    Reponse:
    {
        result:{
            _id:"5c825e0f213827c4f32dfe42"
            name:"chandru"
            email:"[email protected]"
        }
    }
    

    findType: findById

    {
       collection:"user",
       _id:"5c825e0f213827c4f32dfe42",
       findType:"findById",
    }
    Reponse:
    {
               result:{
                   _id:"5c825e0f213827c4f32dfe42"
                   name:"chandru"
                   email:"[email protected]"
               }
           }

    findType: count

    {
       collection:"user",
       query:{username:"chandru",
       findType:"count",
    }
    Reponse:
    {
    "result": 2
    }

    findType: distinct

    {
       collection:"user",
       query:{username:"chandru",
       findType:"distinct",
    uniqueField:"name"
    }
    Reponse:
 {
"result": [
  "chandru"
]
}

Update

Function Name:

  • Dev: cq-backend-dev-services-update
  • Prod:cq-backend-prod-services-update

Parameters:

  • collection: Name of the collection(Required.).

  • where: Query to find proper document(Required)

  • set: Field which need to be update(Required)

  • updateType: Specify the update type(Required) [updateOne,updateMany]

    Example:-

    updateType: updateMany
    {
        collection:"user",
        where:{username:"chandru"},
        set:{email:"[email protected]",
        updateType:"updateMany"
    }
    Reponse:
    {
        result:{
            _id:"5c825e0f213827c4f32dfe42"
            name:"chandru"
            email:"[email protected]"
        }
    }

    updateType: updateOne

    {
     "result": "Updated successfully"
    }
    Reponse:
    {
        result:{
            _id:"5c825e0f213827c4f32dfe42"
            name:"chandru"
            email:"[email protected]"
        }
    }
    

Remove

Function Name:

  • Dev: cq-backend-dev-services-remove
  • Prod:cq-backend-prod-services-remove

Parameters:

  • collection: Name of the collection(Required.).

  • Query: Query to find proper document(Required)

  • removeType: Specify the remove type(Required) [removeOne,removeById,removeAll]

  • id : Document ID when remove type is removeById

    Example:-

    removeType: removeAll
    {
        collection:"user",
        where:{username:"chandru"},
        removeType:"removeAll"
    }
    Reponse:
     {
     "result": {
    "Updated": 0,
    "Removed": 1,
    "Matched": 1,
    "UpsertedId": null
    }
    }

    removeType: removeOne

    {
        collection:"user",
        where:{username:"chandru"},
        removeType:"removeOne"
    
    }
    Reponse:
    {
     "result": "Deleted successfully"
    }
    

    removeType: removeById

    {
        {
        collection:"user",
        id:"5c825e0f213827c4f32dfe42",
        removeType:"removeById"
    }
    }
    Reponse:
    {
          "result": "Deleted successfully"
       }
    

Aggregate

Function Name:

  • Dev: cq-backend-dev-services-aggregate
  • Prod:cq-backend-prod-services-aggregate

Parameters:

  • collection: Name of the collection(Required.).

  • operations: Array of operations required for aggregation(Required)

    Example:-

    {
    	collection:"user",
     operations:[
     	{"$match":{status:"A"}},
     	{"$group":{_id:"$cust_id",total:{"$sum":"$amount"}}}
     ]
    }

    Response:-

    {
    	result:[
     	{ "_id" : "A123", "total" : 750 },
     	{ "_id" : "B212", "total" : 200 }
     ]
    }

About

Learning new features of javascript ES6

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published