Skip to content

Commit

Permalink
Merge pull request #58 from ringcentral/addEmployeeRestelt
Browse files Browse the repository at this point in the history
Use Restlet to fetch CurrentLoggedIn User
  • Loading branch information
DaKingKong authored Oct 25, 2024
2 parents 12c05bd + acf0d21 commit 00eb2e6
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/adapters/netsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const url = require('url');
const { parsePhoneNumber } = require('awesome-phonenumber');
const { parse } = require('path');
const { getTimeZone } = require('../../lib/util');
const { get } = require('shortid/lib/alphabet');

function getAuthType() {
return 'oauth';
Expand All @@ -22,17 +23,23 @@ async function getOauthInfo({ hostname }) {

async function getUserInfo({ authHeader, additionalInfo, query }) {
try {
const url = `https://${query.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/employee/${query.entity}`;
const employeResponse = await axios.get(url,
{
let getCurrentLoggedInUserResponse;
try {
const getCurrentLoggedInUserUrl = `https://${query.hostname.split(".")[0]}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=customscript_getcurrentuser&deploy=customdeploy_getcurrentuser`;
getCurrentLoggedInUserResponse = await axios.get(getCurrentLoggedInUserUrl, {
headers: { 'Authorization': authHeader }
});
const id = query.entity;
const name = employeResponse.data.firstName + ' ' + employeResponse.data.lastName;
const timezoneName = employeResponse.data.time_zone ?? '';
const timezoneOffset = employeResponse.data.time_zone_offset ?? null;
const location = employeResponse.data.location ?? '';
const subsidiaryId = employeResponse.data.subsidiary?.id ?? '';
} catch (e) {
console.log({ message: "Error in getting employee information using RestLet" });
return {
successful: false,
returnMessage: {
messageType: 'danger',
message: "It appears that your SuiteApp is an older version. Please update it to the latest version.",
ttl: 60000
}
}
}
let oneWorldEnabled;
try {
const checkOneWorldLicenseUrl = `https://${query.hostname.split(".")[0]}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=customscript_getoneworldlicense_scriptid&deploy=customdeploy_getoneworldlicense_deployid`;
Expand All @@ -49,14 +56,12 @@ async function getUserInfo({ authHeader, additionalInfo, query }) {
return {
successful: true,
platformUserInfo: {
id,
name,
timezoneName,
timezoneOffset,
id: query.entity,
name: getCurrentLoggedInUserResponse?.data?.name,
platformAdditionalInfo: {
email: employeResponse.data.email,
name: name,
subsidiaryId,
email: getCurrentLoggedInUserResponse?.data?.email,
name: getCurrentLoggedInUserResponse?.data?.name,
subsidiaryId: getCurrentLoggedInUserResponse?.data?.subsidiary,
oneWorldEnabled: oneWorldEnabled,
},

Expand Down

0 comments on commit 00eb2e6

Please sign in to comment.