Loopback validates data when saving data to the model. I am manipulating the data before saving in the remote method and I am getting 500 because the field is not present but I am using validatesPresenceOf() on the field.
module.exports = function(Otp) {
Otp.validatesPresenceOf('number', {
message: 'Phone number is required',
});
Otp.send = function(number, cb) {
// Getting 500 here because number is null
if (number.toString().length === 10) {
number = '1' + number;
}
// Loopback is validating number here
Otp.create({
number: number
});
});
}
How do I validate the presence of number before the remote method is ever getting called?
I could check for the presence in the remote field itself, but I want to use loopback's built in validations