17 lines
444 B
JavaScript
17 lines
444 B
JavaScript
|
module.exports = Self => {
|
||
|
Self.validateAsync('postalCode', hasValidPostcode, {
|
||
|
message: `The postcode doesn't exist. Please enter a correct one`
|
||
|
});
|
||
|
|
||
|
async function hasValidPostcode(err, done) {
|
||
|
if (!this.postalCode)
|
||
|
return done();
|
||
|
|
||
|
const models = Self.app.models;
|
||
|
const postcode = await models.Postcode.findById(this.postalCode);
|
||
|
|
||
|
if (!postcode) err();
|
||
|
done();
|
||
|
}
|
||
|
};
|