feat(client): add more condition for businessType Validation
This commit is contained in:
parent
c5b8280403
commit
eae140003d
|
@ -55,18 +55,6 @@ module.exports = Self => {
|
||||||
with: /^[\w|.|-]+@[\w|-]+(\.[\w|-]+)*(,[\w|.|-]+@[\w|-]+(\.[\w|-]+)*)*$/
|
with: /^[\w|.|-]+@[\w|-]+(\.[\w|-]+)*(,[\w|.|-]+@[\w|-]+(\.[\w|-]+)*)*$/
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.validateAsync('businessTypeFk', hasBusinessType, {
|
|
||||||
message: `The type of business must be filled in basic data`
|
|
||||||
});
|
|
||||||
|
|
||||||
async function hasBusinessType(err, done) {
|
|
||||||
const isWorker = await Self.app.models.UserAccount.findById(this.id);
|
|
||||||
|
|
||||||
if (!this.businessTypeFk && !isWorker)
|
|
||||||
err();
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
|
|
||||||
Self.validatesLengthOf('postcode', {
|
Self.validatesLengthOf('postcode', {
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
allowBlank: true,
|
allowBlank: true,
|
||||||
|
@ -192,6 +180,24 @@ module.exports = Self => {
|
||||||
return regexp.test(value);
|
return regexp.test(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Self.observe('before save', async ctx => {
|
||||||
|
const changes = ctx.data || ctx.instance;
|
||||||
|
const orgData = ctx.currentInstance;
|
||||||
|
const hasChanges = orgData && changes;
|
||||||
|
|
||||||
|
const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk;
|
||||||
|
|
||||||
|
const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked;
|
||||||
|
const isTaxDataCheckedChanged = hasChanges && orgData.isTaxDataChecked != isTaxDataChecked;
|
||||||
|
|
||||||
|
let isWorker = false;
|
||||||
|
if (!ctx.isNewInstance)
|
||||||
|
isWorker = await Self.app.models.UserAccount.findById(orgData.id);
|
||||||
|
|
||||||
|
if (!businessTypeFk && !isTaxDataChecked && !isTaxDataCheckedChanged && !isWorker)
|
||||||
|
throw new UserError(`The type of business must be filled in basic data`);
|
||||||
|
});
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
const changes = ctx.data || ctx.instance;
|
const changes = ctx.data || ctx.instance;
|
||||||
const orgData = ctx.currentInstance;
|
const orgData = ctx.currentInstance;
|
||||||
|
@ -209,7 +215,7 @@ module.exports = Self => {
|
||||||
&& orgData.isTaxDataChecked != isTaxDataChecked;
|
&& orgData.isTaxDataChecked != isTaxDataChecked;
|
||||||
|
|
||||||
if ((socialNameChanged || dataCheckedChanged) && !isAlpha(socialName))
|
if ((socialNameChanged || dataCheckedChanged) && !isAlpha(socialName))
|
||||||
throw new UserError('The socialName has an invalid format');
|
throw new UserError(`The socialName has an invalid format`);
|
||||||
|
|
||||||
if (changes.salesPerson === null) {
|
if (changes.salesPerson === null) {
|
||||||
changes.credit = 0;
|
changes.credit = 0;
|
||||||
|
|
Loading…
Reference in New Issue