budget-api: initial
This commit is contained in:
45
exthernal-ttc-api/src/controllers/budgetSearchController.js
Normal file
45
exthernal-ttc-api/src/controllers/budgetSearchController.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { BudgetSearchService } from '../services/budgetSearchService.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 budgetSearch {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService();
|
||||
this.budgetSearchService = new BudgetSearchService();
|
||||
}
|
||||
|
||||
async onNavigate(req, res) {
|
||||
this.generalService.devhint(1, 'budgetSearch.js', 'onNavigate() start');
|
||||
let organization = req.body.organization;
|
||||
const prommis = await this.onBudgetSearch(req, res, organization);
|
||||
return prommis;
|
||||
}
|
||||
|
||||
async onBudgetSearch(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.budgetSearchService.getBudgetSearch(database, id); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
||||
// this.generalService.devhint(1, 'budgetSearch.js', 'Login success');
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
} finally {
|
||||
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||
if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||
return aryResult
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user