forked from ttc/micro-service-api
ttc-api: added transactionSearch* and projectSearch, more on reportController.
Signed-off-by: supphakitd <67319010028@technictrang.ac.th>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { TransactionSearchService } from '../services/transactionSearchService.js'
|
||||
import { sendError } from '../utils/response.js'
|
||||
// import { OftenError } from '../utils/oftenError.js'
|
||||
import { GeneralService } from '../share/generalservice.js';
|
||||
import { trim_all_array } from '../utils/trim.js'
|
||||
import { verifyToken, generateToken } from '../utils/token.js'
|
||||
|
||||
export class transactionSearch {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService();
|
||||
this.transactionSearchService = new TransactionSearchService();
|
||||
}
|
||||
|
||||
async onNavigate(req, res) {
|
||||
this.generalService.devhint(1, 'transactionSearch.js', 'onNavigate() start');
|
||||
let organization = req.body.organization;
|
||||
const prommis = await this.onTransactionSearch(req, res, organization);
|
||||
return prommis;
|
||||
}
|
||||
|
||||
async onTransactionSearch(req, res, database) {
|
||||
let idx = -1
|
||||
let aryResult = []
|
||||
let condition = {}
|
||||
try {
|
||||
// let username = req.body.request.username;
|
||||
// let password = req.body.request.password;
|
||||
let token = req.headers.authorization?.split(' ')[1];
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
database = decoded.organization
|
||||
let columnParams = req.query.column
|
||||
var column = ""
|
||||
if(columnParams == 'edit'){
|
||||
column = `trnseq, trnprjnam, trnprjseq, trnbdgcod, trncomstt`
|
||||
condition['trnseq'] = req.body.request.trnseq
|
||||
} else if(columnParams == 'result' || columnParams == undefined || columnParams == ''){
|
||||
column = `trnprjnam, trnbdgcod, ${database}.translatedtl('COMSTT', trncomstt) AS trncomstt, trnacpdtm`
|
||||
}
|
||||
|
||||
aryResult = await this.transactionSearchService.getTransactionSearch(database, column, condition);
|
||||
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
} finally {
|
||||
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||
if (aryResult == 0) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||
return aryResult
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user