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

46 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-11-11 17:55:41 +07:00
import { AccountingSetupService } from '../services/accountingSetupService.js'
2025-11-11 15:48:04 +07:00
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 accountingSetup {
constructor() {
this.generalService = new GeneralService();
2025-11-11 17:55:41 +07:00
this.AccountingSetupService = new AccountingSetupService();
2025-11-11 15:48:04 +07:00
}
async onNavigate(req, res) {
this.generalService.devhint(1, 'accountingSetup.js', 'onNavigate() start');
let organization = req.body.organization;
const prommis = await this.onAccountingSetup(req, res, organization);
return prommis;
}
async onAccountingSetup(req, res, database) {
let idx = -1
let result = []
try {
2025-11-11 17:55:41 +07:00
// let username = req.body.request.username;
// let password = req.body.request.password;
2025-11-11 15:48:04 +07:00
2025-11-11 17:55:41 +07:00
result = await this.AccountingSetupService.getAccountingSetup(database); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
2025-11-11 15:48:04 +07:00
// this.generalService.devhint(1, 'accountingSetup.js', 'Login success');
} catch (error) {
idx = 1;
} finally {
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
if (!result) return sendError('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง', 'Invalid credentials');
2025-11-11 17:55:41 +07:00
// แยกกลุ่ม income / expense
let income = result.filter(item => item.dtltblcod === 'ACTCAT_INC').map(({ dtltblcod, ...rest }) => rest);
let expense = result.filter(item => item.dtltblcod === 'ACTCAT_EXP').map(({ dtltblcod, ...rest }) => rest);
let arydiy = { income , expense };
return arydiy
2025-11-11 15:48:04 +07:00
}
}
}