validation.js 432 B

12345678910111213141516
  1. const Validator = require('fastest-validator')
  2. const v = new Validator()
  3. const response = require('./responseHandler')
  4. exports.validate = (res, data, schema, payload) => {
  5. const check = v.compile(schema)
  6. const validationError = check(data)
  7. if (validationError.length) {
  8. response.error(res, {
  9. error: validationError,
  10. message: payload?.message || 'data tidak valid',
  11. })
  12. return false
  13. }
  14. return true
  15. }