This commit is contained in:
parent
579d6d53d8
commit
60e75d7825
|
@ -41,6 +41,9 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function socialNameIsUnique(err, done) {
|
async function socialNameIsUnique(err, done) {
|
||||||
|
if (!this.countryFk)
|
||||||
|
return done();
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
include: {
|
include: {
|
||||||
relation: 'country',
|
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) {
|
if (existingClient && (existingClient.country().isSocialNameUnique || client.isSocialNameUnique))
|
||||||
// eslint-disable-next-line max-len
|
err();
|
||||||
if (existingClient.country().isSocialNameUnique && this.socialName === existingClient.socialName)
|
|
||||||
err();
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue