All files / dist/validators boolean.js

100% Statements 18/18
100% Branches 17/17
100% Functions 1/1
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  3x 3x 3x 3x               3x 47x 47x 23x   9x 5x   9x     24x 5x 3x       19x 4x     47x   3x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleBooleanValidation = void 0;
var validators_1 = require("../utils/validators");
var constants_1 = require("../utils/constants");
/**
 * Handle Boolean Validations
 *
 * @param {String} field
 * @param {Validator} validator
 * @param {Object} value
 */
var handleBooleanValidation = function (field, validator, value) {
    var errors = [];
    if (value !== null && value !== undefined && (0, validators_1.isBoolean)(value)) {
        switch (validator.type) {
            case constants_1.BOOLEAN_VALIDATOR_TYPES.EQUAL:
                if (value !== validator.value) {
                    errors.push({ field: field, message: validator.message });
                }
                break;
        }
    }
    else if (value !== null && value !== undefined && !(0, validators_1.isBoolean)(value)) {
        if (validator.type == constants_1.BOOLEAN_VALIDATOR_TYPES.TYPE) {
            errors.push({ field: field, message: validator.message });
        }
    }
    else {
        if (validator.type == constants_1.BOOLEAN_VALIDATOR_TYPES.REQUIRED) {
            errors.push({ field: field, message: validator.message });
        }
    }
    return errors;
};
exports.handleBooleanValidation = handleBooleanValidation;