Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment Changes for Delete EntityType #947

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/scripts/deleteEntitiesAndTypes/deleteEntitiesAndTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ 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

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 {
Expand All @@ -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() {
Expand All @@ -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
}
}
Expand Down