-- แก้ไขตรวจสอบ ระบบ interface ให้ใช้งาน ได้ สมบูรแบบ

This commit is contained in:
2025-11-17 14:48:03 +07:00
parent 05dfb9a39e
commit 0185c54fb3
4 changed files with 17 additions and 15 deletions

View File

@@ -59,6 +59,6 @@ export class budgetAdd {
bdgcod: req.body.request.bdgcod,
bdgttl: req.body.request.bdgttl
}
return this.Interface.saveInterface('bdgmst', arysave, req);
return this.Interface.saveInterface('bdgmst', arysave, req);
}
}

View File

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

View File

@@ -8,17 +8,17 @@ export class BdgmstInterface {
this.pk = ['bdgseq']
}
async saveInterface(database, data) {
const method = data.methods.toLowerCase()
const payload = { ...data }
delete payload.method
async saveInterface(database, data) {
const method = data.methods.toLowerCase()
const { methods, ...payload } = data
if (method === 'put') return this.update(database, payload)
if (method === 'post') return this.insert(database, payload)
if (method === 'delete') return this.remove(database, payload)
if (method === 'put') return this.update(database, payload)
if (method === 'post') return this.insert(database, payload)
if (method === 'delete') return this.remove(database, payload)
throw new Error(`Unknown method: ${method}`)
}
throw new Error(`Unknown method: ${method}`)
}
async insert(database, payload) {
const cols = Object.keys(payload)

View File

@@ -13,7 +13,7 @@ export class BudgetAddService {
bdgnam
FROM ${database}.bdgmst
WHERE bdgnam = $1
s `
`
const params = [name]
const result = await this.generalService.executeQueryParam(database, sql, params);
return result