Created
January 28, 2020 01:32
-
-
Save zsarnett/1b28994381e0f051c896d9ae8fdbad5c to your computer and use it in GitHub Desktop.
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
/* | |
2020 Vinyl Development, LLC d/b/a Zudy | |
@author Zack Arnett <ZackArnett@zudy.com> | |
*/ | |
import config from "./config.js"; | |
var BTCA = new BTCAClient({ | |
handle: "VINYL_REQUEST_LAUNCHER", | |
cache: true, | |
log: false | |
}); | |
let sendRequest = request => { | |
return new Promise((resolve, reject) => { | |
BTCA.send(request, (result, requestId, error) => { | |
resolve(result); | |
}); | |
}); | |
}; | |
(async () => { | |
var userRequest = { | |
action: "getEntity", | |
params: { | |
entityName: "user", | |
id: "myProfileId" | |
} | |
}; | |
var userResponse = await sendRequest(userRequest); | |
var userGetRequest = { | |
action: "proxyRequest", | |
params: { | |
url: config.userURL + `?$count=true&hubUserID=${userResponse.id}`, | |
method: "GET", | |
headers: { | |
"Content-Type": "application/json", | |
"x-api-key": config.apiKey | |
} | |
} | |
}; | |
var usersGetResponse = await sendRequest(userGetRequest); | |
if (usersGetResponse.count == 0) { | |
var userCreateRequest = { | |
action: "proxyRequest", | |
params: { | |
url: config.userURL, | |
method: "POST", | |
body: { | |
item: { | |
HubUserID: userResponse.id, | |
firstName: userResponse.firstName, | |
lastName: userResponse.lastName, | |
userName: userResponse.email | |
} | |
}, | |
headers: { | |
"Content-Type": "application/json", | |
"x-api-key": config.apiKey | |
} | |
} | |
}; | |
await sendRequest(userCreateRequest); | |
} | |
var formCreateRequest = { | |
action: "proxyRequest", | |
params: { | |
url: config.formCreateURL, | |
method: "POST", | |
body: { | |
item: { | |
FormID: config.formID, | |
HubUserID: userResponse.id | |
} | |
}, | |
headers: { | |
"Content-Type": "application/json", | |
"x-api-key": config.apiKey | |
} | |
} | |
}; | |
await sendRequest(formCreateRequest); | |
var urlRequest = { | |
action: "openURL", | |
params: { | |
url: `${config.formURL}?FormID~Shared=${config.formID}&HubUserID~Shared=${userResponse.id}` | |
} | |
}; | |
await sendRequest(urlRequest); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment