5934-clientSms #1675
|
@ -22,6 +22,9 @@
|
|||
},
|
||||
"isUeeMember": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"isSocialNameUnique": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
@ -39,4 +42,4 @@
|
|||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE `vn`.`country`
|
||||
ADD COLUMN `isSocialNameUnique` tinyint(1) NOT NULL DEFAULT 1;
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -181,6 +181,11 @@
|
|||
"model": "Country",
|
||||
"foreignKey": "countryFk"
|
||||
},
|
||||
"isSocialNameUnique": {
|
||||
"type": "belongsTo",
|
||||
"model": "Country",
|
||||
"foreignKey": "countryFk"
|
||||
},
|
||||
"contactChannel": {
|
||||
"type": "belongsTo",
|
||||
"model": "ContactChannel",
|
||||
|
|
Loading…
Reference in New Issue