gypsum
Version:
Simple and easy lightweight typescript server side framework on Node.js.
29 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Validall = require("validall");
const types_1 = require("../types");
const logger_1 = require("../misc/logger");
function validate(ctx, schema) {
const logger = new logger_1.Logger('validateHook');
logger.info('checking args');
logger.debug('schema:', schema);
if (!schema) {
return ctx.next({
message: 'invalid schema',
code: types_1.RESPONSE_CODES.BAD_REQUEST
});
}
logger.info('args check passed');
logger.info('looping args');
let state = Validall(ctx, schema, { root: 'context', required: false, strict: false, filter: false });
if (!state)
return ctx.next({
message: Validall.error.toString(),
original: Validall.error,
code: types_1.RESPONSE_CODES.UNAUTHORIZED
});
logger.info('all validations passed');
ctx.next();
}
exports.validate = validate;
//# sourceMappingURL=validate.js.map