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": { "isUeeMember": {
"type": "boolean" "type": "boolean"
},
"isSocialNameUnique": {
"type": "boolean"
} }
}, },
"relations": { "relations": {
@ -39,4 +42,4 @@
"permission": "ALLOW" "permission": "ALLOW"
} }
] ]
} }

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) { async function socialNameIsUnique(err, done) {
if (!this.countryFk)
return done();
const filter = { const filter = {
include: {
relation: 'country',
scope: {
fields: {
isSocialNameUnique: true,
},
},
},
where: { where: {
and: [ and: [
{socialName: this.socialName}, {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(); err();
done(); done();
} }

View File

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