Skip to content

Commit

Permalink
Fix edd field name mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Nov 19, 2024
1 parent 2ecf0f0 commit c89c484
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pages/api/hold/request/[id]/edd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const { jsEnabled, ...rest } = JSON.parse(req.body)

const holdRequestResponse = await postEDDRequest({
itemId,
...rest,
itemId,
})

const { requestId } = holdRequestResponse
Expand All @@ -39,7 +39,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {

// Server side redirect in case user has JS disabled
res.redirect(
`${BASE_URL}${PATHS.HOLD_CONFIRMATION}${holdId}?pickupLocation=edd?requestId=${requestId}`
`${BASE_URL}${PATHS.HOLD_CONFIRMATION}/${holdId}?pickupLocation=edd?requestId=${requestId}`
)
} catch (error) {
const { statusText } = error as Response
Expand Down
2 changes: 1 addition & 1 deletion pages/api/hold/request/[id]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {

// Server side redirect in case user has JS disabled
res.redirect(
`${BASE_URL}${PATHS.HOLD_CONFIRMATION}${holdId}?pickupLocation=${pickupLocationFromResponse}?requestId=${requestId}`
`${BASE_URL}${PATHS.HOLD_CONFIRMATION}/${holdId}?pickupLocation=${pickupLocationFromResponse}?requestId=${requestId}`
)
} catch (error) {
const { statusText } = error as Response
Expand Down
3 changes: 2 additions & 1 deletion pages/hold/request/[id]/edd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function EDDRequestPage({
`${BASE_URL}/api/hold/request/${holdId}/edd`,
{
method: "POST",
body: JSON.stringify({ ...eddParams }),
body: JSON.stringify({ ...eddParams, jsEnabled: true }),
}
)
const responseJson = await response.json()
Expand All @@ -108,6 +108,7 @@ export default function EDDRequestPage({
return
}
const { requestId } = responseJson
console.log(responseJson)

setPageStatus(null)
setFormPosting(false)
Expand Down
19 changes: 10 additions & 9 deletions src/server/api/hold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ export async function postEDDRequest(
endingNumber,
chapter,
author,
issue,
publicationDate,
volume,
notes,
} = eddRequestParams
console.log("itemId post", itemId)

// Remove non-numeric characters from item ID
const itemIdNumeric = itemId.replace(/\D/g, "")
Expand All @@ -155,22 +157,21 @@ export async function postEDDRequest(
recordType: "i",
pickupLocation: "edd",
docDeliveryData: {
email,
startingNumber,
endingNumber,
chapter,
emailAddress: email,
startPage: startingNumber,
endPage: endingNumber,
chapterTitle: chapter,
author,
publicationDate,
date: publicationDate,
issue,
volume,
notes,
} as EDDRequestParams,
requestNotes: notes,
},
}
console.log(eddPostParams)

try {
const client = await nyplApiClient()
const eddPostResult = await client.post("/hold-requests", eddPostParams)
console.log("holdPostResult.data", eddPostResult)
const { id: requestId } = eddPostResult.data

if (!requestId) {
Expand Down
12 changes: 11 additions & 1 deletion src/types/holdPageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ export interface DiscoveryHoldPostParams {
pickupLocation?: NYPLocationKey | "edd"
numberOfCopies?: number
// TODO: make this EDD form content object
docDeliveryData?: EDDRequestParams
docDeliveryData?: {
emailAddress: string
startPage: string
endPage: string
chapterTitle: string
author?: string
date?: string
issue?: string
volume?: string
requestNotes?: string
}
}

export type EDDPageStatus = null | "failed" | "unavailable" | "invalid"
Expand Down

0 comments on commit c89c484

Please sign in to comment.