Files
micro-service-api/exthernal-accountingwep-api/src/middlewares/validate.js

25 lines
901 B
JavaScript
Raw Normal View History

2025-11-11 15:11:56 +07:00
import { sendError } from '../utils/response.js'
2025-11-11 12:36:06 +07:00
/**
* Middleware สำหรบตรวจสอบความถกตองของ JSON body
* องก body-parser crash (SyntaxError)
*/
export function validateJsonFormat(err, req, res, next) {
if (err instanceof SyntaxError && 'body' in err) {
console.error('[Invalid JSON Format]', err.message)
2025-11-11 15:11:56 +07:00
return sendError('รูปแบบ บอร์ดี้ ไม่ถูกต้อง', 'Invalid Body format')
2025-11-11 12:36:06 +07:00
}
next()
}
// /**
// * ✅ ตรวจสอบ body/query/params ว่ามีค่า organization หรือไม่
// */
// export function validateRequest(req, res, next) {
// const { organization } = req.body || {}
// if (!organization) {
// return sendResponse(res, 400, 'ไม่พบค่า organization', 'Missing organization')
// }
// next()
// }