Files
micro-service-api/exthernal-accountingwep-api/src/middlewares/validate.js
2025-11-11 15:11:56 +07:00

25 lines
901 B
JavaScript

import { sendError } from '../utils/response.js'
/**
* ✅ 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)
return sendError('รูปแบบ บอร์ดี้ ไม่ถูกต้อง', 'Invalid Body format')
}
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()
// }