module.exports = Self => { Self.remoteMethod('isValidClient', { description: 'Checks if the user havent got the role employee, is active and has verified data', accessType: 'READ', accepts: [ { arg: 'id', type: 'string', required: true, description: 'The user id', http: {source: 'path'} } ], returns: { type: 'boolean', root: true }, http: { path: `/:id/isValidClient`, verb: 'GET' } }); Self.isValidClient = async(id, options) => { const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); const query = ` SELECT r.name FROM salix.Account a JOIN vn.client c ON a.id = c.id JOIN salix.RoleMapping rm ON rm.principalId = a.id JOIN salix.Role r ON r.id = rm.roleId WHERE a.id = ? AND c.isActive AND c.isTaxDataChecked`; const roleNames = await Self.rawSql(query, [id], myOptions); const isEmployee = roleNames.findIndex(role => { return role.name === 'employee'; }); if (!roleNames.length || isEmployee > -1) return false; return true; }; };