2019-06-17 06:14:48 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.validatesPresenceOf('name', {
|
2021-01-15 10:24:32 +00:00
|
|
|
message: 'Name cannot be blank'
|
2019-11-28 11:54:34 +00:00
|
|
|
});
|
2021-02-17 15:11:34 +00:00
|
|
|
|
2019-11-28 11:54:34 +00:00
|
|
|
Self.validatesPresenceOf('bic', {
|
2021-01-15 10:24:32 +00:00
|
|
|
message: 'Swift / BIC cannot be empty'
|
|
|
|
});
|
2021-02-17 15:11:34 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
Self.validatesUniquenessOf('bic', {
|
2024-01-31 09:46:16 +00:00
|
|
|
message: 'This BIC already exist'
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.validatesPresenceOf('countryFk', {
|
|
|
|
message: 'CountryFK cannot be empty'
|
2019-06-17 06:14:48 +00:00
|
|
|
});
|
2023-11-03 08:15:41 +00:00
|
|
|
|
|
|
|
Self.validateAsync('bic', checkBic, {
|
|
|
|
message: 'Bank entity id must be specified'
|
|
|
|
});
|
|
|
|
async function checkBic(err, done) {
|
|
|
|
const filter = {
|
|
|
|
fields: ['code'],
|
|
|
|
where: {id: this.countryFk}
|
|
|
|
};
|
|
|
|
const country = await Self.app.models.Country.findOne(filter);
|
|
|
|
const code = country ? country.code.toLowerCase() : null;
|
|
|
|
|
|
|
|
if (code == 'es' && !this.id)
|
|
|
|
err();
|
|
|
|
done();
|
|
|
|
}
|
2019-06-17 06:14:48 +00:00
|
|
|
};
|