From b6624691767a4eb24b57915d630addf24eb8c9f2 Mon Sep 17 00:00:00 2001 From: supphakitd <67319010028@technictrang.ac.th> Date: Tue, 18 Nov 2025 10:12:52 +0700 Subject: [PATCH] accountingAdd*: initial (working maybe) Signed-off-by: supphakitd <67319010028@technictrang.ac.th> --- .../controllers/accountingAddController.js | 41 +++++++++++++++++++ .../src/routes/route.js | 13 ++++-- .../src/services/accountingAddService.js | 21 ++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 exthernal-accountingwep-api/src/controllers/accountingAddController.js create mode 100644 exthernal-accountingwep-api/src/services/accountingAddService.js diff --git a/exthernal-accountingwep-api/src/controllers/accountingAddController.js b/exthernal-accountingwep-api/src/controllers/accountingAddController.js new file mode 100644 index 0000000..70083d4 --- /dev/null +++ b/exthernal-accountingwep-api/src/controllers/accountingAddController.js @@ -0,0 +1,41 @@ +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 + } + } +} diff --git a/exthernal-accountingwep-api/src/routes/route.js b/exthernal-accountingwep-api/src/routes/route.js index be10822..8362d50 100644 --- a/exthernal-accountingwep-api/src/routes/route.js +++ b/exthernal-accountingwep-api/src/routes/route.js @@ -1,7 +1,8 @@ import express from 'express' -import { accountingSetup } from '../controllers/accountingSetup.js' -import { accountingSearch } from '../controllers/accountingSearch.js' -import { accountingSum } from '../controllers/accountingSum.js' +import { accountingSetup } from '../controllers/accountingSetupController.js' +import { accountingSearch } from '../controllers/accountingSearchController.js' +import { accountingSum } from '../controllers/accountingSumController.js' +import { accountingAdd } from '../controllers/accountingAddController.js' // import { authMiddleware } from '../middlewares/auth.js' // import { sendResponse } from '../utils/response.js' @@ -10,7 +11,7 @@ const router = express.Router() const controller_accountingSetup_post = new accountingSetup() const controller_accountingSearch_post = new accountingSearch() const controller_accountingSum_post = new accountingSum() - +const controller_accountingAdd_post = new accountingAdd() router.post('/accountingSetup', async (req, res) => { const result = await controller_accountingSetup_post.onNavigate(req, res) @@ -28,6 +29,10 @@ router.post('/accountingSum', async (req, res) => { if (result) return res.json(result) }) +router.post('/accountingAdd', async (req, res) => { + const result = await controller_accountingAdd_post.onNavigate(req, res) + if (result) return res.json(result) +}) // // =================================================== // // 🔹 BIOMETRIC LOGIN diff --git a/exthernal-accountingwep-api/src/services/accountingAddService.js b/exthernal-accountingwep-api/src/services/accountingAddService.js new file mode 100644 index 0000000..9c0bd2d --- /dev/null +++ b/exthernal-accountingwep-api/src/services/accountingAddService.js @@ -0,0 +1,21 @@ +import { GeneralService } from '../share/generalservice.js' + +export class AccountingAddService { + + constructor() { + this.generalService = new GeneralService() + } + + async getAccountingAdd(database, name) { + const sql = ` + SELECT + actseq, + actnam + FROM ${database}.actmst + WHERE actnam = $1 + ` + const params = [name] + const result = await this.generalService.executeQueryParam(database, sql, params); + return result + } +} \ No newline at end of file