const check = require('validator').check
const db = require('../lib/db');

const Issuers = db.table('issuers', {
  fields: [
    'id',
    'slug',
    'name',
    'url',
    'description',
    'email',
    'imageId'
  ],
});

Issuers.validateRow = function (row) {
  return this.fields.reduce(function (errors, field) {
    try {
      const validator = validation[field] || noop
      validator(row[field])
    }
    catch(e) {
      e.field = field
      errors.push(e)
    }
    return errors
  }, [])
}

const validation = {
  id: function (id) {
    if (typeof id == 'undefined') return;
    check(id).isInt();
  },
  slug: function (slug) {
    check(slug).len(1, 50);
  },
  name: function (name) {
    check(name).len(1, 50);
  },
  url: function (url) {
    check(url).isUrl();
  },
  description: function (desc) {
    check(desc).len(0, 255);
  },
  email: function (email) {
    if (typeof email == 'undefined') return;
    check(email).isEmail();
  },
}

function noop() {}

exports = module.exports = Issuers;

@@ -3,25 +3,78 @@
 nst 
-check = require('
+db = require('../lib/db');%0Aconst makeValidator = require('../lib/make-
 vali
@@ -84,23 +84,20 @@
 or')
-.check
 %0Aconst 
-db
+check
  = r
@@ -104,27 +104,33 @@
 equire('
-../lib/db')
+validator').check
 ;%0A%0Aconst
@@ -301,287 +301,22 @@
 w = 
-function (row) %7B%0A  return this.fields.reduce(function (errors, field) %7B%0A    try %7B%0A      const validator = validation%5Bfield%5D %7C%7C noop%0A      validator(row%5Bfield%5D)%0A    %7D%0A    catch(e) %7B%0A      e.field = field%0A      errors.push(e)%0A    %7D%0A    return errors%0A  %7D, %5B%5D)%0A%7D%0A%0Aconst validation = 
+makeValidator(
 %7B%0A  
@@ -754,28 +754,9 @@
 %7D,%0A%7D
-%0A%0Afunction noop() %7B%7D
+)
 %0A%0Aex

Use `makeValidator` helper.