Created
February 19, 2016 01:37
-
-
Save juniorconte/f36757c057e298be309c to your computer and use it in GitHub Desktop.
Criar usuários dreamfactory e registrar com diferentes papéis via API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lodash = require("lodash.min.js"); | |
var role1Id = 1; | |
var role2Id = 2; | |
var role3Id = 3; | |
var appVendorId = 1; | |
var appCustomerId = 2; | |
var originAppId = platform.session.app.id; | |
if (platform.session.user) { | |
var userObject = platform.api.get('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id'); | |
lodash._.each(userObject.content.user_to_app_to_role_by_user_id, function(userApp) { | |
switch (originAppId) { | |
case appCustomerId: | |
if (userApp.app_id === appCustomerId) { | |
userApp.role_id = role1Id; | |
} | |
break; | |
case appVendorId: | |
if (userApp.app_id === appVendorId) { | |
userApp.role_id = role2Id; | |
} | |
break; | |
} | |
}); | |
platform.api.patch('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id', userObject.content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required setup, and more information on http://goo.gl/tPa4Fa