-เส้น search
This commit is contained in:
@@ -8,8 +8,17 @@ PG_PASS=123456
|
|||||||
PG_DB=ttc
|
PG_DB=ttc
|
||||||
PG_PORT=5432
|
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-TOKENS
|
||||||
JWT_SECRET=MY_SUPER_SECRET
|
JWT_SECRET=5b8273b2f79602e6b3987d3a9b018c66fd15e14848ff73ab1d332942c11eac80
|
||||||
|
|
||||||
# DEV_HINT
|
# DEV_HINT
|
||||||
DEVHINT=true
|
DEVHINT=true
|
||||||
|
|||||||
@@ -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,6 +25,11 @@ export class accountingSetup {
|
|||||||
try {
|
try {
|
||||||
// let username = req.body.request.username;
|
// let username = req.body.request.username;
|
||||||
// let password = req.body.request.password;
|
// let password = req.body.request.password;
|
||||||
|
let token = req.body.request.token;
|
||||||
|
const decoded = verifyToken(token);
|
||||||
|
|
||||||
|
database = decoded.organization
|
||||||
|
|
||||||
|
|
||||||
result = await this.AccountingSetupService.getAccountingSetup(database); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
result = await this.AccountingSetupService.getAccountingSetup(database); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
|
||||||
// this.generalService.devhint(1, 'accountingSetup.js', 'Login success');
|
// this.generalService.devhint(1, 'accountingSetup.js', 'Login success');
|
||||||
@@ -38,7 +43,11 @@ export class accountingSetup {
|
|||||||
|
|
||||||
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
|
return arydiy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { accountingSetup } from '../controllers/accountingSetup.js'
|
import { accountingSetup } from '../controllers/accountingSetup.js'
|
||||||
|
import { accountingSearch } from '../controllers/accountingSearch.js'
|
||||||
|
|
||||||
// import { authMiddleware } from '../middlewares/auth.js'
|
// import { authMiddleware } from '../middlewares/auth.js'
|
||||||
// import { sendResponse } from '../utils/response.js'
|
// import { sendResponse } from '../utils/response.js'
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const controller_accountingSetup_post = new accountingSetup()
|
const controller_accountingSetup_post = new accountingSetup()
|
||||||
|
const controller_accountingSearch_post = new accountingSearch()
|
||||||
|
|
||||||
router.post('/accountingSetup', async (req, res) => {
|
router.post('/accountingSetup', async (req, res) => {
|
||||||
const result = await controller_accountingSetup_post.onNavigate(req, res)
|
const result = await controller_accountingSetup_post.onNavigate(req, res)
|
||||||
if (result) return res.json(result)
|
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
|
// // 🔹 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 = `
|
const sql = `
|
||||||
SELECT
|
SELECT
|
||||||
dtlnam,
|
dtlnam,
|
||||||
dtlcod,
|
${database}.translatedtl('ACTTYP', dtlcod) as dtlname,
|
||||||
dtltblcod
|
dtltblcod
|
||||||
FROM ${database}.dtlmst
|
FROM ${database}.dtlmst
|
||||||
WHERE dtltblcod IN ('ACTTYP', 'ACTCAT_INC', 'ACTCAT_EXP');
|
WHERE dtltblcod IN ('ACTTYP', 'ACTCAT_INC', 'ACTCAT_EXP');
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ export function generateToken(payload) {
|
|||||||
export function verifyToken(token) {
|
export function verifyToken(token) {
|
||||||
try {
|
try {
|
||||||
return jwt.verify(token, process.env.JWT_SECRET)
|
return jwt.verify(token, process.env.JWT_SECRET)
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error("❌ JWT verify error:", err.message);
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user