Skip to content

Commit

Permalink
Replace 'data' for 'result' in API response
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymmmy committed Jan 10, 2024
1 parent 3f6e489 commit 0d32aa8
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 103 deletions.
4 changes: 2 additions & 2 deletions packages/boutique/frontend/src/hooks/use-products-query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UseQueryResult, useQuery } from '@tanstack/react-query'
import { fetcher, APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'

export interface Product {
id: string
Expand All @@ -12,7 +12,7 @@ export interface Product {
}

export function useProductsQuery(): UseQueryResult<
SuccessReponse<Product[]>,
SuccessResponse<Product[]>,
APIError
> {
return useQuery({
Expand Down
4 changes: 2 additions & 2 deletions packages/boutique/frontend/src/lib/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FieldValues, FieldPath } from 'react-hook-form'
import { API_BASE_URL } from './constants.ts'
import { ErrorResponse, SuccessReponse } from './types.ts'
import { ErrorResponse, SuccessResponse } from './types.ts'

export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'

Expand All @@ -22,7 +22,7 @@ export class APIError<T = undefined> extends Error {
export async function fetcher<JSON = any>(
input: string,
options?: RequestInit
): Promise<SuccessReponse<JSON>> {
): Promise<SuccessResponse<JSON>> {
const response = await fetch(API_BASE_URL + input, {
credentials: 'include',
headers: {
Expand Down
2 changes: 1 addition & 1 deletion packages/boutique/frontend/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ErrorResponse {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface SuccessReponse<T = any> {
export interface SuccessResponse<T = any> {
success: true
message: string
data: T
Expand Down
10 changes: 7 additions & 3 deletions packages/wallet/backend/src/account/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class AccountController implements IAccountController {

res
.status(200)
.json({ success: true, message: 'SUCCESS', data: createAccountResult })
.json({
success: true,
message: 'SUCCESS',
result: createAccountResult
})
} catch (e) {
next(e)
}
Expand All @@ -56,7 +60,7 @@ export class AccountController implements IAccountController {

res
.status(200)
.json({ success: true, message: 'SUCCESS', data: accounts })
.json({ success: true, message: 'SUCCESS', result: accounts })
} catch (e) {
next(e)
}
Expand All @@ -78,7 +82,7 @@ export class AccountController implements IAccountController {

res
.status(200)
.json({ success: true, message: 'SUCCESS', data: getAccountsResult })
.json({ success: true, message: 'SUCCESS', result: getAccountsResult })
} catch (e) {
next(e)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/backend/src/asset/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AssetController implements IAssetController {
) => {
try {
const assets = await this.rafikiClient.listAssets({ first: 100 })
res.json({ success: true, message: 'Success', data: assets })
res.json({ success: true, message: 'Success', result: assets })
} catch (e) {
next(e)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/backend/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare global {
type BaseResponseBody<T = any> = {
success: boolean
message: string
data?: T
result?: T
errors?: Record<string, string>
}

Expand Down
8 changes: 4 additions & 4 deletions packages/wallet/backend/src/grant/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GrantController implements IGrantController {
req.session.user.id
)
const grants = await this.rafikiAuthService.listGrants(identifiers)
res.json({ success: true, message: 'Success', data: grants })
res.json({ success: true, message: 'Success', result: grants })
} catch (e) {
next(e)
}
Expand All @@ -56,7 +56,7 @@ export class GrantController implements IGrantController {
try {
const grant = await this.rafikiAuthService.getGrantById(req.params.id)

res.json({ success: true, message: 'Success', data: grant })
res.json({ success: true, message: 'Success', result: grant })
} catch (e) {
next(e)
}
Expand All @@ -74,7 +74,7 @@ export class GrantController implements IGrantController {
req.params.nonce
)

res.json({ success: true, message: 'Success', data: grant })
res.json({ success: true, message: 'Success', result: grant })
} catch (e) {
next(e)
}
Expand All @@ -97,7 +97,7 @@ export class GrantController implements IGrantController {
response
)

res.json({ success: true, message: 'Success', data: grant })
res.json({ success: true, message: 'Success', result: grant })
} catch (e) {
next(e)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/wallet/backend/src/incomingPayment/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class IncomingPaymentController implements IIncomingPaymentController {
description,
expiration
)
res.status(200).json({ success: true, message: 'SUCCESS', data: { url } })
res
.status(200)
.json({ success: true, message: 'SUCCESS', result: { url } })
} catch (e) {
next(e)
}
Expand All @@ -58,7 +60,7 @@ export class IncomingPaymentController implements IIncomingPaymentController {
await this.incomingPaymentService.getPaymentDetailsByUrl(url)
res
.status(200)
.json({ success: true, message: 'SUCCESS', data: paymentDetails })
.json({ success: true, message: 'SUCCESS', result: paymentDetails })
} catch (e) {
next(e)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/backend/src/quote/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class QuoteController implements IQuoteController {
receiver,
description
})
res.status(200).json({ success: true, message: 'SUCCESS', data: quote })
res.status(200).json({ success: true, message: 'SUCCESS', result: quote })
} catch (e) {
next(e)
}
Expand All @@ -60,7 +60,7 @@ export class QuoteController implements IQuoteController {
amount
})

res.status(200).json({ success: true, message: 'SUCCESS', data: quote })
res.status(200).json({ success: true, message: 'SUCCESS', result: quote })
} catch (e) {
next(e)
}
Expand Down
12 changes: 8 additions & 4 deletions packages/wallet/backend/src/rapyd/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class RapydController implements IRapydController {

res
.status(200)
.json({ success: true, message: 'SUCCESS', data: countryNamesResult })
.json({ success: true, message: 'SUCCESS', result: countryNamesResult })
} catch (e) {
next(e)
}
Expand All @@ -49,7 +49,11 @@ export class RapydController implements IRapydController {
await this.rapydService.getDocumentTypes(userId)
res
.status(200)
.json({ success: true, message: 'SUCCESS', data: documentTypesResult })
.json({
success: true,
message: 'SUCCESS',
result: documentTypesResult
})
} catch (e) {
next(e)
}
Expand Down Expand Up @@ -100,7 +104,7 @@ export class RapydController implements IRapydController {
res.status(200).json({
success: true,
message: 'Wallet created succesfully',
data: createWalletResponse
result: createWalletResponse
})
} catch (e) {
next(e)
Expand Down Expand Up @@ -148,7 +152,7 @@ export class RapydController implements IRapydController {
res.status(200).json({
success: true,
message: 'Wallet created succesfully',
data: verifyIdentityResponse
result: verifyIdentityResponse
})
} catch (e) {
next(e)
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/backend/src/transaction/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class TransactionController implements ITransactionController {
)
res
.status(200)
.json({ success: true, message: 'SUCCESS', data: transactions })
.json({ success: true, message: 'SUCCESS', result: transactions })
} catch (e) {
next(e)
}
Expand Down Expand Up @@ -65,7 +65,7 @@ export class TransactionController implements ITransactionController {
res.status(200).json({
success: true,
message: 'SUCCESS',
data: transactions
result: transactions
})
} catch (e) {
next(e)
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/backend/src/user/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class UserController implements IUserController {
res.json({
success: true,
message: 'User retrieved successfully',
data: {
result: {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
Expand Down Expand Up @@ -143,7 +143,7 @@ export class UserController implements IUserController {
res.json({
success: true,
message: 'Token was checked',
data: { isValid }
result: { isValid }
})
} catch (e) {
next(e)
Expand Down
12 changes: 6 additions & 6 deletions packages/wallet/backend/src/walletAddress/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class WalletAddressController implements IWalletAddressController {
})
res
.status(200)
.json({ success: true, message: 'SUCCESS', data: walletAddress })
.json({ success: true, message: 'SUCCESS', result: walletAddress })
} catch (e) {
next(e)
}
Expand All @@ -70,7 +70,7 @@ export class WalletAddressController implements IWalletAddressController {
)
res
.status(200)
.json({ success: true, message: 'SUCCESS', data: walletAddresses })
.json({ success: true, message: 'SUCCESS', result: walletAddresses })
} catch (e) {
next(e)
}
Expand All @@ -88,7 +88,7 @@ export class WalletAddressController implements IWalletAddressController {

res
.status(200)
.json({ success: true, message: 'SUCCESS', data: walletAddresses })
.json({ success: true, message: 'SUCCESS', result: walletAddresses })
} catch (e) {
next(e)
}
Expand All @@ -108,7 +108,7 @@ export class WalletAddressController implements IWalletAddressController {
res.status(200).json({
success: true,
message: 'SUCCESS',
data: externalWalletAddress
result: externalWalletAddress
})
} catch (e) {
next(e)
Expand All @@ -132,7 +132,7 @@ export class WalletAddressController implements IWalletAddressController {

res
.status(200)
.json({ success: true, message: 'SUCCESS', data: walletAddress })
.json({ success: true, message: 'SUCCESS', result: walletAddress })
} catch (e) {
next(e)
}
Expand Down Expand Up @@ -177,7 +177,7 @@ export class WalletAddressController implements IWalletAddressController {
res.status(200).json({
success: true,
message: 'Public key is successfully registered',
data: { privateKey, publicKey, keyId }
result: { privateKey, publicKey, keyId }
})
} catch (e) {
next(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ const WalletAddressCTA = () => {
return
}

if (response.data) {
const { privateKey } = response.data
if (response.result) {
const { privateKey } = response.result

generateAndDownloadFile({
content: privateKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/frontend/src/lib/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useTransactions = () => {
pagination
})
if (response.success) {
setTransactions(response.data ?? defaultState)
setTransactions(response.result ?? defaultState)
}
},
[request]
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/frontend/src/lib/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { FieldPath, FieldValues } from 'react-hook-form'
export type SuccessResponse<T = undefined> = {
message: string
success: true
data?: T
result?: T
}

export type ErrorResponse<T = undefined> = {
Expand Down
11 changes: 7 additions & 4 deletions packages/wallet/frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ export async function middleware(req: NextRequest) {
if (response.success) {
// If the user is logged in and has not completed KYC, redirect to KYC page.
if (
response.data?.needsWallet &&
response.result?.needsWallet &&
req.nextUrl.pathname !== '/kyc/personal'
) {
const url = new URL('/kyc/personal', req.url)
url.searchParams.append('next', 'proof')
return NextResponse.redirect(url)
}

if (response.data?.needsIDProof && req.nextUrl.pathname !== '/kyc/proof') {
if (
response.result?.needsIDProof &&
req.nextUrl.pathname !== '/kyc/proof'
) {
if (nextPage !== 'proof')
return NextResponse.redirect(new URL('/kyc/proof', req.url))
}

// If KYC is completed and the user tries to navigate to the page, redirect
// to homepage.
if (
!response.data?.needsIDProof &&
!response.data?.needsWallet &&
!response.result?.needsIDProof &&
!response.result?.needsWallet &&
req.nextUrl.pathname.startsWith('/kyc')
) {
return NextResponse.redirect(new URL('/', req.url))
Expand Down
14 changes: 7 additions & 7 deletions packages/wallet/frontend/src/pages/account/[accountId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ export const getServerSideProps: GetServerSideProps<{
if (
!accountResponse.success ||
!walletAddressesResponse.success ||
!accountResponse.data ||
!walletAddressesResponse.data
!accountResponse.result ||
!walletAddressesResponse.result
) {
return {
notFound: true
Expand All @@ -328,21 +328,21 @@ export const getServerSideProps: GetServerSideProps<{

let balance = 0

walletAddressesResponse.data.walletAddresses.map((pp) => {
walletAddressesResponse.result.walletAddresses.map((pp) => {
pp.url = pp.url.replace('https://', '$')
})
walletAddressesResponse.data.wmWalletAddresses.map((pp) => {
walletAddressesResponse.result.wmWalletAddresses.map((pp) => {
pp.url = pp.url.replace('https://', '$')
balance += Number(pp.incomingBalance)
})

return {
props: {
account: accountResponse.data,
allWalletAddresses: walletAddressesResponse.data,
account: accountResponse.result,
allWalletAddresses: walletAddressesResponse.result,
balance: formatAmount({
value: balance.toString(),
assetCode: accountResponse.data.assetCode,
assetCode: accountResponse.result.assetCode,
assetScale: 9
})
}
Expand Down
Loading

0 comments on commit 0d32aa8

Please sign in to comment.