Skip to content

Instantly share code, notes, and snippets.

@sodiray
Created August 9, 2022 22:56
Show Gist options
  • Select an option

  • Save sodiray/8b6cffe6ef651e0caf4639cc34bf0c01 to your computer and use it in GitHub Desktop.

Select an option

Save sodiray/8b6cffe6ef651e0caf4639cc34bf0c01 to your computer and use it in GitHub Desktop.
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