@credenceanalytics/fsapi-manager

1.0.0 • Public • Published

FASTREST

Prerequisite

  • Oracle DB
  • NRest Repository
  • Oracleinstaclient
  • NRestServer is running in development mode with nodemon

Usage

FASTREST - INTEGRATION

Pull the fsapi-manager repo in the existing node restserver. To initialize fsapi-manager, add the following in Nrest/index.js

const initFSAPI = require("./fsapi-manager");
(async () => {
    await initFSAPI({                                  
        "app":app,                                        // app  - Express App Object   
        "config": path.join(servicesdir, 'dbconfig.json') // Config file
        ,"fsdir":path.join(__dirname, "fs-apis")          // Path of the Folder within Node rest server where APIS will be created
        ,"logger":logger                                  // Logger object to log info
    });
})();

API Folder Struture

|__fs-apis  
      └── index.js      ---- Registering API    
            └── <apiname>/   
                  |── index.js --- Mandatory File 
                  ├── model.js
                  ├── controller.js       
                  ├── hooks.js
                  └── validation.js        

Registering API - fs-apis/index.js

const SampleAPI=require("./sample");

module.exports=(app)=>{
    const options={}
    fsutils.registerFSService("/sample",SampleAPI(app,options))
}

API Creation

File Description

  • model.js [DB Schema Definition ]

    {
      "<model name>":{
        "COLUMN-1": {
            "type": "STRING/DATE/NUMBER",
            "iskey": true,   //primary key or not
            "sequence":""   //database sequence name if data is to be autopopulated from sequence.
        },
        "COLUMN-2": {
            "type": "STRING/DATE/NUMBER",
            "mandatory":"",
            "enumlist":["",""],
            "min-val":"",  // Mininum value in case of number 
            "max-val":"", // Maximum value in case of number 
            "maxlength":"" //Maximum length of string
    
        }
      }  
    }
  • hooks.js
    Functions can be added to before/after events of CRUD operation. For this you need to add functions to the file hook.js.Each function will get 2 standard inputs, data,action

    module.exports={
      "<modelname>":{  
          "before":{
            "create":[function(data,action){}],
            "update":[],
            "delete":[],
            "read":[]
          },
          "after":{
            "create":[],
            "update":[],
            "delete":[],
            "read":[]
          }
      }
    }
  • Controller.js
    In case any of the API CRUD operation is to be overwritten, the code will go in this file

    module.exports=function(app,opts){
      return {
              model: model, // model.js
              hooks:hooks,  //hooks.js
              create:function(args){
                // Overwrite Create
              },
              update:function(args){
                // Overwrite Update
              },
              delete:function(args){
                // Overwrite Delete
              },
              read:function(args){
                // Overwrite Read
              }
          }
    }

Final API Definition Structure

{
  "model" :{/* DB Schema Definition */},
  "hooks":{/* Before/After API Hooks */},
  "create":function(args){ 
    /*
     * In case the function is to be overwritten
    */
  },
  "update":function(args){ 
    /*
     * In case the function is to be overwritten
    */
  }
  "delete":function(args){ 
    /*
     * In case the function is to be overwritten
    */
  }
  "read":function(args){ 
    /*
     * In case the function is to be overwritten
    */
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @credenceanalytics/fsapi-manager

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

80.6 kB

Total Files

26

Last publish

Collaborators

  • jiteshsuthar
  • atulknowsme
  • shruti_shende
  • sonalnadkar
  • cred-shubham
  • sagarf
  • prajaktacred
  • mandakadam
  • prabhuvikas
  • jimmyjammerx
  • suraj_chavan
  • mohinim18