-ตัวอย่าง microservice

This commit is contained in:
2025-11-11 17:55:41 +07:00
parent 406089741f
commit 968f3efd52
11 changed files with 46 additions and 378 deletions

View File

@@ -1,4 +1,4 @@
import { LoginService } from '../services/loginservice.js'
import { AccountingSetupService } from '../services/accountingSetupService.js'
import { sendError } from '../utils/response.js'
// import { OftenError } from '../utils/oftenError.js'
import { GeneralService } from '../share/generalservice.js';
@@ -9,7 +9,7 @@ export class accountingSetup {
constructor() {
this.generalService = new GeneralService();
this.loginService = new LoginService();
this.AccountingSetupService = new AccountingSetupService();
}
async onNavigate(req, res) {
@@ -23,18 +23,23 @@ export class accountingSetup {
let idx = -1
let result = []
try {
let username = req.body.request.username;
let password = req.body.request.password;
// let username = req.body.request.username;
// let password = req.body.request.password;
result = await this.loginService.verifyLogin(database, username, password); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
result = await this.AccountingSetupService.getAccountingSetup(database); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
// 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');
if(result) { return result }
return null
// แยกกลุ่ม 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
}
}
}