Endpoint getCustomersForCurrentUserAtBank v3.1.0 rewritten in new style

This commit is contained in:
Marko Milić 2019-10-09 10:43:31 +02:00
parent 5f32a1fb99
commit 705aab322a
2 changed files with 9 additions and 6 deletions

View File

@ -59,6 +59,7 @@ object NewStyle {
(nameOf(Implementations2_0_0.addKycStatus), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.addKycCheck), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_1_0.getRoles), ApiVersion.v3_1_0.toString),
(nameOf(Implementations2_1_0.getCustomersForCurrentUserAtBank), ApiVersion.v3_1_0.toString),
(nameOf(Implementations2_2_0.config), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getViewsForBankAccount), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getCurrentFxRate), ApiVersion.v2_2_0.toString),

View File

@ -1485,14 +1485,16 @@ trait APIMethods210 {
case "banks" :: BankId(bankId) :: "customers" :: Nil JsonGet _ => {
cc => {
for {
u <- cc.user ?~! UserNotLoggedIn
(bank, callContext ) <- BankX(bankId, Some(cc)) ?~! {BankNotFound}
customers <- tryo{CustomerX.customerProvider.vend.getCustomersByUserId(u.userId)} ?~! UserCustomerLinksNotFoundForUser
// Filter so we only see the ones for the bank in question
bankCustomers = customers.filter(_.bankId==bankId.value)
(Full(u), callContext) <- authorizedAccess(cc)
(_, callContext) <- NewStyle.function.getBank(bankId, callContext)
(customers, callContext) <- Connector.connector.vend.getCustomersByUserId(u.userId, callContext) map {
connectorEmptyResponse(_, callContext)
}
} yield {
// Filter so we only see the ones for the bank in question
val bankCustomers = customers.filter(_.bankId==bankId.value)
val json = JSONFactory210.createCustomersJson(bankCustomers)
successJsonResponse(Extraction.decompose(json))
(json, HttpCode.`200`(callContext))
}
}
}