From 53585e9c8305c19894d9ffbbd681a2d9f57127c7 Mon Sep 17 00:00:00 2001 From: sumanvpacewisdom Date: Wed, 11 Sep 2024 12:57:49 +0530 Subject: [PATCH] Comment Changes for Delete EntityType --- .../deleteEntitiesAndTypes.js | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/scripts/deleteEntitiesAndTypes/deleteEntitiesAndTypes.js b/src/scripts/deleteEntitiesAndTypes/deleteEntitiesAndTypes.js index b9194ff3b..a197b48c4 100644 --- a/src/scripts/deleteEntitiesAndTypes/deleteEntitiesAndTypes.js +++ b/src/scripts/deleteEntitiesAndTypes/deleteEntitiesAndTypes.js @@ -7,9 +7,10 @@ const rl = readline.createInterface({ output: process.stdout, }) -let accessToken = '' +let authenticatedUserToken = '' let adminAuthToken = '' let organizationId = '' +let authorization = '' const DEFAULT_MENTORING_DOMAIN = 'http://localhost:3569' let MENTORING_DOMAIN = DEFAULT_MENTORING_DOMAIN @@ -17,10 +18,12 @@ let MENTORING_DOMAIN = DEFAULT_MENTORING_DOMAIN async function main() { try { await promptForDomain() - await promptForAccessToken() + await promptForAuthenticatedUserToken() + await promptForAuthorization() await promptForAdminAuthToken() await promptForOrganizationId() - return await deleteEntityType() + const entityTypes = await promptForEntityTypeValues() + return await deleteEntityType(entityTypes) } catch (error) { console.error('Error occurred:', error) } finally { @@ -36,8 +39,12 @@ async function promptForDomain() { console.log(`Using domain: ${MENTORING_DOMAIN}`) } -async function promptForAccessToken() { - accessToken = await promptQuestion('Enter access token: ') +async function promptForAuthenticatedUserToken() { + authenticatedUserToken = await promptQuestion('Enter authenticated user token: ') +} + +async function promptForAuthorization() { + authorization = await promptQuestion('Enter authorization token: ') } async function promptForAdminAuthToken() { @@ -48,22 +55,36 @@ async function promptForOrganizationId() { organizationId = await promptQuestion('Enter organization Id: ') } -async function deleteEntityType() { +async function promptForEntityTypeValues() { + return new Promise((resolve, reject) => { + rl.question('Enter entity type values(space separated): ', (answer) => { + const entityTypeValues = answer.split(' ').filter((name) => name.length > 0) + if (entityTypeValues.length > 0) { + console.log('Chosen entity type values :', entityTypeValues) + resolve(entityTypeValues) + } else { + reject(new Error('No entity type values provided.')) + } + }) + }) +} + +async function deleteEntityType(entityTypes) { try { const response = await axios.delete(`${MENTORING_DOMAIN}/mentoring/v1/entity-type/delete`, { headers: { - 'x-auth-token': `bearer ${accessToken}`, + 'x-authenticated-user-token': `${authenticatedUserToken}`, + Authorization: `bearer ${authorization}`, 'Content-Type': 'application/json', 'admin-auth-token': `${adminAuthToken}`, 'organization-id': `${organizationId}`, }, - data: JSON.stringify({ value: ['designation', 'recommended_for', 'categories', 'area_of_expertise'] }), + data: JSON.stringify({ value: entityTypes }), }) - // entityTypeId = response.data.result.id console.log(response.data.message) } catch (error) { - console.error('Entity type creation failed:', error) + console.error('Entity type deletion failed:', error) throw error } }