-- แก้ไขตรวจสอบ ระบบ 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

@@ -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 นั้น ๆ