Skip to content

Commit

Permalink
Decode the information we'll need to remove reviews from ORCID
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Dec 6, 2023
1 parent 605247d commit 92bf732
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/Orcid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const PeerReviewsSchema = Schema.struct({
}),
),
}),
'peer-review-summary': Schema.tuple(
Schema.struct({
'put-code': Schema.number,
}),
),
}),
),
}),
Expand Down
37 changes: 31 additions & 6 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Orcid from './Orcid.js'
import * as Users from './Users.js'
import * as Zenodo from './Zenodo.js'

const getPeerReviewsDoisForOrcidId = flow(
const getPeerReviewsForOrcidId = flow(
(user: Users.User) => Orcid.getPeerReviewsForOrcidId(user.orcidId),
Effect.flatMap(
ReadonlyArray.findFirst(
Expand All @@ -15,7 +15,11 @@ const getPeerReviewsDoisForOrcidId = flow(
Effect.map(group =>
ReadonlyArray.map(
group['peer-review-group'],
peerReview => peerReview['external-ids']['external-id'][0]['external-id-value'],
peerReview =>
({
doi: peerReview['external-ids']['external-id'][0]['external-id-value'],
id: peerReview['peer-review-summary'][0]['put-code'],
}) satisfies OrcidReview,
),
),
Effect.catchTag('NoSuchElementException', () => Effect.succeed([])),
Expand All @@ -42,18 +46,39 @@ const getPeerReviewsOnZenodoForOrcidId = flow(
Effect.map(reviews => ReadonlyArray.map(reviews.hits, review => review.doi)),
)

interface OrcidReview {
readonly doi: Doi.Doi
readonly id: number
}

const makeDecisions = ({
user,
zenodoReviews,
orcidReviews,
}: {
user: Users.User
zenodoReviews: ReadonlyArray<Doi.Doi>
orcidReviews: ReadonlyArray<Doi.Doi>
orcidReviews: ReadonlyArray<OrcidReview>
}) =>
ReadonlyArray.union(
ReadonlyArray.difference(zenodoReviews, orcidReviews).map(doi => Decision.AddReviewToProfile({ user, doi })),
ReadonlyArray.difference(orcidReviews, zenodoReviews).map(doi => Decision.RemoveReviewFromProfile({ user, doi })),
ReadonlyArray.difference(
zenodoReviews,
orcidReviews.map(review => review.doi),
).map(doi =>
Decision.AddReviewToProfile({
user,
doi,
}),
),
ReadonlyArray.difference(
orcidReviews.map(review => review.doi),
zenodoReviews,
).map(doi =>
Decision.RemoveReviewFromProfile({
user,
doi,
}),
),
)

const processUser = (user: Users.User) =>
Expand All @@ -64,7 +89,7 @@ const processUser = (user: Users.User) =>
Effect.all(
{
zenodoReviews: getPeerReviewsOnZenodoForOrcidId(user),
orcidReviews: getPeerReviewsDoisForOrcidId(user),
orcidReviews: getPeerReviewsForOrcidId(user),
},
{ concurrency: 'inherit' },
).pipe(
Expand Down

0 comments on commit 92bf732

Please sign in to comment.