diff --git a/desci-server/src/controllers/nodes/sharedNodes.ts b/desci-server/src/controllers/nodes/sharedNodes.ts index 8c2d6d8ae..b8fcc10c2 100644 --- a/desci-server/src/controllers/nodes/sharedNodes.ts +++ b/desci-server/src/controllers/nodes/sharedNodes.ts @@ -18,6 +18,8 @@ export type SharedNode = { published?: boolean; dpid?: ResearchObjectV1Dpid; publishDate?: string; + pendingVerification: boolean; + pendingContributionId?: string; shareKey: string; }; @@ -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, @@ -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, }; }),