Skip to content

Commit

Permalink
feat: return isVerified in GET /accounts (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarodragan authored Jul 11, 2019
1 parent 2ec6042 commit d1e65ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/api/accounts/FindAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const FindAccount = (
) => async (ctx: any, next: any): Promise<any> => {
const logger = ctx.logger(__dirname)
const { issuer } = ctx.query
const { user } = ctx.state

logger.info({ issuer }, 'FindAccount')

Expand All @@ -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 }),
}),
}
}
6 changes: 4 additions & 2 deletions src/api/accounts/GetAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const routes = (accountController: AccountController, archiveController:
router.get(
Path.ACCOUNTS,
validate(FindAccountSchema),
authentication,
FindAccount(accountController),
)
router.get(
Expand Down

0 comments on commit d1e65ed

Please sign in to comment.