Skip to content

Commit

Permalink
Merge branch 'dev' into IN-945-service-edit-page
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Feb 15, 2024
2 parents cec1366 + 2168fa0 commit 51b393f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 51 deletions.
31 changes: 15 additions & 16 deletions packages/api/router/geo/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { defineRouter, publicProcedure } from '~api/lib/trpc'
import { defineRouter, importHandler, publicProcedure } from '~api/lib/trpc'

import * as schema from './schemas'

const HandlerCache: Partial<GeoHandlerCache> = {}
const NAMESPACE = 'geo'

type GeoHandlerCache = {
autocomplete: typeof import('./query.autocomplete.handler').autocomplete
geoByPlaceId: typeof import('./query.geoByPlaceId.handler').geoByPlaceId
}
const namespaced = (s: string) => `${NAMESPACE}.${s}`

export const geoRouter = defineRouter({
autocomplete: publicProcedure.input(schema.ZAutocompleteSchema).query(async ({ ctx, input }) => {
if (!HandlerCache.autocomplete)
HandlerCache.autocomplete = await import('./query.autocomplete.handler').then((mod) => mod.autocomplete)
if (!HandlerCache.autocomplete) throw new Error('Failed to load handler')
return HandlerCache.autocomplete({ ctx, input })
autocomplete: publicProcedure.input(schema.ZAutocompleteSchema).query(async (opts) => {
const handler = await importHandler(
namespaced('autocomplete'),
() => import('./query.autocomplete.handler')
)
return handler(opts)
}),
geoByPlaceId: publicProcedure.input(schema.ZGeoByPlaceIdSchema).query(async ({ ctx, input }) => {
if (!HandlerCache.geoByPlaceId)
HandlerCache.geoByPlaceId = await import('./query.geoByPlaceId.handler').then((mod) => mod.geoByPlaceId)
if (!HandlerCache.geoByPlaceId) throw new Error('Failed to load handler')
return HandlerCache.geoByPlaceId({ ctx, input })
geoByPlaceId: publicProcedure.input(schema.ZGeoByPlaceIdSchema).query(async (opts) => {
const handler = await importHandler(
namespaced('geoByPlaceId'),
() => import('./query.geoByPlaceId.handler')
)
return handler(opts)
}),
})
1 change: 1 addition & 0 deletions packages/api/router/geo/query.autocomplete.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export const autocomplete = async ({ input }: TRPCHandlerParams<TAutocompleteSch
const parsedData = autocompleteResponse.parse(data)
return googleAPIResponseHandler(parsedData, data)
}
export default autocomplete
1 change: 1 addition & 0 deletions packages/api/router/geo/query.geoByPlaceId.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export const geoByPlaceId = async ({ input }: TRPCHandlerParams<TGeoByPlaceIdSch
const parsedData = geocodeResponse.parse(data)
return googleAPIResponseHandler(parsedData, data)
}
export default geoByPlaceId
57 changes: 22 additions & 35 deletions packages/api/router/misc/index.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
import { defineRouter, permissionedProcedure, publicProcedure } from '~api/lib/trpc'
import { defineRouter, importHandler, permissionedProcedure, publicProcedure } from '~api/lib/trpc'

import * as schema from './schemas'

const HandlerCache: Partial<MiscHandlerCache> = {}

type MiscHandlerCache = {
hasContactInfo: typeof import('./query.hasContactInfo.handler').hasContactInfo
getCountryTranslation: typeof import('./query.getCountryTranslation.handler').getCountryTranslation
forEditNavbar: typeof import('./query.forEditNavbar.handler').forEditNavbar
}
const NAMESPACE = 'misc'

const namespaced = (s: string) => `${NAMESPACE}.${s}`
export const miscRouter = defineRouter({
hasContactInfo: publicProcedure.input(schema.ZHasContactInfoSchema).query(async ({ ctx, input }) => {
if (!HandlerCache.hasContactInfo)
HandlerCache.hasContactInfo = await import('./query.hasContactInfo.handler').then(
(mod) => mod.hasContactInfo
)

if (!HandlerCache.hasContactInfo) throw new Error('Failed to load handler')
return HandlerCache.hasContactInfo({ ctx, input })
hasContactInfo: publicProcedure.input(schema.ZHasContactInfoSchema).query(async (opts) => {
const handler = await importHandler(
namespaced('hasContactInfo'),
() => import('./query.hasContactInfo.handler')
)
return handler(opts)
}),
getCountryTranslation: publicProcedure.input(schema.ZGetCountryTranslationSchema).query(async (opts) => {
const handler = await importHandler(
namespaced('getCountryTranslation'),
() => import('./query.getCountryTranslation.handler')
)
return handler(opts)
}),
getCountryTranslation: publicProcedure
.input(schema.ZGetCountryTranslationSchema)
.query(async ({ ctx, input }) => {
if (!HandlerCache.getCountryTranslation)
HandlerCache.getCountryTranslation = await import('./query.getCountryTranslation.handler').then(
(mod) => mod.getCountryTranslation
)

if (!HandlerCache.getCountryTranslation) throw new Error('Failed to load handler')
return HandlerCache.getCountryTranslation({ ctx, input })
}),
forEditNavbar: permissionedProcedure('updateLocation')
.input(schema.ZForEditNavbarSchema)
.query(async ({ ctx, input }) => {
if (!HandlerCache.forEditNavbar)
HandlerCache.forEditNavbar = await import('./query.forEditNavbar.handler').then(
(mod) => mod.forEditNavbar
)

if (!HandlerCache.forEditNavbar) throw new Error('Failed to load handler')
return HandlerCache.forEditNavbar({ ctx, input })
.query(async (opts) => {
const handler = await importHandler(
namespaced('forEditNavbar'),
() => import('./query.forEditNavbar.handler')
)
return handler(opts)
}),
})
1 change: 1 addition & 0 deletions packages/api/router/misc/query.forEditNavbar.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export const forEditNavbar = async ({ input }: TRPCHandlerParams<TForEditNavbarS
handleError(error)
}
}
export default forEditNavbar
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export const getCountryTranslation = async ({ input }: TRPCHandlerParams<TGetCou
handleError(error)
}
}
export default getCountryTranslation
1 change: 1 addition & 0 deletions packages/api/router/misc/query.hasContactInfo.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ export const hasContactInfo = async ({ input }: TRPCHandlerParams<THasContactInf
handleError(error)
}
}
export default hasContactInfo

0 comments on commit 51b393f

Please sign in to comment.