

Route
======
router.get('/get/:id', PriceController.get)


Controller
==========

get: async (request, response) => {
    try {
        const { params: { id } = {} } = request
        if (+id > 0) {
        let result = await PriceModel.get(id)
        return common.handleSuccess(response, result)
        }

        return common.handleError(response, globalMessages.sendValidId)
    } catch (e) {
        return common.handleError(response, e)
    }
}

Model
======

get: async (id) => {
	try {
		debug('PriceModel:get')
		const selectedColumn = [
		'ID',
		'SKUID',
		'DISTRIBUTOR_ID',
		'DISTRIBUTOR_PRICE',
		'RETAILER_PRICE',
		'MRP',
		'STATUS'        
		];
		const [result] = await knex.select(selectedColumn)
		.from(tables.pricing_master)
		.where({ id })
		return Promise.resolve(result ? result : [])
	} catch (e) {
		return Promise.reject(e)
	}
},
distributor_list: async (requestBody = {}) => {

    try {

        debug('PriceModel:distributor_list')

        let rawQuery = `SELECT t_u.ID, t_u.NAME FROM ${tables.user_master} as t_u WHERE 1 = 1 AND USER_TYPE_ID = '1' AND STATUS = '1' `;

        const [finalRecord] = await knex.raw(rawQuery);

        return Promise.resolve(finalRecord)

    } catch (e) {

        return Promise.reject(e)

    }

    },



    ============================app.js==================
    require('dotenv').config();
var app = require('express')();
var http = require('http').Server(app);

var Connection = require('tedious').Connection;  
var Request = require('tedious').Request;  
var TYPES = require('tedious').TYPES;  
var async = require('async');

// Create connection to database
// var config = {
//         userName: 'sa',  
//         password: '123456',  
//         server: '192.168.1.70',
//         options: {
//             encrypt: true, /*If you are connecting to a Microsoft Azure SQL database, you will need this*/
//             database: 'zangowango'
//         }
//     }
// var connection = new Connection(config);  

// // Attempt to connect and execute queries if connection goes through
// connection.on('connect', function(err) {  
//     if (err) {
//         console.log(err);
//     }  
//     else    {
//         console.log("Connected");

//         // Execute all functions in the array serially
//         async.waterfall([
//             function Start(callback){
//                 console.log("Starting...");
//                 callback(null, 'Jake', 'United States');
//             },
//             function Insert(name, location, callback){
//                 console.log("Inserting into Table...");

//                 request = new Request("INSERT ;", function(err){  
//                      if (err) {
//                             console.log(err);
//                         }  
//                     }
//                 );  
//                 request.addParameter('Name', TYPES.NVarChar, name);  
//                 request.addParameter('Location', TYPES.NVarChar, location);  

//                 request.on('row', function(columns) {  
//                     columns.forEach(function(column) {  
//                       if (column.value === null) {  
//                         console.log('NULL');  
//                       } else {  
//                         console.log("Employee id inserted is " + column.value);  
//                       }  
//                     });  
//                 }); 

//                 // Check how many rows were inserted
//                 request.on('doneInProc', function(rowCount, more) {  
//                     console.log(rowCount + ' row(s) inserted');  
//                     callback(null, 'Jared');
//                 });             

//                 connection.execSql(request);  
//             },
//             function Read(callback){
//                 // Requests can only be made in the LoggedIn state, so check for that
//                 if (connection.state !== connection.STATE.LOGGED_IN) {
//                     // Put the request back on the dispatcher if connection is not in LoggedIn state
//                     setTimeout(Read, 0, callback);
//                     return;
//                 }

//                 console.log("Reading rows from the Table...");

//                 // Create the request to read from table
//                 request = new Request("SELECT * FROM dbo.employees;", function(err) {  
//                     if (err) {
//                         console.log(err);
//                     }  
//                 });  

//                 // Output the number of rows read 
//                 request.on('doneInProc', function (rowCount, more, rows) {  
//                     console.log(rowCount + ' row(s) returned');  
//                     callback(null);
//                 });  

//                 connection.execSql(request);  
//             }],
//             function Complete(err, result) {
//                 if(err) {
//                     console.log("Error:", err);
//                 }
//                 else {
//                     console.log("Done!");
//                 }
//             }
//         )
//     }
// });

var Connection = require('tedious').Connection;  
var config = {  
    server: '192.168.1.70',  //update me
    authentication: {
        type: 'default',
        options: {
            userName: 'zangowango', //update me
            password: '123456',  //update me
            port:'1433'
        },
        pool: {

            max: 10,
        
            min: 0,
        
            idleTimeoutMillis: 30000
        
          },
    },
    options: {
        // If you are on Microsoft Azure, you need encryption:
        encrypt: false,
        database: 'zangowango',  //update me
        validateBulkLoadParameters:false,
        
    }
}; 
var connection = new Connection(config);  
connection.on('connect', function(err) {  
    // If no error, then good to proceed.  
    if(err) {
        console.log('Error: ', err)
      } else {
        console.log("Successful connection");
        executeStatement();
      }
});  

connection.connect();

var Request = require('tedious').Request;  
var TYPES = require('tedious').TYPES;  

function executeStatement() {  
    request  = new Request("SELECT * FROM Customer WHERE LastName='EMILY';", function(err) {  
    if (err) {  
        console.log(err);}  
    });  
    var result = "";  
    request.on('row', function(columns) {  
        columns.forEach(function(column) {  
          if (column.value === null) {  
            // console.log('NULL');  
          } else {  
            result+= column.value + " ";  
          }  
        });  
        // console.log(result);  
        result ="";  
    });  

    request.on('done', function(rowCount, more) {  
    console.log(rowCount + ' rows returned');  
    });  
    
    // Close the connection after the final event emitted by the request, after the callback passes
    request.on("requestCompleted", function (rowCount, more) {
        connection.close();
    });
    connection.execSql(request);  
}  

    // var Connection = require('tedious').Connection;
    // var config = {
    //     server: '192.168.1.70', //update me
    //     authentication: {
    //         type: 'default',
    //         options: {
    //             userName: 'sa', //update me
    //             password: '123456', //update me
    //         }
    //     },
    //     options: {
    //         encrypt: false,
    //         enableArithAbort: true,
    //         integratedSecurity: true,
    //         trustServerCertificate: true,
    //         rowCollectionOnDone: true,
    //         database: 'zangowango' //update me
    //     }
    // };
    
    
    
//     var connection = new Connection(config);
//     connection.on('connect', function(err) { 
//         console.log('connected');
//         executeStatement(); 
//     });
    
// var Request = require('tedious').Request;  
// var TYPES = require('tedious').TYPES;  

// function executeStatement() {  
//     request = new Request("select * from Customer;", function(err) {  
//     if (err) {  
//         console.log(err);}  
//     });  
//     var result = "";  
//     request.on('row', function(columns) {  
//         columns.forEach(function(column) {  
//           if (column.value === null) {  
//             console.log('NULL');  
//           } else {  
//             result+= column.value + " ";  
//           }  
//         });  
//         console.log(result);  
//         result ="";  
//     });  

//     request.on('done', function(rowCount, more) {  
//     console.log(rowCount + ' rows returned');  
//     });  
//     connection.execSql(request);
// }  
    // connection.connect(function(err) {
    //     console.log('testing')
    //         // var request = new Request("Select * from products", function(err, rowCount, rows) {
    //         //     console.log(rowCount);
    //         //     console.log(JSON.stringify(rows))
    //         // });
    //         // connection.execSql(request);
    
    //     connection.execSql(new Request('SELECT * FROM Customer', function(err, rowCount, rows) {
    //             if (err) {
    //                 throw err;
    //             }
    //         })
    //         .on('doneInProc', function(rowCount, more, rows) {
    //             console.log(more, rows[0], rowCount); // not empty
    //         }));
    
    // });
    
// executeStatement()
var port= process.env.PORT;

var accountSid  = process.env.ACCOUNT_SID;
var authToken   = process.env.AUTH_TOKEN;
var from_number = process.env.TWILIO_NO;
var to_number   = '+919711713562';
var template    = `This is a test template message`

const twilioClient = require("twilio")(accountSid, authToken);twilioClient.messages.create({
  from: from_number,
  to: to_number,
  body: template,
});

http.listen(port, function(){
    console.log(`node is running on port:${port}`);
});