....
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
PJ_NAME=exthernal-ttc-api
|
||||
|
||||
# database
|
||||
PG_HOST=localhost
|
||||
PG_HOST=10.9.0.0
|
||||
PG_USER=postgres
|
||||
PG_PASS=123456
|
||||
PG_PASS=ttc@2026
|
||||
PG_DB=ttc
|
||||
PG_PORT=5432
|
||||
|
||||
|
||||
@@ -33,17 +33,20 @@ export class budgetAdd {
|
||||
let id = req.body.request.bdgseq;
|
||||
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');
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
} finally {
|
||||
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);
|
||||
return prommis
|
||||
} else {
|
||||
return sendError('คีย์หลักซ้ำในระบบ', 'Duplicate Primary Key');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ import jwt from 'jsonwebtoken'
|
||||
import { BdgmstInterface } from './table/bdgmstInterface.js'
|
||||
// import { ActmstInterface } from './actmstInterface.js'
|
||||
|
||||
// -------------------------------
|
||||
// GLOBAL FILE
|
||||
// -----------------------------
|
||||
|
||||
export class Interface {
|
||||
|
||||
constructor() {
|
||||
@@ -21,7 +25,7 @@ export class Interface {
|
||||
// ------------------------------
|
||||
const handler = this.map[tableName.toLowerCase()]
|
||||
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]
|
||||
if (!token) {
|
||||
throw new Error('Missing token in request header')
|
||||
return new Error('Missing token in request header')
|
||||
}
|
||||
|
||||
let decoded
|
||||
try {
|
||||
decoded = jwt.verify(token, process.env.JWT_SECRET)
|
||||
} catch (err) {
|
||||
throw new Error('Invalid token: ' + err.message)
|
||||
return new Error('Invalid token: ' + err.message)
|
||||
}
|
||||
|
||||
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 นั้น ๆ
|
||||
|
||||
@@ -6,15 +6,15 @@ export class BudgetAddService {
|
||||
this.generalService = new GeneralService()
|
||||
}
|
||||
|
||||
async getBudgetAdd(database, id, name) {
|
||||
async getBudgetAdd(database, name) {
|
||||
const sql = `
|
||||
SELECT
|
||||
bdgseq,
|
||||
bdgnam
|
||||
FROM ${database}.bdgmst
|
||||
WHERE bdgseq = $1 AND bdgnam = $2
|
||||
`
|
||||
const params = [id, name]
|
||||
WHERE bdgnam = $1
|
||||
s `
|
||||
const params = [name]
|
||||
const result = await this.generalService.executeQueryParam(database, sql, params);
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user