-ต้นแบบ โครงสร้าง ไฟล์ API เส้น /api/ttc

This commit is contained in:
2025-11-17 09:03:36 +07:00
parent eefbb8e5dd
commit 9f9c9aa80d
25 changed files with 1019 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import { formatSuccessResponse } from '../utils/response.js'
export function globalResponseHandler(req, res, next) {
const oldJson = res.json.bind(res)
res.json = (data) => {
if (!data) return oldJson(formatSuccessResponse(null))
// ถ้า code ไม่ใช่ 200 → ตั้ง HTTP status ให้ตรงกับ code
if (data?.code && String(data.code) !== '200') {
res.status(Number(data.code) || 400)
return oldJson(data)
}
res.status(200)
return oldJson(formatSuccessResponse(data))
}
next()
}