-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use get by integrator for fees * fix: only show next page url if there are more pages * test: use new api path for tests * docs: update readme with new commands
- Loading branch information
1 parent
57e2ea9
commit 8382d15
Showing
25 changed files
with
169 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/modules/fee-repository/dtos/FindByIntegratorAndPageOptionsDTO.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
interface IProps { | ||
integrator: string; | ||
limit?: number; | ||
page?: number; | ||
} | ||
|
||
export default class FindByIntegratorAndPageOptionsDTO { | ||
public readonly integrator: string; | ||
public readonly limit?: number; | ||
public readonly page?: number; | ||
|
||
constructor({ integrator, limit, page }: IProps) { | ||
this.integrator = integrator; | ||
this.limit = limit; | ||
this.page = page; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as CreateOptionsDTO } from './CreateOptionsDTO'; | ||
export { default as FindByPageOptionsDTO } from './FindByPageOptionsDTO'; | ||
export { default as FindByPageResultDTO } from './FindByPageResultDTO'; | ||
export { default as FindByIntegratorAndPageOptionsDTO } from './FindByIntegratorAndPageOptionsDTO'; | ||
export { default as FindByIntegratorAndPageResultDTO } from './FindByIntegratorAndPageResultDTO'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,67 @@ | ||
import { | ||
Controller, | ||
Get, | ||
NotFoundException, | ||
Param, | ||
Query, | ||
Req, | ||
} from '@nestjs/common'; | ||
import { ApiNotFoundResponse, ApiOkResponse } from '@nestjs/swagger'; | ||
import { Controller, Get, Param, Query, Req } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { ApiOkResponse } from '@nestjs/swagger'; | ||
import type { Request } from 'express'; | ||
|
||
// configs | ||
import { chains } from '@app/configs'; | ||
|
||
// constants | ||
import { FEE_PAGINATION_MAX_LIMIT } from '@app/constants'; | ||
|
||
// dtos | ||
import { FindByPageResultDTO } from '@app/modules/fee-repository'; | ||
import { FindByIntegratorAndPageResultDTO } from '@app/modules/fee-repository'; | ||
import { | ||
GetByChainIdOptionsDTO, | ||
GetByIntegratorOptionsDTO, | ||
GetFeesParamsDTO, | ||
GetFeesQueryDTO, | ||
GetFeesResponseBodyDTO, | ||
} from './dtos'; | ||
|
||
// enums | ||
import { APIPathEnum } from '@app/enums'; | ||
import { APIPathEnum, EnvironmentVariableKeyEnum } from '@app/enums'; | ||
|
||
// services | ||
// providers | ||
import Service from './service'; | ||
|
||
// types | ||
import type { IChainConfig } from '@app/types'; | ||
import type { IEnvironmentVariables } from '@app/types'; | ||
|
||
// utils | ||
import createChainId from '@app/utils/createChainId'; | ||
import createAPIPathPrefix from '@app/utils/createAPIPathPrefix'; | ||
|
||
@Controller(APIPathEnum.Fees) | ||
export default class FeesController { | ||
constructor(private readonly service: Service) {} | ||
constructor( | ||
private readonly configService: ConfigService<IEnvironmentVariables, true>, | ||
private readonly service: Service | ||
) {} | ||
|
||
@Get(':chainId') | ||
@Get(':integrator') | ||
@ApiOkResponse({ | ||
description: 'Gets the fees collected for a given chain.', | ||
description: 'Gets the fees collected for a given integrator.', | ||
type: GetFeesResponseBodyDTO, | ||
}) | ||
@ApiNotFoundResponse({ | ||
description: 'If the chain ID cannot be found.', | ||
}) | ||
public async getByChainId( | ||
@Param() { chainId }: GetFeesParamsDTO, | ||
public async getByIntegrator( | ||
@Param() { integrator }: GetFeesParamsDTO, | ||
@Query() query: GetFeesQueryDTO, | ||
@Req() req: Request | ||
): Promise<GetFeesResponseBodyDTO> { | ||
const chainConfig: IChainConfig | null = | ||
chains.find((value) => createChainId(value) === chainId) || null; | ||
let result: FindByPageResultDTO; | ||
|
||
if (!chainConfig) { | ||
throw new NotFoundException(`unknown chain "${chainId}"`); | ||
} | ||
|
||
result = await this.service.getByChainId( | ||
new GetByChainIdOptionsDTO({ | ||
chainId, | ||
limit: query.limit | ||
? parseInt(query.limit, 10) | ||
: FEE_PAGINATION_MAX_LIMIT, | ||
page: query.page ? parseInt(query.page, 10) : 1, | ||
}) | ||
); | ||
const result: FindByIntegratorAndPageResultDTO = | ||
await this.service.getByIntegrator( | ||
new GetByIntegratorOptionsDTO({ | ||
integrator, | ||
limit: query.limit | ||
? parseInt(query.limit, 10) | ||
: FEE_PAGINATION_MAX_LIMIT, | ||
page: query.page ? parseInt(query.page, 10) : 1, | ||
}) | ||
); | ||
|
||
return new GetFeesResponseBodyDTO({ | ||
...result, | ||
nextPageURL: `${req.protocol}://${req.get('host')}/${APIPathEnum.Fees}/${chainId}?limit=${result.limit}&page=${result.page + 1}`, | ||
// only show the next page url | ||
nextPageURL: | ||
result.total > 0 && result.page < Math.ceil(result.total / result.limit) | ||
? `${req.protocol}://${req.get('host')}/${createAPIPathPrefix(this.configService.get<string>(EnvironmentVariableKeyEnum.AppVersion))}/${APIPathEnum.Fees}/${integrator}?limit=${result.limit}&page=${result.page + 1}` | ||
: null, | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
interface IProps { | ||
integrator: string; | ||
limit: number; | ||
page: number; | ||
} | ||
|
||
export default class GetByIntegratorOptionsDTO { | ||
public readonly integrator: string; | ||
public readonly limit: number; | ||
public readonly page: number; | ||
|
||
constructor({ integrator, limit, page }: IProps) { | ||
this.integrator = integrator; | ||
this.limit = limit; | ||
this.page = page; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as GetByChainIdOptionsDTO } from './GetByChainIdOptionsDTO'; | ||
export { default as GetByIntegratorOptionsDTO } from './GetByIntegratorOptionsDTO'; | ||
export { default as GetFeesParamsDTO } from './GetFeesParamsDTO'; | ||
export { default as GetFeesQueryDTO } from './GetFeesQueryDTO'; | ||
export { default as GetFeesResponseBodyDTO } from './GetFeesResponseBodyDTO'; |
Oops, something went wrong.