This commit is contained in:
parent
579d6d53d8
commit
60e75d7825
|
@ -41,6 +41,9 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
async function socialNameIsUnique(err, done) {
|
||||
if (!this.countryFk)
|
||||
return done();
|
||||
|
||||
const filter = {
|
||||
include: {
|
||||
relation: 'country',
|
||||
|
@ -59,13 +62,11 @@ module.exports = Self => {
|
|||
}
|
||||
};
|
||||
|
||||
const existingClient = await Self.app.models.Client.findOne(filter);
|
||||
const client = await Self.app.models.Country.findById(this.countryFk, {fields: ['isSocialNameUnique']});
|
||||
const existingClient = await Self.findOne(filter);
|
||||
|
||||
if (existingClient) {
|
||||
// eslint-disable-next-line max-len
|
||||
if (existingClient.country().isSocialNameUnique && this.socialName === existingClient.socialName)
|
||||
if (existingClient && (existingClient.country().isSocialNameUnique || client.isSocialNameUnique))
|
||||
err();
|
||||
}
|
||||
|
||||
done();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue