Skip to content

Commit

Permalink
Add getStatements() to civic/statements.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieulemieux committed Nov 4, 2024
1 parent c19b91a commit b6c997e
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/civic/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ const contentMatching = ({
return records;
};

/**
* Given source & list of sourceIds, returns corresponding statements
*
* @param {ApiConnection} conn the api connection object for GraphKB
* @param {object} param1
* @param {string} param1.source the source RID
* @param {string[]} param1.sourceIds an array of sourceIds
* @returns {string[]} a list of statement RIDs
*/
const getStatements = async (conn, { source, sourceIds }) => {
const records = await conn.getRecords({
filters: {
AND: [
{ sourceId: sourceIds },
{ source },
],
},
target: 'Statement',
});
const rids = records.map(
(el) => el['@rid'],
);
return rids;
};

/**
* Given content from CIViC, try to create the GraphKB record
*
Expand Down Expand Up @@ -250,18 +275,7 @@ const deleteStatements = async (conn, { rids = [], source, sourceIds }) => {
// Get rids to delete if none provided
if (rids.length === 0) {
logger.info('Loading corresponding GraphKB statement RIDs to delete');
const records = await conn.getRecords({
filters: {
AND: [
{ sourceId: sourceIds },
{ source },
],
},
target: 'Statement',
});
rids.push(...records.map(
(el) => el['@rid'],
));
rids.push(...await getStatements(conn, { source, sourceIds }));
logger.info(`${rids.length} RIDs found`);
}

Expand All @@ -286,6 +300,7 @@ module.exports = {
contentMatching,
createStatement,
deleteStatements,
getStatements,
isMatching,
needsUpdate,
updateStatement,
Expand Down

0 comments on commit b6c997e

Please sign in to comment.