1
- import { Request , Response , Router } from 'express'
2
- import { handlerWrapper } from '../errors/AppError'
3
- import { decodeDrep } from '../helpers/validator'
1
+ import { Request , Response , Router } from 'express'
2
+ import { handlerWrapper } from '../errors/AppError'
3
+ import { decodeDrep } from '../helpers/validator'
4
4
import {
5
5
fetchDrepDetails ,
6
6
fetchDrepList ,
@@ -11,7 +11,7 @@ import {
11
11
fetchDRepActiveDelegators ,
12
12
fetchDrepLiveStats ,
13
13
} from '../repository/drep'
14
- import { DrepSortType , DrepStatusType } from '../types/drep'
14
+ import { DrepSortType , DrepStatusType } from '../types/drep'
15
15
16
16
const router = Router ( )
17
17
@@ -26,30 +26,42 @@ const getDrepList = async (req: Request, res: Response) => {
26
26
const page = req . query . page ? + req . query . page : 1
27
27
const status = req . query . status ? ( req . query . status as DrepStatusType ) : undefined
28
28
const sort = req . query . sort ? ( req . query . sort as DrepSortType ) : undefined
29
- const searchDrep = req . query . search ? decodeDrep ( req . query . search as string ) : { credential : '' , isScript : undefined }
30
- const {
31
- items,
32
- totalCount
33
- } = await fetchDrepList ( page , size , searchDrep . credential , searchDrep . isScript , status , sort )
34
- return res . status ( 200 ) . json ( { total : totalCount , page, size, items} )
29
+ const searchDrep = req . query . search
30
+ ? decodeDrep ( req . query . search as string )
31
+ : { credential : '' , isScript : undefined }
32
+ const { items, totalCount } = await fetchDrepList (
33
+ page ,
34
+ size ,
35
+ searchDrep . credential ,
36
+ searchDrep . isScript ,
37
+ status ,
38
+ sort
39
+ )
40
+ return res . status ( 200 ) . json ( { total : totalCount , page, size, items } )
35
41
}
36
42
37
43
const getDrepVoteDetails = async ( req : Request , res : Response ) => {
44
+ const size = req . query . size ? + req . query . size : 10
45
+ const page = req . query . page ? + req . query . page : 1
38
46
const dRepId = decodeDrep ( req . params . id as string )
39
- const result = await fetchDrepVoteDetails ( dRepId . credential , dRepId . isScript )
40
- return res . status ( 200 ) . json ( result )
47
+ const { totalCount , items } = await fetchDrepVoteDetails ( size , page , dRepId . credential , dRepId . isScript )
48
+ return res . status ( 200 ) . json ( { totalCount , size , page , items } )
41
49
}
42
50
43
51
const getDrepDelegationDetails = async ( req : Request , res : Response ) => {
52
+ const size = req . query . size ? + req . query . size : 10
53
+ const page = req . query . page ? + req . query . page : 1
44
54
const dRepId = decodeDrep ( req . params . id as string )
45
- const result = await fetchDrepDelegationHistory ( dRepId . credential , dRepId . isScript )
46
- return res . status ( 200 ) . json ( result )
55
+ const { items , totalCount } = await fetchDrepDelegationHistory ( size , page , dRepId . credential , dRepId . isScript )
56
+ return res . status ( 200 ) . json ( { totalCount , page , size , items } )
47
57
}
48
58
49
59
const getDrepRegistrationDetails = async ( req : Request , res : Response ) => {
60
+ const size = req . query . size ? + req . query . size : 10
61
+ const page = req . query . page ? + req . query . page : 1
50
62
const dRepId = decodeDrep ( req . params . id as string )
51
- const result = await fetchDrepRegistrationDetails ( dRepId . credential , dRepId . isScript )
52
- return res . status ( 200 ) . json ( result )
63
+ const { items , totalCount } = await fetchDrepRegistrationDetails ( size , page , dRepId . credential , dRepId . isScript )
64
+ return res . status ( 200 ) . json ( { totalCount , page , size , items } )
53
65
}
54
66
55
67
const getDrepLiveStats = async ( req : Request , res : Response ) => {
@@ -59,17 +71,27 @@ const getDrepLiveStats = async (req: Request, res: Response) => {
59
71
}
60
72
61
73
const getDrepActiveDelegators = async ( req : Request , res : Response ) => {
74
+ const size = req . query . size ? + req . query . size : 10
75
+ const page = req . query . page ? + req . query . page : 1
62
76
const dRepId = decodeDrep ( req . params . id as string )
63
77
const balance = req . query . balance === 'true'
64
- const result = await fetchDRepActiveDelegators ( dRepId . credential , dRepId . isScript , balance )
65
- return res . status ( 200 ) . json ( result )
78
+ const { items, totalCount } = await fetchDRepActiveDelegators (
79
+ size ,
80
+ page ,
81
+ dRepId . credential ,
82
+ dRepId . isScript ,
83
+ balance
84
+ )
85
+ return res . status ( 200 ) . json ( { total : totalCount , page, size, items } )
66
86
}
67
87
68
88
const getDrepLiveDelegators = async ( req : Request , res : Response ) => {
89
+ const size = req . query . size ? + req . query . size : 10
90
+ const page = req . query . page ? + req . query . page : 1
69
91
const dRepId = decodeDrep ( req . params . id as string )
70
92
const balance = req . query . balance === 'true'
71
- const liveDelegators = await fetchDrepLiveDelegators ( dRepId . credential , dRepId . isScript , balance )
72
- return res . status ( 200 ) . json ( liveDelegators )
93
+ const { totalCount , items } = await fetchDrepLiveDelegators ( size , page , dRepId . credential , dRepId . isScript , balance )
94
+ return res . status ( 200 ) . json ( { totalCount , page , size , items } )
73
95
}
74
96
75
97
router . get ( '/' , handlerWrapper ( getDrepList ) )
0 commit comments