import { JurisdictionServiceClient , JurisdictionDomainModel } from '@mds-core/mds-jurisdiction-service' ; import { parseRequest } from '@mds-core/mds-api-helpers' ; import { ApiQuery } from '@mds-core/mds-api-server' ; import { HasJurisdictionClaim } from './utils' ; import { JurisdictionApiRequest , JurisdictionApiResponse } from '../@types' ; type GetJurisdictionsRequest = JurisdictionApiRequest & ApiQuery < 'effective' > ; type GetJurisdictionsResponse = JurisdictionApiResponse < { jurisdictions : JurisdictionDomainModel [ ] ; } > ; export const GetJurisdictionsHandler = async ( req , res ) => { try { const { effective } = parseRequest ( req , { parser : Number } ) . query ( 'effective' ) ; const jurisdictions = await JurisdictionServiceClient . getJurisdictions ( { effective } ) ; const { version } = res . locals ; return res . status ( 200 ) . send ( { version , jurisdictions : jurisdictions . filter ( HasJurisdictionClaim ( res ) ) } ) ; } catch ( error ) { return res . status ( 500 ) . send ( { error } ) ; } } ;