From c5b8280403fe2ec6a5689c4ca18cfa62282fd592 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 5 Jan 2022 12:44:18 +0100 Subject: [PATCH] feat(client): add isWorker condition in hasBusinessType --- modules/client/back/models/client.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index b4961771d9..d9007e95aa 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -55,13 +55,16 @@ module.exports = Self => { with: /^[\w|.|-]+@[\w|-]+(\.[\w|-]+)*(,[\w|.|-]+@[\w|-]+(\.[\w|-]+)*)*$/ }); - Self.validate('businessTypeFk', hasBusinessType, { + Self.validateAsync('businessTypeFk', hasBusinessType, { message: `The type of business must be filled in basic data` }); - function hasBusinessType(err) { - if (!this.businessTypeFk) + async function hasBusinessType(err, done) { + const isWorker = await Self.app.models.UserAccount.findById(this.id); + + if (!this.businessTypeFk && !isWorker) err(); + done(); } Self.validatesLengthOf('postcode', {