Throw invalid businessType for new clients
This commit is contained in:
parent
d85f95a8f4
commit
ebee852de6
|
@ -184,17 +184,26 @@ module.exports = Self => {
|
|||
const changes = ctx.data || ctx.instance;
|
||||
const orgData = ctx.currentInstance;
|
||||
|
||||
const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk;
|
||||
const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked;
|
||||
|
||||
let invalidBusinessType = false;
|
||||
if (!ctx.isNewInstance) {
|
||||
const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk;
|
||||
const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked;
|
||||
const isWorker = await Self.app.models.UserAccount.findById(orgData.id);
|
||||
const changedFields = Object.keys(changes);
|
||||
const hasChangedOtherFields = changedFields.some(key => key !== 'businessTypeFk');
|
||||
|
||||
const isWorker = await Self.app.models.UserAccount.findById(orgData.id);
|
||||
|
||||
if (!businessTypeFk && !isTaxDataChecked && !isWorker && !hasChangedOtherFields)
|
||||
throw new UserError(`The type of business must be filled in basic data`);
|
||||
invalidBusinessType = true;
|
||||
}
|
||||
|
||||
if (ctx.isNewInstance) {
|
||||
if (!businessTypeFk && !isTaxDataChecked)
|
||||
invalidBusinessType = true;
|
||||
}
|
||||
|
||||
if (invalidBusinessType)
|
||||
throw new UserError(`The type of business must be filled in basic data`);
|
||||
});
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
|
|
Loading…
Reference in New Issue