Skip to content

Commit

Permalink
Push up hardcoding
Browse files Browse the repository at this point in the history
Refs #1712
  • Loading branch information
thewilkybarkid committed May 16, 2024
1 parent fda8136 commit 3b49446
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import slashes from 'connect-slashes'
import type { Doi } from 'doi-ts'
import express from 'express'
import type { Json } from 'fp-ts/Json'
import * as R from 'fp-ts/Reader'
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as TE from 'fp-ts/TaskEither'
import { apply, flow, identity, pipe } from 'fp-ts/function'
import helmet from 'helmet'
import http from 'http'
Expand Down Expand Up @@ -40,6 +42,7 @@ export type ConfigEnv = Omit<
| 'getUser'
| 'getUserOnboarding'
| 'getPreprint'
| 'getPreprintFields'
| 'getPreprintTitle'
| 'templatePage'
| 'getPreprintIdFromUuid'
Expand All @@ -66,6 +69,9 @@ const getPreprint = flow(
),
)

const getPreprintFields = (preprint: IndeterminatePreprintId) =>
preprint.value === ('10.1101/2023.06.12.544578' as Doi) ? TE.right(['13' as const, '24' as const]) : TE.right([])

const getPreprintTitle = flow(
getPreprint,
RTE.local(useStaleCache()),
Expand Down Expand Up @@ -271,6 +277,7 @@ export const app = (config: ConfigEnv) => {
getUser: withEnv(() => getUser, env),
getUserOnboarding: withEnv(getUserOnboarding, env),
getPreprint: withEnv(getPreprint, env),
getPreprintFields,
getPreprintTitle: withEnv(getPreprintTitle, env),
templatePage: withEnv(page, env),
getPreprintIdFromUuid: withEnv(getPreprintIdFromLegacyPreviewUuid, env),
Expand Down
10 changes: 10 additions & 0 deletions src/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { LanguageCode } from 'iso-639-1'
import type { Orcid } from 'orcid-id-ts'
import type { Html } from './html'
import type { PartialDate } from './time'
import type { FieldId } from './types/field'
import type { IndeterminatePreprintId, PreprintId } from './types/preprint-id'

export interface Preprint {
Expand Down Expand Up @@ -49,6 +50,10 @@ export interface GetPreprintTitleEnv {
getPreprintTitle: (id: IndeterminatePreprintId) => TE.TaskEither<'not-found' | 'unavailable', PreprintTitle>
}

export interface GetPreprintFieldsEnv {
getPreprintFields: (id: IndeterminatePreprintId) => TE.TaskEither<'not-found' | 'unavailable', ReadonlyArray<FieldId>>
}

export const doesPreprintExist = (id: IndeterminatePreprintId) =>
RTE.asksReaderTaskEither(RTE.fromTaskEitherK(({ doesPreprintExist }: DoesPreprintExistEnv) => doesPreprintExist(id)))

Expand All @@ -62,3 +67,8 @@ export const getPreprintTitle = (
id: IndeterminatePreprintId,
): RTE.ReaderTaskEither<GetPreprintTitleEnv, 'not-found' | 'unavailable', PreprintTitle> =>
RTE.asksReaderTaskEither(RTE.fromTaskEitherK(({ getPreprintTitle }) => getPreprintTitle(id)))

export const getPreprintFields = (
id: IndeterminatePreprintId,
): RTE.ReaderTaskEither<GetPreprintFieldsEnv, 'not-found' | 'unavailable', ReadonlyArray<FieldId>> =>
RTE.asksReaderTaskEither(RTE.fromTaskEitherK(({ getPreprintFields }) => getPreprintFields(id)))
17 changes: 12 additions & 5 deletions src/prereview-coar-notify/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Doi } from 'doi-ts'
import type * as F from 'fetch-fp-ts'
import type { FetchEnv } from 'fetch-fp-ts'
import * as RTE from 'fp-ts/ReaderTaskEither'
Expand All @@ -7,7 +6,7 @@ import { flow, identity, pipe } from 'fp-ts/function'
import type { LoggerEnv } from 'logger-fp-ts'
import { match } from 'ts-pattern'
import type { RecentReviewRequest } from '../home-page'
import { type GetPreprintTitleEnv, getPreprintTitle } from '../preprint'
import { type GetPreprintFieldsEnv, type GetPreprintTitleEnv, getPreprintFields, getPreprintTitle } from '../preprint'
import type { ReviewRequestPreprintId } from '../review-request'
import type { ReviewRequests } from '../review-requests-page'
import type { GenerateUuidEnv } from '../types/uuid'
Expand All @@ -34,7 +33,7 @@ export const publishToPrereviewCoarNotifyInbox = (
export const getReviewRequestsFromPrereviewCoarNotify = (
page: number,
): RTE.ReaderTaskEither<
FetchEnv & GetPreprintTitleEnv & LoggerEnv & PrereviewCoarNotifyEnv,
FetchEnv & GetPreprintFieldsEnv & GetPreprintTitleEnv & LoggerEnv & PrereviewCoarNotifyEnv,
'not-found' | 'unavailable',
ReviewRequests
> =>
Expand Down Expand Up @@ -66,8 +65,16 @@ export const getReviewRequestsFromPrereviewCoarNotify = (
),
),
),
RTE.let('fields', () =>
preprint.value === ('10.1101/2023.06.12.544578' as Doi) ? ['13' as const, '24' as const] : [],
RTE.apSW(
'fields',
pipe(
getPreprintFields(preprint),
RTE.orElseW(error =>
match(error)
.with('not-found', () => RTE.right(RA.empty))
.otherwise(RTE.left),
),
),
),
),
),
Expand Down
9 changes: 8 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ import { type OrcidApiEnv, getNameFromOrcid } from './orcid'
import type { FathomEnv, PhaseEnv, TemplatePageEnv } from './page'
import { partners } from './partners'
import { people } from './people'
import type { DoesPreprintExistEnv, GetPreprintEnv, GetPreprintTitleEnv, ResolvePreprintIdEnv } from './preprint'
import type {
DoesPreprintExistEnv,
GetPreprintEnv,
GetPreprintFieldsEnv,
GetPreprintTitleEnv,
ResolvePreprintIdEnv,
} from './preprint'
import { preprintReviews } from './preprint-reviews-page'
import {
type PrereviewCoarNotifyEnv,
Expand Down Expand Up @@ -320,6 +326,7 @@ export type RouterEnv = Keyv.AvatarStoreEnv &
ResolvePreprintIdEnv &
GenerateUuidEnv &
GetPreprintEnv &
GetPreprintFieldsEnv &
GetPreprintTitleEnv &
GetUserEnv &
GetUserOnboardingEnv &
Expand Down

0 comments on commit 3b49446

Please sign in to comment.