-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(admin-trades): Implementing API and UI #3049
Draft
doga-foton
wants to merge
5
commits into
master
Choose a base branch
from
feat/admin-trades
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de48c6f
Getting trades endpoint for the admin has been implemented
doga-foton b5bef63
unused imported dependencies have been removed
doga-foton 85fb810
Trades view has been implemented under menu item of Admin
doga-foton b61fef2
unused imported dependencies have been removed
doga-foton a77239c
exchange dependency has been fixed in user lib
doga-foton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/trade/exchange-irec/src/admin/admin-trade.controller.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,18 @@ | ||
import { BaseAdminTradeController } from '@energyweb/exchange'; | ||
import { NullOrUndefinedResultInterceptor } from '@energyweb/origin-backend-utils'; | ||
import { | ||
Controller, | ||
UseInterceptors, | ||
UsePipes, | ||
ValidationPipe | ||
} from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; | ||
import { ProductDTO, ProductFilterDTO } from '../product'; | ||
|
||
|
||
@ApiTags('admin') | ||
@ApiBearerAuth('access-token') | ||
@Controller('admin') | ||
@UseInterceptors(NullOrUndefinedResultInterceptor) | ||
@UsePipes(ValidationPipe) | ||
export class AdminTradeController extends BaseAdminTradeController<ProductDTO, ProductFilterDTO> { } |
10 changes: 10 additions & 0 deletions
10
packages/trade/exchange-irec/src/admin/admin-trade.module.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,10 @@ | ||
import { TradeModule as BaseTradeModule } from '@energyweb/exchange'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { AdminTradeController } from './admin-trade.controller'; | ||
|
||
@Module({ | ||
imports: [BaseTradeModule], | ||
controllers: [AdminTradeController] | ||
}) | ||
export class AdminTradeModule {} |
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,2 @@ | ||
export * from './admin-trade.controller'; | ||
export * from './admin-trade.module'; |
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
42 changes: 42 additions & 0 deletions
42
packages/trade/exchange/src/pods/trade/base-admin-trade.controller.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,42 @@ | ||
import { | ||
ActiveUserGuard, | ||
NullOrUndefinedResultInterceptor | ||
} from '@energyweb/origin-backend-utils'; | ||
import { | ||
Controller, | ||
Get, | ||
HttpStatus, | ||
UseGuards, | ||
UseInterceptors, | ||
UsePipes, | ||
ValidationPipe | ||
} from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
|
||
import { TradeDTO } from './trade.dto'; | ||
import { TradeService } from './trade.service'; | ||
|
||
@ApiTags('admin') | ||
@ApiBearerAuth('access-token') | ||
@Controller('admin') | ||
@UseInterceptors(NullOrUndefinedResultInterceptor) | ||
@UsePipes(ValidationPipe) | ||
export class BaseAdminTradeController<TProduct, TProductFilter> { | ||
constructor(private readonly tradeService: TradeService<TProduct, TProductFilter>) {} | ||
|
||
@UseGuards(AuthGuard(), ActiveUserGuard) | ||
@Get('trades') | ||
@ApiResponse({ status: HttpStatus.OK, type: [TradeDTO], description: 'Get all trades for Admin' }) | ||
public async getAll(): Promise<TradeDTO<TProduct>[]> { | ||
const trades = await this.tradeService.getAll(); | ||
|
||
return trades.map((trade) => | ||
TradeDTO.fromTrade( | ||
trade, | ||
trade.ask.assetId, | ||
trade.ask.product | ||
) | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
TradeDTO, | ||
useAdminTradeControllerGetAll, | ||
} from '@energyweb/exchange-irec-react-query-client'; | ||
|
||
export const useApiAdminTrades = () => { | ||
const refetchInterval = 10000; | ||
const { data, isLoading } = useAdminTradeControllerGetAll({ | ||
query: { refetchInterval }, | ||
}); | ||
const adminTrades = data ?? ([] as TradeDTO[]); | ||
|
||
return { adminTrades, isLoading }; | ||
}; |
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,3 +1,4 @@ | ||
export * from './useAdminUsersTableLogic'; | ||
export * from './useAdminUpdateUserFormLogic'; | ||
export * from './claims'; | ||
export * from './useAdminUsersTableLogic'; | ||
export * from './useAdminUpdateUserFormLogic'; | ||
export * from './claims'; | ||
export * from './trades'; |
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,86 @@ | ||
import { TradeDTO } from '@energyweb/exchange-irec-react-query-client'; | ||
import { TableComponentProps, TableRowData } from '@energyweb/origin-ui-core'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { formatDate } from '@energyweb/origin-ui-utils'; | ||
import { ComposedPublicDevice } from '@energyweb/origin-ui-user-data'; | ||
|
||
type TUseAdminTradesTableLogicArgs = { | ||
trades: TradeDTO[]; | ||
allDevices: ComposedPublicDevice[]; | ||
isLoading: boolean; | ||
}; | ||
type TUseAdminTradesTableLogic = ( | ||
args: TUseAdminTradesTableLogicArgs | ||
) => TableComponentProps<string>; | ||
type TFormatTrades = ( | ||
args: Omit<TUseAdminTradesTableLogicArgs, 'isLoading'> | ||
) => TableRowData<string>[]; | ||
|
||
type FormattedTrade = { | ||
id: string; | ||
date: string; | ||
buyer: string; | ||
seller: string; | ||
deviceName: string; | ||
volume: number; | ||
price: number; | ||
total: number; | ||
}; | ||
|
||
const formatTrades: TFormatTrades = ({ trades, allDevices }) => { | ||
const formattedTrades: FormattedTrade[] = []; | ||
|
||
trades?.forEach((trade) => { | ||
formattedTrades.push({ | ||
id: `${trade.id}`, | ||
date: formatDate(trade.created), | ||
buyer: '', | ||
seller: '', | ||
deviceName: '', | ||
volume: 0, | ||
price: 0, | ||
total: 0, | ||
}); | ||
}); | ||
|
||
// trades?.forEach((trade) => | ||
// trade.claims?.forEach((claim) => { | ||
// formattedClaims.push({ | ||
// id: `${trade.id};${claim.claimData.periodStartDate}`, | ||
// certificateId: trade.id, | ||
// deviceName: allDevices.find( | ||
// (device) => device.externalRegistryId === trade.deviceId | ||
// )?.name, | ||
// energy: PowerFormatter.format(parseInt(claim.value), true), | ||
// beneficiary: claim.claimData.beneficiary, | ||
// fromDate: formatDate(claim.claimData.periodStartDate), | ||
// toDate: formatDate(claim.claimData.periodEndDate), | ||
// }); | ||
// }) | ||
// ); | ||
|
||
return formattedTrades; | ||
}; | ||
|
||
export const useAdminTradesTableLogic: TUseAdminTradesTableLogic = ({ | ||
isLoading, | ||
trades, | ||
allDevices, | ||
}) => { | ||
const { t } = useTranslation(); | ||
return { | ||
header: { | ||
date: t('admin.trades.date'), | ||
buyer: t('admin.trades.buyer'), | ||
seller: t('admin.trades.seller'), | ||
energy: 'Energy', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't forget to localize this |
||
deviceName: t('admin.trades.device'), | ||
volume: t('admin.trades.quantity'), | ||
price: t('admin.trades.price'), | ||
total: t('admin.trades.total'), | ||
}, | ||
pageSize: 10, | ||
loading: isLoading, | ||
data: formatTrades({ trades, allDevices }), | ||
}; | ||
}; |
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
packages/ui/libs/user/view/src/pages/AdminTradesPage/AdminTradesPage.effects.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 @@ | ||
import { useFetchAllDevices, useApiAdminTrades } from '@energyweb/origin-ui-user-data'; | ||
import { useAdminTradesTableLogic } from '@energyweb/origin-ui-user-logic'; | ||
|
||
export const useAdminTradesPageEffects = () => { | ||
const { adminTrades, isLoading: areTradesLoading } = useApiAdminTrades(); | ||
const { allDevices, isLoading: areDeviceLoading } = useFetchAllDevices(); | ||
|
||
const isLoading = areDeviceLoading || areTradesLoading; | ||
|
||
const tableProps = useAdminTradesTableLogic({ | ||
trades: adminTrades, | ||
allDevices, | ||
isLoading, | ||
}); | ||
|
||
return tableProps; | ||
}; |
9 changes: 9 additions & 0 deletions
9
packages/ui/libs/user/view/src/pages/AdminTradesPage/AdminTradesPage.tsx
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,9 @@ | ||
import { TableComponent } from '@energyweb/origin-ui-core'; | ||
import React from 'react'; | ||
import { useAdminTradesPageEffects } from './AdminTradesPage.effects'; | ||
|
||
export const AdminTradesPage = () => { | ||
const tableProps = useAdminTradesPageEffects(); | ||
|
||
return <TableComponent {...tableProps} />; | ||
}; |
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 @@ | ||
export * from './AdminTradesPage'; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const formattedTrades: FormattedTrade[] = trades.map
will better fit here