Created
August 9, 2022 22:56
-
-
Save sodiray/8b6cffe6ef651e0caf4639cc34bf0c01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { compose } from 'radash' | |
| import { useNext } from '@exobase/next' | |
| import { useService, useJsonArgs } from '@exobase/hooks' | |
| import type { Props } from '@exobase/core' | |
| import makeDatabase from 'src/database' | |
| import * as t from 'src/types' | |
| import * as mappers from 'src/view/mappers' | |
| type Args = { | |
| listingId: string | |
| } | |
| type Response = { | |
| listing: t.ListingView | |
| } | |
| const findListingEndpoint = async ({ args, services ): Promise<Response> => { | |
| const { database } = services | |
| const { listingId } = args | |
| // Database methods return model types | |
| const listing: t.Listing = await db.listings.find(listingId) | |
| // Endpoints return view types | |
| return { | |
| listing: mappers.ListingView.toView(listing) | |
| } | |
| } | |
| export default compose( | |
| useNext(), | |
| useJsonArgs(yup => ({ | |
| listingId: yup.string().required() | |
| }), | |
| useService({ | |
| db: makeDatabase() | |
| }), | |
| findListingEndpoint | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment