delete profile from TerminusX when clicking delete
This commit is contained in:
parent
56671bdae2
commit
4d8e668c51
|
|
@ -43,7 +43,7 @@ type KeyValuePair = [string, unknown];
|
||||||
let Name = '';
|
let Name = '';
|
||||||
let hasCredential = {};
|
let hasCredential = {};
|
||||||
let cid
|
let cid
|
||||||
let primary_url, profileImage, Description
|
let primary_url, profileImage, Description, terminusID
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await client.connect()
|
await client.connect()
|
||||||
|
|
@ -66,7 +66,7 @@ type KeyValuePair = [string, unknown];
|
||||||
const jsonObjects = await getJSONFromWNFS()
|
const jsonObjects = await getJSONFromWNFS()
|
||||||
console.log("jsonObjects", jsonObjects)
|
console.log("jsonObjects", jsonObjects)
|
||||||
// Find the JSON object with the username "tester"
|
// Find the JSON object with the username "tester"
|
||||||
const usernameJSONObject = jsonObjects.find(obj => obj.name === 'tester')
|
const usernameJSONObject = jsonObjects.find(obj => obj.name === username)
|
||||||
|
|
||||||
// Log the CID of the "username.json" file to the console
|
// Log the CID of the "username.json" file to the console
|
||||||
cid = usernameJSONObject ? usernameJSONObject.cid : null
|
cid = usernameJSONObject ? usernameJSONObject.cid : null
|
||||||
|
|
@ -156,7 +156,7 @@ type KeyValuePair = [string, unknown];
|
||||||
const jsonObjects = await getJSONFromWNFS()
|
const jsonObjects = await getJSONFromWNFS()
|
||||||
console.log(jsonObjects)
|
console.log(jsonObjects)
|
||||||
// Find the JSON object with the username "tester"
|
// Find the JSON object with the username "tester"
|
||||||
const usernameJSONObject = jsonObjects.find(obj => obj.name === 'tester')
|
const usernameJSONObject = jsonObjects.find(obj => obj.name === username)
|
||||||
|
|
||||||
// Log the CID of the "username.json" file to the console
|
// Log the CID of the "username.json" file to the console
|
||||||
cid = usernameJSONObject ? usernameJSONObject.cid : null
|
cid = usernameJSONObject ? usernameJSONObject.cid : null
|
||||||
|
|
@ -214,31 +214,36 @@ type KeyValuePair = [string, unknown];
|
||||||
console.log("added document", result)
|
console.log("added document", result)
|
||||||
const addedID = extractPersonId(String(result))
|
const addedID = extractPersonId(String(result))
|
||||||
const queryTemplate = { "@id": addedID }
|
const queryTemplate = { "@id": addedID }
|
||||||
const terminusperson = await client.getDocument({ type: 'person', as_list: true, query: queryTemplate });
|
const terminusperson = await client.getDocument({ type: 'person', as_list: true, query: queryTemplate });
|
||||||
console.log("result ", terminusperson);
|
console.log("result ", terminusperson);
|
||||||
const real_id: string = terminusperson[0]['@id'];
|
const real_id: string = terminusperson[0]['@id'];
|
||||||
const num_id: string = real_id.split('/').pop() || '';
|
terminusID = real_id
|
||||||
|
console.log("terminusID", terminusID)
|
||||||
|
const num_id: string = real_id.split('/').pop() || '';
|
||||||
|
|
||||||
// Create a new object without the '@id' key
|
// Create a new object without the '@id' key
|
||||||
const newDocument: Document = Object.entries(terminusperson[0])
|
const newDocument: Document = Object.entries(terminusperson[0])
|
||||||
.filter(([key]) => key !== '@id')
|
.filter(([key]) => key !== '@id')
|
||||||
.reduce<Document>((acc, [key, value]: KeyValuePair) => {
|
.reduce<Document>((acc, [key, value]: KeyValuePair) => {
|
||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Update the document with the new 'id'
|
// Update the document with the new 'id'
|
||||||
newDocument['id'] = num_id;
|
newDocument['id'] = num_id;
|
||||||
|
|
||||||
const newDocumentsArray = [newDocument];
|
const newDocumentsArray = [newDocument];
|
||||||
|
|
||||||
const searchResult = await index.addDocuments(newDocumentsArray);
|
const searchResult = await index.addDocuments(newDocumentsArray);
|
||||||
console.log("searchResult", searchResult)
|
console.log("searchResult", searchResult)
|
||||||
} else{
|
} else{
|
||||||
console.log('adding doc')
|
console.log('adding doc')
|
||||||
const addedPerson = await client.addDocument(entryObj);
|
const addedPerson = await client.addDocument(entryObj);
|
||||||
console.log("added document", addedPerson)
|
console.log("added document", addedPerson)
|
||||||
addNotification(`profile has been added to knowledge graph`, 'success')
|
addNotification(`profile has been added to knowledge graph`, 'success')
|
||||||
|
const addedID = extractPersonId(String(addedPerson))
|
||||||
|
terminusID = addedID
|
||||||
|
console.log("terminusID", terminusID)
|
||||||
}
|
}
|
||||||
const entries2 = await client.getDocument({"graph_type":"instance","as_list":true,"type":"person"})
|
const entries2 = await client.getDocument({"graph_type":"instance","as_list":true,"type":"person"})
|
||||||
console.log(entries2);
|
console.log(entries2);
|
||||||
|
|
@ -260,6 +265,12 @@ const searchResult = await index.addDocuments(newDocumentsArray);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
console.log("deleting", terminusID);
|
||||||
|
|
||||||
|
const deleted = await client.deleteDocument({id:terminusID});
|
||||||
|
if (deleted){
|
||||||
|
addNotification(`profile has been deleted from knowledge graph`, 'success')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue