import { UpdateJurisdictionDomainModel , JurisdictionServiceClient , JurisdictionDomainModel , JurisdictionIdType } from '@mds-core/mds-jurisdiction-service' ; import { isServiceError } from '@mds-core/mds-service-helpers' ; import { JurisdictionApiRequest , JurisdictionApiResponse } from '../@types' ; interface UpdateJurisdictionRequest extends JurisdictionApiRequest < { jurisdiction_id : JurisdictionIdType ; } > { body : UpdateJurisdictionDomainModel ; } type UpdateJurisdictionResponse = JurisdictionApiResponse < { jurisdiction : JurisdictionDomainModel ; } > ; export const UpdateJurisdictionHandler = async ( req , res ) => { try { const { jurisdiction_id } = req . params ; const { version } = res . locals ; const jurisdiction = await JurisdictionServiceClient . updateJurisdiction ( jurisdiction_id , req . body ) ; return res . status ( 200 ) . send ( { version , jurisdiction } ) ; } catch ( error ) { if ( isServiceError ( error ) ) { if ( error . type === 'ValidationError' ) { return res . status ( 400 ) . send ( { error } ) ; } if ( error . type === 'NotFoundError' ) { return res . status ( 404 ) . send ( { error } ) ; } if ( error . type === 'ConflictError' ) { return res . status ( 409 ) . send ( { error } ) ; } } return res . status ( 500 ) . send ( { error } ) ; } } ;