first commit
This commit is contained in:
68
adapter/dbadapter.js
Normal file
68
adapter/dbadapter.js
Normal file
@ -0,0 +1,68 @@
|
||||
const e = require('express');
|
||||
const db=require('../config/dbproc.js');
|
||||
const Controller = require('../controllers/controller.js');
|
||||
|
||||
class DbAdapter extends Controller {
|
||||
constructor(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
async queryDynamictable(columninfo,tablename,callback) {
|
||||
db.query('SELECT '+columninfo+' from ?? where isdeleted=0 order by id asc', [tablename], function (error, results, fields) {
|
||||
var apiResult = {};
|
||||
if (error) {
|
||||
apiResult.meta = {
|
||||
table: tablename,
|
||||
type: "collection",
|
||||
total: 0
|
||||
}
|
||||
apiResult.data = [];
|
||||
callback(error,apiResult);
|
||||
}
|
||||
|
||||
//make results
|
||||
var resultJson = JSON.stringify(results);
|
||||
resultJson = JSON.parse(resultJson);
|
||||
|
||||
apiResult.meta = {
|
||||
table: tablename,
|
||||
type: "collection",
|
||||
total: resultJson.length,
|
||||
total_entries: 0
|
||||
}
|
||||
|
||||
//add our JSON results to the data table
|
||||
apiResult.data = resultJson;
|
||||
callback(null, apiResult);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static async queryExistsTransactionHeader(fakturnumber,callback){
|
||||
var qry="select h.id idheader,d.id iddetail from tbl_salesheader h inner join tbl_salesdetail d on h.id=d.idheader";
|
||||
qry= qry +" where h.fakturnumber='"+fakturnumber+"' and h.isdeleted=0 and d.isdeleted=0";
|
||||
db.query(qry, [], function (error, results) {
|
||||
var res={"res":false,"id":0};
|
||||
if(error){throw error;}
|
||||
if(results.length>0)
|
||||
{
|
||||
var iddetail=[];
|
||||
results.forEach(function(e){
|
||||
iddetail.push(e.iddetail);
|
||||
});
|
||||
res={
|
||||
"res":true,
|
||||
"id" :results[0].idheader,
|
||||
"iddetail" : iddetail
|
||||
}
|
||||
|
||||
}
|
||||
callback(res);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = DbAdapter;
|
||||
Reference in New Issue
Block a user