Skip to content
Merged
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
12 changes: 11 additions & 1 deletion src/charityNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ const lookupFromPdcCommand: CommandModule<unknown, LookupFromPdcCommandArgs> = {
apiKey,
validEins,
);
if (!charityNavResponse.data) {
Comment thread
bickelj marked this conversation as resolved.
logger.warn('No data found');
return;
}
if (args.outputFile) {
await writeFile(
args.outputFile,
Expand All @@ -299,6 +303,12 @@ const lookupFromPdcCommand: CommandModule<unknown, LookupFromPdcCommandArgs> = {
logger.info(`Wrote CharityNavigator data for ${JSON.stringify(args.ein)} to ${JSON.stringify(args.outputFile)}`);
} else {
logger.info({ charityNavResponse }, 'CharityNavigator result');
const { edges } = charityNavResponse.data.nonprofitsPublic;
const nonprofits = edges.filter((e): e is NonprofitPublic => isNonprofitPublic(e));
const changemakerIds = nonprofits.map(
Comment thread
bickelj marked this conversation as resolved.
(e) => getChangemakerByEin(e.ein, changemakers),
).filter((c) => c !== null).map((c) => c.id);
logger.info({ changemakerIds }, 'Changemaker IDs present in CharityNavigator');
}
},
};
Expand Down Expand Up @@ -374,7 +384,7 @@ const updateAllCommand: CommandModule<unknown, UpdateAllCommandArgs> = {
// Third, register a batch of changemaker fields to be posted
const fieldBatch = await postChangemakerFieldValueBatch(args.pdcApiBaseUrl, token, { sourceId: source.id, notes: `data-scripts charityNavigator.ts execution ${Date.now()}` });
// Last, for each nonprofit, for each field, post the field
edges.map(async (e) => {
nonprofits.map(async (e) => {
const changemaker = getChangemakerByEin(e.ein, changemakers);
if (changemaker !== null) {
Object.entries(baseFieldMap).map(async ([cnAttributeName, baseFieldShortCode]) => {
Expand Down