Files
micro-service-api/exthernal-accountingwep-api/src/controllers/accountingAddController.js

42 lines
1.6 KiB
JavaScript
Raw Normal View History

import { AccountingAddService } from '../services/accountingAddService.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 accountingAdd {
constructor() {
this.generalService = new GeneralService();
this.accountingAddService = new AccountingAddService();
}
async onNavigate(req, res) {
this.generalService.devhint(1, 'accountingAdd.js', 'onNavigate() start');
let organization = req.body.organization;
const prommis = await this.onAccountingAdd(req, res, organization);
return prommis;
}
async onAccountingAdd(req, res, database) {
let idx = -1
let aryResult = []
try {
let token = req.body.request.token;
const decoded = verifyToken(token);
let num = req.body.request.actnum;
database = decoded.organization
aryResult = await this.accountingAddService.getAccountingAdd(database, num);
} catch (error) {
idx = 1;
} finally {
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
return aryResult
}
}
}