From 406089741f01da6c33ebf3f9ae43e548d79a5c63 Mon Sep 17 00:00:00 2001 From: x2Skyz Date: Tue, 11 Nov 2025 15:48:04 +0700 Subject: [PATCH] service --- .../src/controllers/accountingSetup.js | 40 +++++++++++++++++++ .../src/services/userservice.js | 7 +++- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 exthernal-accountingwep-api/src/controllers/accountingSetup.js diff --git a/exthernal-accountingwep-api/src/controllers/accountingSetup.js b/exthernal-accountingwep-api/src/controllers/accountingSetup.js new file mode 100644 index 0000000..aa7eb32 --- /dev/null +++ b/exthernal-accountingwep-api/src/controllers/accountingSetup.js @@ -0,0 +1,40 @@ +import { LoginService } from '../services/loginservice.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 accountingSetup { + + constructor() { + this.generalService = new GeneralService(); + this.loginService = new LoginService(); + } + + 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 { + let username = req.body.request.username; + let password = req.body.request.password; + + result = await this.loginService.verifyLogin(database, username, password); // เช็คกับ 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 + } + } +} diff --git a/exthernal-accountingwep-api/src/services/userservice.js b/exthernal-accountingwep-api/src/services/userservice.js index fb5fcd6..d2fbcc9 100644 --- a/exthernal-accountingwep-api/src/services/userservice.js +++ b/exthernal-accountingwep-api/src/services/userservice.js @@ -1,6 +1,9 @@ import { executeQueryParam } from '../share/generalservice.js' -export const userService = { +export class userservice { + constructor() { + this.generalService = new GeneralService() + } async createUser(database, usrnam, usreml) { const sql = ` SELECT * FROM ${database}.usrmst @@ -9,5 +12,5 @@ export const userService = { const params = [usrnam, usreml] const result = await executeQueryParam(sql, database, params) return result - }, + } }