Prevent businessTypeFk validation for other invalid fields
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e1c9195495
commit
2279b3d9ab
|
@ -184,15 +184,17 @@ module.exports = Self => {
|
||||||
const changes = ctx.data || ctx.instance;
|
const changes = ctx.data || ctx.instance;
|
||||||
const orgData = ctx.currentInstance;
|
const orgData = ctx.currentInstance;
|
||||||
|
|
||||||
|
if (!ctx.isNewInstance) {
|
||||||
const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk;
|
const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk;
|
||||||
const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked;
|
const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked;
|
||||||
|
const changedFields = Object.keys(changes);
|
||||||
|
const hasChangedOtherFields = changedFields.some(key => key !== 'businessTypeFk');
|
||||||
|
|
||||||
let isWorker = false;
|
const isWorker = await Self.app.models.UserAccount.findById(orgData.id);
|
||||||
if (!ctx.isNewInstance)
|
|
||||||
isWorker = await Self.app.models.UserAccount.findById(orgData.id);
|
|
||||||
|
|
||||||
if (!businessTypeFk && !isTaxDataChecked && !isWorker)
|
if (!businessTypeFk && !isTaxDataChecked && !isWorker && !hasChangedOtherFields)
|
||||||
throw new UserError(`The type of business must be filled in basic data`);
|
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) {
|
||||||
|
|
Loading…
Reference in New Issue