forked from ttc/micro-service-api
-template make save
This commit is contained in:
61
exthernal-ttc-api/src/controllers/budgetAddController.js
Normal file
61
exthernal-ttc-api/src/controllers/budgetAddController.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import { AccountingSearchService } from '../services/accountingSearchService.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'
|
||||
import { Interface } from '../interfaces/Interface.js';
|
||||
|
||||
|
||||
export class accountingSearch {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService();
|
||||
this.Interface = new Interface();
|
||||
this.accountingSearchService = new AccountingSearchService();
|
||||
}
|
||||
|
||||
async onNavigate(req, res) {
|
||||
this.generalService.devhint(1, 'accountingSearch.js', 'onNavigate() start');
|
||||
let organization = req.body.organization;
|
||||
const prommis = await this.onAccountingSearch(req, res, organization);
|
||||
return prommis;
|
||||
}
|
||||
|
||||
async onAccountingSearch(req, res, database) {
|
||||
let idx = -1
|
||||
let aryResult = []
|
||||
try {
|
||||
// let username = req.body.request.username;
|
||||
// let password = req.body.request.password;
|
||||
let token = req.body.request.token;
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
let id = decoded.id
|
||||
let username = decoded.name
|
||||
database = decoded.organization
|
||||
|
||||
aryResult = await this.accountingSearchService.getAccountingSearch(database, id, username); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
||||
// this.generalService.devhint(1, 'accountingSearch.js', 'Login success');
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
} finally {
|
||||
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||
if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||
|
||||
|
||||
let prommis = await this.makeArySave(req);
|
||||
return prommis
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async makeArySave(req){
|
||||
let arysave = {
|
||||
methods: 'post',
|
||||
bdgseq: req.body.request.bdgseq,
|
||||
bdgttl: req.body.request.bdgseq
|
||||
}
|
||||
return this.Interface.saveInterface('bdgmst', arysave);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user