Skip to content

Commit

Permalink
feature #6 - update get products output
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeniosales committed Oct 17, 2022
1 parent c1c98c0 commit e1d3b55
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/2-business/dto/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export interface Output<T> {
message?: string
code?: string
httpCode?: number
statusCode?: number
data?: T
body?: string
headers?: any
}
2 changes: 1 addition & 1 deletion src/2-business/useCases/product/getProductsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GetProductsUseCase {

private async calculatePriceByLatestCurrentExchangeRate (products: Product[], originCurrency: CurrencyEnum, targetCurrency: CurrencyEnum | undefined): Promise<Product[]> {
const exchangeRate = await this.exchangeRateInternalService.get(originCurrency)
console.log('calculatePriceByLatestCurrentExchangeRate ::', { exchangeRate })
console.log('calculatePriceByLatestCurrentExchangeRate ::', exchangeRate)

const targetCurrencyExchangeRate = exchangeRate.rates[targetCurrency || originCurrency]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export class GetExchangeRateController extends ControllerBase<InputGetExchangeRa
console.log(`${logPrefix} :: end`)

return {
httpCode: 200,
status: 'success',
data: { exchangeRate }
statusCode: 200,
body: JSON.stringify({ exchangeRate })
}

} catch (error) {
Expand Down
12 changes: 8 additions & 4 deletions src/3-adapters/controller/product/getProductsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ export class GetProductsController extends ControllerBase<InputGetProducts, Outp
)

const products: Product[] = await getProductsUseCase.execute(input)

console.log(`${logPrefix} :: products`, products)
console.log(`${logPrefix} :: end`)

return {
httpCode: 200,
status: 'success',
data: { products }
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Methods': '*',
'Access-Control-Allow-Origin': '*'
},
statusCode: 200,
body: JSON.stringify({ products })
}

} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/4-framework/services/exchangeRateInternalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class ExchangeRateInternalService implements IExchangeRateInternalService
}
})

console.log(`${logPrefix} :: success ::`, { data: response.data })
return response.data
console.log(`${logPrefix} :: success ::`, { data: response.data.exchangeRate })
return response.data.exchangeRate
} catch (error) {
console.error(`${logPrefix} :: error ::`, error)
throw error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ describe('UpdateExchangeRateController', () => {
const response = await controller.run(inputMock)

expect(response).toEqual({
httpCode: 200,
status: 'success',
data: { exchangeRate: exchangeRateMock }
statusCode: 200,
body: JSON.stringify({ exchangeRate: exchangeRateMock })
})
})
})

0 comments on commit e1d3b55

Please sign in to comment.