Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Feb 15, 2024
1 parent 983e7b6 commit eb311f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
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 eb311f6

Please sign in to comment.