Skip to content

Commit

Permalink
feat: extend User interface with identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 28, 2024
1 parent dfcf7ac commit d6c8c26
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/users/domain/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export interface User {
firstName: string
lastName: string
email: string
identifier: string
affiliation?: string
}
21 changes: 21 additions & 0 deletions src/users/infrastructure/mappers/JSUserMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { User } from '@/users/domain/models/User'
import { AuthenticatedUser } from '@iqss/dataverse-client-javascript'

export class JSUserMapper {
static toUser(authenticatedUser: AuthenticatedUser): User {
return {
displayName: authenticatedUser.displayName,
persistentId: authenticatedUser.persistentUserId,
firstName: authenticatedUser.firstName,
lastName: authenticatedUser.lastName,
email: authenticatedUser.email,
affiliation: authenticatedUser.affiliation,
superuser: authenticatedUser.superuser,
identifier: this.removeAtSymbol(authenticatedUser.identifier)
}
}

static removeAtSymbol(identifier: string): string {
return identifier.startsWith('@') ? identifier.slice(1) : identifier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
deleteCurrentApiToken
} from '@iqss/dataverse-client-javascript/dist/users'
import { logout, ReadError, WriteError } from '@iqss/dataverse-client-javascript'
import { JSUserMapper } from '../mappers/JSUserMapper'

interface ApiTokenInfoPayload {
apiToken: string
Expand All @@ -20,15 +21,7 @@ export class UserJSDataverseRepository implements UserRepository {
return getCurrentAuthenticatedUser
.execute()
.then((authenticatedUser: AuthenticatedUser) => {
return {
displayName: authenticatedUser.displayName,
persistentId: authenticatedUser.persistentUserId,
firstName: authenticatedUser.firstName,
lastName: authenticatedUser.lastName,
email: authenticatedUser.email,
affiliation: authenticatedUser.affiliation,
superuser: authenticatedUser.superuser
}
return JSUserMapper.toUser(authenticatedUser)
})
.catch((error: ReadError) => {
throw error
Expand Down
6 changes: 4 additions & 2 deletions tests/component/users/domain/models/UserMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class UserMother {
lastName: 'Potts',
email: '[email protected]',
affiliation: 'Harvard University',
superuser: false
superuser: false,
identifier: 'jamespotts'
}
}
static createSuperUser(): User {
Expand All @@ -20,7 +21,8 @@ export class UserMother {
firstName: 'James',
lastName: 'Potts',
email: '[email protected]',
affiliation: 'Harvard University'
affiliation: 'Harvard University',
identifier: 'jamespotts'
}
}
}

0 comments on commit d6c8c26

Please sign in to comment.