5934-clientSms #1675

Merged
alexm merged 5 commits from 5934-clientSms into dev 2023-07-20 07:01:02 +00:00
4 changed files with 28 additions and 3 deletions
Showing only changes of commit 5771ccb488 - Show all commits

View File

@ -22,6 +22,9 @@
},
"isUeeMember": {
"type": "boolean"
},
"isSocialNameUnique": {
"type": "boolean"
}
},
"relations": {

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn`.`country`
ADD COLUMN `isSocialNameUnique` tinyint(1) NOT NULL DEFAULT 1;

View File

@ -41,7 +41,18 @@ module.exports = Self => {
});
async function socialNameIsUnique(err, done) {
if (!this.countryFk)
return done();
const filter = {
include: {
relation: 'country',
scope: {
fields: {
isSocialNameUnique: true,
},
},
},
where: {
and: [
{socialName: this.socialName},
@ -50,9 +61,13 @@ module.exports = Self => {
]
}
};
const client = await Self.app.models.Client.findOne(filter);
if (client)
const client = await Self.app.models.Country.findById(this.countryFk, {fields: ['isSocialNameUnique']});
const existingClient = await Self.findOne(filter);
if (existingClient && (existingClient.country().isSocialNameUnique || client.isSocialNameUnique))
err();
done();
}

View File

@ -181,6 +181,11 @@
"model": "Country",
"foreignKey": "countryFk"
},
"isSocialNameUnique": {
"type": "belongsTo",
"model": "Country",
"foreignKey": "countryFk"
},
"contactChannel": {
"type": "belongsTo",
"model": "ContactChannel",