From d1e65edf43bdd32a3f340683b58a318e5c4b2941 Mon Sep 17 00:00:00 2001 From: Lautaro Dragan Date: Thu, 11 Jul 2019 02:33:43 -0300 Subject: [PATCH] feat: return isVerified in GET /accounts (#972) --- src/api/accounts/FindAccount.ts | 20 ++++++++++++++++++-- src/api/accounts/GetAccount.ts | 6 ++++-- src/api/routes.ts | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/api/accounts/FindAccount.ts b/src/api/accounts/FindAccount.ts index d03dafbaa..f5ce9fa5e 100644 --- a/src/api/accounts/FindAccount.ts +++ b/src/api/accounts/FindAccount.ts @@ -15,6 +15,7 @@ export const FindAccount = ( ) => async (ctx: any, next: any): Promise => { const logger = ctx.logger(__dirname) const { issuer } = ctx.query + const { user } = ctx.state logger.info({ issuer }, 'FindAccount') @@ -23,6 +24,21 @@ export const FindAccount = ( if (!response) throw new AccountNotFound() - const { id, email, createdAt, name, bio, ethereumAddress } = response - ctx.body = { id, email, createdAt, name, bio, ethereumAddress } + const { + id, email, verified, emailPublic, createdAt, name, bio, ethereumAddress, poeAddress, poeAddressVerified, + } = response + + const isAccountOwner = user && user.issuer === issuer + const alwaysPublicFields = { id, createdAt, name, bio, ethereumAddress, poeAddressVerified } + const alwaysPrivateFields = { poeAddress, verified } + + ctx.body = { + ...alwaysPublicFields, + ...(isAccountOwner ? { + ...alwaysPrivateFields, + email, + } : { + ...(emailPublic && { email }), + }), + } } diff --git a/src/api/accounts/GetAccount.ts b/src/api/accounts/GetAccount.ts index bd9e5c20e..74c0a75e0 100644 --- a/src/api/accounts/GetAccount.ts +++ b/src/api/accounts/GetAccount.ts @@ -22,11 +22,13 @@ export const GetAccount = (accountController: AccountController) => async (ctx: if (!response) throw new AccountNotFound() - const { id, email, emailPublic, createdAt, name, bio, ethereumAddress, poeAddress, poeAddressVerified } = response + const { + id, email, verified, emailPublic, createdAt, name, bio, ethereumAddress, poeAddress, poeAddressVerified, + } = response const isAccountOwner = user && user.issuer === issuer const alwaysPublicFields = { id, createdAt, name, bio, ethereumAddress, poeAddressVerified } - const alwaysPrivateFields = { poeAddress } + const alwaysPrivateFields = { poeAddress, verified } ctx.body = { ...alwaysPublicFields, diff --git a/src/api/routes.ts b/src/api/routes.ts index ff0deaaef..af8f8e594 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -93,6 +93,7 @@ export const routes = (accountController: AccountController, archiveController: router.get( Path.ACCOUNTS, validate(FindAccountSchema), + authentication, FindAccount(accountController), ) router.get(