forked from ttc/micro-service-api
....
This commit is contained in:
@@ -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 นั้น ๆ
|
||||
|
||||
Reference in New Issue
Block a user