fix(avs): match mobile number better between LDAP and AVS
This commit is contained in:
parent
e4fa1ddd68
commit
f108c6cfec
@ -31,7 +31,7 @@ import Data.Aeson
|
||||
import Data.Aeson.Types as Aeson
|
||||
|
||||
import Utils.Postal (validPostAddressText)
|
||||
import Utils.Mail (pickValidEmail)
|
||||
import Utils.Mail (pickValidEmail, canonicalPhone)
|
||||
|
||||
|
||||
{-
|
||||
@ -557,14 +557,14 @@ _avsInfoDisplayName = lens g s
|
||||
|
||||
instance FromJSON AvsPersonInfo where
|
||||
parseJSON = withObject "AvsPersonInfo" $ \o -> AvsPersonInfo
|
||||
<$> o .: "PersonsNo" -- NOTE: PersonsNo, not PersonNo as elsewhere
|
||||
<*> o .: "FirstName"
|
||||
<*> o .: "LastName"
|
||||
<*> o .: "RampLicence"
|
||||
<*> o .:? "DateOfBirth"
|
||||
<*> o .:?! "PersonEMail"
|
||||
<*> o .:?! "PersonMobilePhoneNo"
|
||||
<*> o .:?! "InternalPersonalNo"
|
||||
<$> o .: "PersonsNo" -- NOTE: PersonsNo, not PersonNo as elsewhere
|
||||
<*> o .: "FirstName"
|
||||
<*> o .: "LastName"
|
||||
<*> o .: "RampLicence"
|
||||
<*> o .:? "DateOfBirth"
|
||||
<*> o .:?! "PersonEMail"
|
||||
<*> (o .:?! "PersonMobilePhoneNo" <&> fmap canonicalPhone)
|
||||
<*> o .:?! "InternalPersonalNo"
|
||||
|
||||
|
||||
instance ToJSON AvsPersonInfo where
|
||||
|
||||
@ -62,3 +62,35 @@ pickValidUserEmail' x y
|
||||
| validEmail' x = Just x
|
||||
| validEmail' y = Just y
|
||||
| otherwise = Nothing
|
||||
|
||||
|
||||
--------------------
|
||||
-- Telephone Utils
|
||||
|
||||
-- | normalize phone numbers
|
||||
canonicalPhone :: Text -> Text
|
||||
canonicalPhone pn
|
||||
| Just pn01 <- Text.stripPrefix "01" pn
|
||||
= german_mobile pn01
|
||||
| Just pn01 <- Text.stripPrefix "+491" pn
|
||||
= german_mobile pn01
|
||||
| Just pn00 <- Text.stripPrefix "00" pn
|
||||
= Text.cons '+' $ Text.map repl_nondigit pn00
|
||||
| Just ('0', pn0) <- Text.uncons pn
|
||||
, Just (snr, _ ) <- Text.uncons pn0
|
||||
, snr /= '0'
|
||||
, Char.isDigit snr
|
||||
= "+49 " <> Text.map repl_nondigit pn0
|
||||
| otherwise
|
||||
= Text.map repl_nondigit pn
|
||||
where
|
||||
german_mobile :: Text -> Text
|
||||
german_mobile wpx =
|
||||
let (area,endnr) = Text.splitAt 2 $ Text.filter Char.isDigit wpx
|
||||
in "+49 1" <> area <> Text.cons ' ' endnr
|
||||
|
||||
repl_nondigit :: Char -> Char
|
||||
repl_nondigit c
|
||||
| Char.isDigit c = c
|
||||
| c == '+' = '+'
|
||||
| otherwise = ' '
|
||||
|
||||
Reference in New Issue
Block a user