Replace checkit-based validation with a simple property check for the time being
parent
d4c01e8056
commit
89fe5054f0
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
validateSync: require("./validate-sync"),
|
||||
requireProperties: require("./require-properties"),
|
||||
createObject: require("./create-object"),
|
||||
createCompositeObject: require("./create-composite-object")
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function requireProperties(object, properties) {
|
||||
let missingProperties = [];
|
||||
|
||||
properties.forEach((property) => {
|
||||
if (object[property] == null) {
|
||||
missingProperties.push(property);
|
||||
}
|
||||
});
|
||||
|
||||
if (missingProperties.length > 0) {
|
||||
throw new Error(`Missing required properties: ${missingProperties.join(", ")}`);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const checkit = require("checkit");
|
||||
|
||||
module.exports = function(object, rules) {
|
||||
let [error, validated] = checkit(rules).runSync(object);
|
||||
|
||||
if (error != null) {
|
||||
throw error;
|
||||
} else {
|
||||
return validated;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue