forked from ttc/micro-service-api
-เส้น search
This commit is contained in:
@@ -8,12 +8,21 @@ PG_PASS=123456
|
||||
PG_DB=ttc
|
||||
PG_PORT=5432
|
||||
|
||||
# EMAIL
|
||||
SMTP_USER=lalisakuty@gmail.com
|
||||
SMTP_PASS=lurl pckw qugk tzob
|
||||
|
||||
# REDIS
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PORT=6379
|
||||
OTP_TTL_SECONDS=300
|
||||
|
||||
# JWT-TOKENS
|
||||
JWT_SECRET=MY_SUPER_SECRET
|
||||
JWT_SECRET=5b8273b2f79602e6b3987d3a9b018c66fd15e14848ff73ab1d332942c11eac80
|
||||
|
||||
# DEV_HINT
|
||||
DEVHINT=true
|
||||
DEVHINT_LEVEL=3
|
||||
|
||||
#PORT
|
||||
PORT=1013
|
||||
PORT=1013
|
||||
@@ -0,0 +1,45 @@
|
||||
import { AccountingSearchService } from '../services/accountingSearchService.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 accountingSearch {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService();
|
||||
this.accountingSearchService = new AccountingSearchService();
|
||||
}
|
||||
|
||||
async onNavigate(req, res) {
|
||||
this.generalService.devhint(1, 'accountingSearch.js', 'onNavigate() start');
|
||||
let organization = req.body.organization;
|
||||
const prommis = await this.onAccountingSearch(req, res, organization);
|
||||
return prommis;
|
||||
}
|
||||
|
||||
async onAccountingSearch(req, res, database) {
|
||||
let idx = -1
|
||||
let aryResult = []
|
||||
try {
|
||||
// let username = req.body.request.username;
|
||||
// let password = req.body.request.password;
|
||||
let token = req.body.request.token;
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
let id = decoded.id
|
||||
let username = decoded.name
|
||||
database = decoded.organization
|
||||
|
||||
aryResult = await this.accountingSearchService.getAccountingSearch(database, id, username); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
||||
// this.generalService.devhint(1, 'accountingSearch.js', 'Login success');
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
} finally {
|
||||
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||
if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||
return aryResult
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,13 @@ export class accountingSetup {
|
||||
try {
|
||||
// let username = req.body.request.username;
|
||||
// let password = req.body.request.password;
|
||||
let token = req.body.request.token;
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
result = await this.AccountingSetupService.getAccountingSetup(database); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
||||
database = decoded.organization
|
||||
|
||||
|
||||
result = await this.AccountingSetupService.getAccountingSetup(database); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
||||
// this.generalService.devhint(1, 'accountingSetup.js', 'Login success');
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
@@ -36,9 +41,13 @@ export class accountingSetup {
|
||||
// แยกกลุ่ม 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 expense = result.filter(item => item.dtltblcod === 'ACTCAT_EXP').map(({ dtltblcod, ...rest }) => rest);
|
||||
|
||||
let arydiy = {
|
||||
income ,
|
||||
expense
|
||||
};
|
||||
|
||||
let arydiy = { income , expense };
|
||||
return arydiy
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
import express from 'express'
|
||||
import { accountingSetup } from '../controllers/accountingSetup.js'
|
||||
import { accountingSearch } from '../controllers/accountingSearch.js'
|
||||
|
||||
// import { authMiddleware } from '../middlewares/auth.js'
|
||||
// import { sendResponse } from '../utils/response.js'
|
||||
|
||||
const router = express.Router()
|
||||
const controller_accountingSetup_post = new accountingSetup()
|
||||
const controller_accountingSearch_post = new accountingSearch()
|
||||
|
||||
router.post('/accountingSetup', async (req, res) => {
|
||||
const result = await controller_accountingSetup_post.onNavigate(req, res)
|
||||
if (result) return res.json(result)
|
||||
})
|
||||
|
||||
|
||||
router.post('/accountingSearch', async (req, res) => {
|
||||
const result = await controller_accountingSearch_post.onNavigate(req, res)
|
||||
if (result) return res.json(result)
|
||||
})
|
||||
|
||||
|
||||
// // ===================================================
|
||||
// // 🔹 BIOMETRIC LOGIN
|
||||
// // ===================================================
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { GeneralService } from '../share/generalservice.js'
|
||||
|
||||
export class AccountingSearchService {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService()
|
||||
}
|
||||
|
||||
async getAccountingSearch(database, id, username) {
|
||||
const sql = `
|
||||
SELECT
|
||||
actseq,
|
||||
actnum,
|
||||
${database}.translatedtl('ACTTYP', acttyp) as acttypnam,
|
||||
${database}.translatedtl_multi(ARRAY['ACTCAT_INC', 'ACTCAT_EXP'], actcat) as actcatnam,
|
||||
actqty,
|
||||
actcmt,
|
||||
actacpdtm
|
||||
FROM ${database}.actmst
|
||||
WHERE actnum = $1
|
||||
`
|
||||
const params = [id]
|
||||
const result = await this.generalService.executeQueryParam(database, sql, params);
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export class AccountingSetupService {
|
||||
const sql = `
|
||||
SELECT
|
||||
dtlnam,
|
||||
dtlcod,
|
||||
${database}.translatedtl('ACTTYP', dtlcod) as dtlname,
|
||||
dtltblcod
|
||||
FROM ${database}.dtlmst
|
||||
WHERE dtltblcod IN ('ACTTYP', 'ACTCAT_INC', 'ACTCAT_EXP');
|
||||
|
||||
@@ -9,7 +9,8 @@ export function generateToken(payload) {
|
||||
export function verifyToken(token) {
|
||||
try {
|
||||
return jwt.verify(token, process.env.JWT_SECRET)
|
||||
} catch {
|
||||
} catch (err) {
|
||||
console.error("❌ JWT verify error:", err.message);
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user