Skip to content

Instantly share code, notes, and snippets.

@mickaelw
Last active August 18, 2020 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickaelw/6d6b6ab7b4e987e005defe1d29565d40 to your computer and use it in GitHub Desktop.
Save mickaelw/6d6b6ab7b4e987e005defe1d29565d40 to your computer and use it in GitHub Desktop.
interface BookDetailsViewModel {
title: string
is_available: boolean
}
export function getBookById(dependencies: Dependencies) {
return async (req: Request, res: Response) => {
try {
const result = await dependencies
.bookInformation(req.params.id)
res.json(_mapToBookDetailsViewModel(result))
} catch (e) {
res.status(404).json(e.toString())
}
}
}
function _mapToBookDetailsViewModel(result: BookDetails): BookDetailsViewModel {
return {
title: result.title,
is_available: result.isAvailable
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment