forked from bepronetwork/web-network
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bepro 1920 add marketplace filter and column to the leaderboard (#289)
* add curator overview endpoint * remove unused * introduce curator overview * update design * add network filter * adjust design and filters * add translations * add translations * adjust style * fix search * adding col-auto * adding processLeaderBoard * adding userPayments belongsTo * refactoring logic search/leaderboard * adding count logic * adjusting variables search/leaderboard * adding council translate to leaderboard page * adding two new variables to leaderBoard interface * adding truncateString helper * adjusting SelectNetwork to use fontRegular * adding networkFilter & new columns to leaderboard * adding fontRegular param to SelectNetwork * add curator overview endpoint * remove unused * introduce curator overview * update design * add network filter * adjust design and filters * add translations * add translations * adjust style * fix search * refactor to reduce loops * add space below list * use infinite loading * no need of lower case * change how we get networks * fix reading of undefined * filter chain --------- Co-authored-by: vhcsilva <[email protected]>
- Loading branch information
1 parent
fe33bca
commit d110309
Showing
10 changed files
with
114 additions
and
46 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
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,2 @@ | ||
export const truncateString = (str, limit) => | ||
str?.length > limit ? `${str.substring(0, limit)}...` : str; |
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,53 +1,78 @@ | ||
import {ParsedUrlQuery} from "querystring"; | ||
import {Op, Sequelize, WhereOptions} from "sequelize"; | ||
import { ParsedUrlQuery } from "querystring"; | ||
import { WhereOptions } from "sequelize"; | ||
|
||
import models from "db/models"; | ||
import Database from "db/models"; | ||
|
||
import paginate, {calculateTotalPages, DEFAULT_ITEMS_PER_PAGE} from "helpers/paginate"; | ||
import { DEFAULT_ITEMS_PER_PAGE, calculateTotalPages } from "helpers/paginate"; | ||
|
||
export default async function get(query: ParsedUrlQuery) { | ||
const { | ||
address, | ||
page, | ||
search, | ||
sortBy, | ||
order | ||
} = query; | ||
const { address, page, search, sortBy, order, networkName } = query; | ||
|
||
const whereCondition: WhereOptions = {}; | ||
|
||
if (address) whereCondition.address = address; | ||
|
||
const whereInclude = search ? { | ||
[Op.or]: [ | ||
{ address: { [Op.iLike]: `%${search}%` } }, | ||
{ handle: { [Op.iLike]: `%${search}%` } }, | ||
] | ||
} : {}; | ||
|
||
const PAGE = +(page || 1); | ||
const OFFSET = (PAGE - 1) * DEFAULT_ITEMS_PER_PAGE; | ||
|
||
const leaderboard = await models.leaderBoard.findAndCountAll(paginate({ | ||
attributes: { | ||
exclude: ["id"] | ||
}, | ||
where: whereCondition, | ||
include: [ | ||
{ | ||
association: "user", | ||
attributes: ["handle"], | ||
required: !!search, | ||
on: Sequelize.where(Sequelize.fn("lower", Sequelize.col("user.address")), | ||
"=", | ||
Sequelize.fn("lower", Sequelize.col("leaderboard.address"))), | ||
where: whereInclude | ||
const leaderboardQuery = ` | ||
SELECT | ||
count(*) OVER() AS "count", | ||
address, | ||
handle, | ||
COUNT(issue) AS numberNfts, | ||
array_to_string(array_agg(DISTINCT "logoIcon"), ', ') AS networksLogos, | ||
array_to_string(array_agg(DISTINCT icon), ', ') AS chainsLogos | ||
FROM ( | ||
SELECT | ||
up.address, | ||
u."handle" AS handle, | ||
i.id AS issue, | ||
n."logoIcon", | ||
c.icon | ||
FROM | ||
users_payments up | ||
INNER JOIN users u ON LOWER(u.address) = LOWER(up.address) | ||
INNER JOIN issues i ON i.id = up."issueId" | ||
INNER JOIN networks n ON n.id = i.network_id | ||
INNER JOIN chains c ON c."chainId" = i.chain_id | ||
WHERE 1 = 1 | ||
${ | ||
search | ||
? `AND ( | ||
u.address ILIKE '%${search}%' OR | ||
u."handle" ILIKE '%${search}%' | ||
)` | ||
: "" | ||
} | ||
] | ||
}, { page: PAGE }, [[sortBy || "numberNfts", order || "DESC"]])); | ||
${networkName === 'all' ? '' : networkName ? `AND n.name = LOWER('${networkName}')` : ""} | ||
${address ? `AND u.address = LOWER('${address}')` : ""} | ||
) tbl | ||
GROUP BY address, handle | ||
ORDER BY COUNT(issue) ${order ? order : "DESC"} | ||
OFFSET ${OFFSET} LIMIT ${DEFAULT_ITEMS_PER_PAGE}; | ||
`; | ||
|
||
const leaderboard = await Database.sequelize | ||
.query(leaderboardQuery, { | ||
type: Database.sequelize.QueryTypes.SELECT, | ||
}) | ||
.then((leaderboards) => { | ||
return { | ||
count: leaderboards?.length ? leaderboards[0]?.count : 0, | ||
rows: leaderboards.map((l) => ({ | ||
...l, | ||
... l?.handle ? {user: { handle: l?.handle }} : null, | ||
numberNfts: l?.numbernfts, | ||
networkslogos: l?.chainslogos?.split(", "), | ||
marketplacelogos: l?.networkslogos?.split(", "), | ||
})), | ||
}; | ||
}); | ||
|
||
return { | ||
...leaderboard, | ||
currentPage: PAGE, | ||
pages: calculateTotalPages(leaderboard.count, DEFAULT_ITEMS_PER_PAGE) | ||
pages: calculateTotalPages(leaderboard.count, DEFAULT_ITEMS_PER_PAGE), | ||
}; | ||
} |