Skip to content

Commit 8650b43

Browse files
committed
refactor: change dto response
1 parent ce55856 commit 8650b43

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

src/infrastructure/clients/AuthenticationClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Account } from '@modules/authentication/domain/entities/Account'
22
import { LoginResultDto } from '@modules/authentication/presentation/dtos/LoginDto'
33
import { AccountDto } from '@modules/shared/presentation/dto/AccountDto'
4+
import { GetAccountResponseDto } from '@modules/users/presentation/dto/getAccountResponseDto'
45
import { BadRequestException, Injectable } from '@nestjs/common'
56
import * as crypto from 'node:crypto'
67
import { IAuthenticationClient } from '../../modules/shared/infrastructure/IAuthenticationClient'
@@ -55,7 +56,7 @@ export class AuthenticationClient implements IAuthenticationClient {
5556
return false
5657
}
5758

58-
async getAllAccounts(): Promise<AccountDto[]> {
59+
async getAllAccounts(): Promise<GetAccountResponseDto[]> {
5960
accounts.map((account) => {
6061
delete account.password
6162
return account
@@ -67,11 +68,12 @@ export class AuthenticationClient implements IAuthenticationClient {
6768
return accounts.find((account) => account.email === email)
6869
}
6970

70-
async getAccountById(id: string): Promise<AccountDto> {
71+
async getAccountById(id: string): Promise<GetAccountResponseDto> {
7172
const accountExists = accounts.find((account) => account.id === id)
7273
if (!accountExists) {
7374
throw new BadRequestException(ClientErrorMessages.ACCOUNT_NOT_FOUND)
7475
}
76+
delete accountExists.password
7577
return accountExists
7678
}
7779

src/modules/shared/infrastructure/IAuthenticationClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LoginResultDto } from '@modules/authentication/presentation/dtos/LoginDto'
22
import { AccountDto } from '@modules/shared/presentation/dto/AccountDto'
3+
import { GetAccountResponseDto } from '@modules/users/presentation/dto/getAccountResponseDto'
34

45
export interface ClientResult<T> {
56
status: number
@@ -10,8 +11,8 @@ export interface IAuthenticationClient {
1011
createAccount(account: AccountDto): Promise<AccountDto>
1112
login(email: string, password: string): Promise<LoginResultDto>
1213
validateLogin(loginToken: string): Promise<boolean>
13-
getAllAccounts(): Promise<AccountDto[]>
14+
getAllAccounts(): Promise<GetAccountResponseDto[]>
1415
getAccountByEmail(email: string): Promise<AccountDto>
15-
getAccountById(id: string): Promise<AccountDto>
16+
getAccountById(id: string): Promise<GetAccountResponseDto>
1617
deleteAccountByEmail(email: string): Promise<boolean>
1718
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { AccountDto } from '@modules/shared/presentation/dto/AccountDto'
1+
import { GetAccountResponseDto } from '../presentation/dto/getAccountResponseDto'
22

33
export interface IUsersService {
4-
listAllUsers(): Promise<AccountDto[]>
5-
getUserById(id: string): Promise<AccountDto>
4+
listAllUsers(): Promise<GetAccountResponseDto[]>
5+
getUserById(id: string): Promise<GetAccountResponseDto>
66
}

src/modules/users/application/UsersService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { InfrastructureInjectionList } from '@infrastructure/InfrastructureInjectionList'
2-
import { AccountDto } from '@modules/shared/presentation/dto/AccountDto'
32
import { Inject, Injectable } from '@nestjs/common'
43
import { IAuthenticationClient } from '../../shared/infrastructure/IAuthenticationClient'
4+
import { GetAccountResponseDto } from '../presentation/dto/getAccountResponseDto'
55
import { IUsersService } from './IUsersService'
66

77
@Injectable()
@@ -11,11 +11,11 @@ export class UsersService implements IUsersService {
1111
private readonly authenticationClient: IAuthenticationClient
1212
) {}
1313

14-
async listAllUsers(): Promise<AccountDto[]> {
14+
async listAllUsers(): Promise<GetAccountResponseDto[]> {
1515
return await this.authenticationClient.getAllAccounts()
1616
}
1717

18-
async getUserById(id: string): Promise<AccountDto> {
18+
async getUserById(id: string): Promise<GetAccountResponseDto> {
1919
return await this.authenticationClient.getAccountById(id)
2020
}
2121

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
export type GetAccountResponseDto = {
3+
id: string
4+
name: string
5+
email: string
6+
zipCode: string
7+
}

0 commit comments

Comments
 (0)