This commit is contained in:
2025-11-17 14:36:32 +07:00
parent 33f8fce3e6
commit 05dfb9a39e
4 changed files with 20 additions and 13 deletions

View File

@@ -2,9 +2,9 @@
PJ_NAME=exthernal-ttc-api PJ_NAME=exthernal-ttc-api
# database # database
PG_HOST=localhost PG_HOST=10.9.0.0
PG_USER=postgres PG_USER=postgres
PG_PASS=123456 PG_PASS=ttc@2026
PG_DB=ttc PG_DB=ttc
PG_PORT=5432 PG_PORT=5432

View File

@@ -33,17 +33,20 @@ export class budgetAdd {
let id = req.body.request.bdgseq; let id = req.body.request.bdgseq;
database = decoded.organization database = decoded.organization
aryResult = await this.budgetAddService.getBudgetAdd(database, id, name); // เช็คกับ db กลาง ส่ง jwttoken ออกมา aryResult = await this.budgetAddService.getBudgetAdd(database, name); // เช็คกับ db กลาง ส่ง jwttoken ออกมา
// this.generalService.devhint(1, 'budgetSearch.js', 'Login success'); // this.generalService.devhint(1, 'budgetSearch.js', 'Login success');
} catch (error) { } catch (error) {
idx = 1; idx = 1;
} finally { } finally {
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error'); if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data'); // if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
if (aryResult == 0){
let prommis = await this.makeArySave(req); let prommis = await this.makeArySave(req);
return prommis return prommis
} else {
return sendError('คีย์หลักซ้ำในระบบ', 'Duplicate Primary Key');
}
} }
} }

View File

@@ -2,6 +2,10 @@ import jwt from 'jsonwebtoken'
import { BdgmstInterface } from './table/bdgmstInterface.js' import { BdgmstInterface } from './table/bdgmstInterface.js'
// import { ActmstInterface } from './actmstInterface.js' // import { ActmstInterface } from './actmstInterface.js'
// -------------------------------
// GLOBAL FILE
// -----------------------------
export class Interface { export class Interface {
constructor() { constructor() {
@@ -21,7 +25,7 @@ export class Interface {
// ------------------------------ // ------------------------------
const handler = this.map[tableName.toLowerCase()] const handler = this.map[tableName.toLowerCase()]
if (!handler) { if (!handler) {
throw new Error(`Interface not found for table: ${tableName}`) return new Error(`Interface not found for table: ${tableName}`)
} }
// ------------------------------ // ------------------------------
@@ -29,18 +33,18 @@ export class Interface {
// ------------------------------ // ------------------------------
const token = req.headers.authorization?.split(' ')[1] const token = req.headers.authorization?.split(' ')[1]
if (!token) { if (!token) {
throw new Error('Missing token in request header') return new Error('Missing token in request header')
} }
let decoded let decoded
try { try {
decoded = jwt.verify(token, process.env.JWT_SECRET) decoded = jwt.verify(token, process.env.JWT_SECRET)
} catch (err) { } catch (err) {
throw new Error('Invalid token: ' + err.message) return new Error('Invalid token: ' + err.message)
} }
const schema = decoded.organization // ⭐ ได้ schema ที่ต้องการ const schema = decoded.organization // ⭐ ได้ schema ที่ต้องการ
if (!schema) throw new Error("Token missing 'organization' field") if (!schema) return new Error("Token missing 'organization' field")
// ------------------------------ // ------------------------------
// ✔ 3) ส่งงานไปยัง interface ของ table นั้น ๆ // ✔ 3) ส่งงานไปยัง interface ของ table นั้น ๆ

View File

@@ -6,15 +6,15 @@ export class BudgetAddService {
this.generalService = new GeneralService() this.generalService = new GeneralService()
} }
async getBudgetAdd(database, id, name) { async getBudgetAdd(database, name) {
const sql = ` const sql = `
SELECT SELECT
bdgseq, bdgseq,
bdgnam bdgnam
FROM ${database}.bdgmst FROM ${database}.bdgmst
WHERE bdgseq = $1 AND bdgnam = $2 WHERE bdgnam = $1
` s `
const params = [id, name] const params = [name]
const result = await this.generalService.executeQueryParam(database, sql, params); const result = await this.generalService.executeQueryParam(database, sql, params);
return result return result
} }