refs #5837 fix client condition
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-07-20 08:23:43 +02:00
parent 579d6d53d8
commit 60e75d7825
1 changed files with 7 additions and 6 deletions

View File

@ -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();
}