Skip to content

Commit

Permalink
Merge pull request #443 from desci-labs/shared-info
Browse files Browse the repository at this point in the history
Update to shared collection endpoint
  • Loading branch information
hubsmoke authored Aug 15, 2024
2 parents 081f0e7 + 8710a3d commit 70d0b71
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions desci-server/src/controllers/nodes/sharedNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type SharedNode = {
published?: boolean;
dpid?: ResearchObjectV1Dpid;
publishDate?: string;
pendingVerification: boolean;
pendingContributionId?: string;
shareKey: string;
};

Expand Down Expand Up @@ -90,11 +92,33 @@ export const listSharedNodes = async (req: ListSharedNodesRequest, res: Response
'Published nodes map created successfully',
);

// Work out if any action on the shared node is required (e.g. verifying the contribution)
const contributionEntries = await prisma.nodeContribution.findMany({
where: {
deleted: false,
OR: [{ userId: user.id }, { email: user.email }, { orcid: user.orcid }],
userId: user.id,
node: {
uuid: {
in: nodeUuids,
},
},
},
include: { node: true },
});

const contributionEntryMap = contributionEntries.reduce((acc, entry) => {
acc[entry.node.uuid] = entry;
return acc;
}, {});

const filledSharedNodes = await Promise.all(
privSharedNodes.map(async (priv) => {
const { node } = priv;
const latestManifest = await getLatestManifestFromNode(node);
const publishedEntry = publishedNodesMap[node.uuid];
const contributionEntry = contributionEntryMap[node.uuid];
const pendingVerification = contributionEntry?.verified === false && contributionEntry?.denied === false;

return {
uuid: node.uuid,
Expand All @@ -105,6 +129,8 @@ export const listSharedNodes = async (req: ListSharedNodesRequest, res: Response
dpid: latestManifest.dpid,
publishDate: publishedEntry?.versions[0].time,
published: !!publishedEntry,
pendingVerification: !!pendingVerification,
...(!!pendingVerification && { pendingContributionId: contributionEntry.contributorId }),
shareKey: priv.shareId,
};
}),
Expand Down

0 comments on commit 70d0b71

Please sign in to comment.