@qualipool/swissrets-json
Version:
A swiss real estate transfer standard.
36 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.allCustomValidators = void 0;
const allCustomValidators = () => {
return [sameAsCustomValidator, uniqueIdCustomValidator];
};
exports.allCustomValidators = allCustomValidators;
const sameAsCustomValidator = {
keyword: 'sameAs',
schema: false,
validate(value, root) {
// needed to add this because this custom validator takes precedence over the type check
// @ts-expect-error - this is a custom validator
if (!Array.isArray(root.rootData.projects)) {
return true;
}
// @ts-expect-error - this is a custom validator
return root.rootData.projects.some((obj) =>
// @ts-expect-error - this is a custom validator
obj.units?.some((item) => item.referenceId === value));
},
errors: true
};
const uniqueIdCustomValidator = {
keyword: 'uniqueId',
schema: false,
validate(values) {
if (!values) {
return false;
}
// @ts-expect-error - this is a custom validator
return new Set(values.map((item) => item.referenceId)).size == values.length;
},
errors: true
};
//# sourceMappingURL=custom-validation.js.map