Skip to content

Commit

Permalink
[FIX] Fix leaderboard build fail (RocketChat#170)
Browse files Browse the repository at this point in the history
fix build fail
  • Loading branch information
Dnouv committed Nov 3, 2022
1 parent 023220f commit 0b38b3e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 47 deletions.
36 changes: 18 additions & 18 deletions app/components/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,56 +61,56 @@ export function Leaderboard({ contributors, community, leaderboardSize }) {
</td>
<td scope="row" colSpan="1">
<Image
src={contributor.avatarUrl}
title={contributor.username}
alt={contributor.username}
src={contributor.attributes.avatarUrl}
title={contributor.attributes.username}
alt={contributor.attributes.username}
height={42}
width={42}
/>
</td>
<td colSpan="2">
<a href={contributor.profileUrl}>
<span>{contributor.username}</span>
<a href={contributor.attributes.profileUrl}>
<span>{contributor.attributes.username}</span>
</a>
</td>
<td
className={
contributor.openPRsNumber > 0
contributor.attributes.openPRsNumber > 0
? "d-none d-sm-table-cell"
: `${styles["disabled-link"]} d-none d-sm-table-cell`
}
colSpan="1"
>
<a
href={contributor.openPRsLink}
href={contributor.attributes.openPRsLink}
target={"blank"}
className="leader-board-link"
>
{contributor.openPRsNumber}
{contributor.attributes.openPRsNumber}
</a>
</td>
<td
className={
contributor.mergedPRsNumber > 0
contributor.attributes.mergedPRsNumber > 0
? "d-none d-sm-table-cell"
: `${styles["disabled-link"]} d-none d-sm-table-cell`
}
colSpan="1"
>
<a href={contributor.mergedPRsLink} target={"blank"}>
{contributor.mergedPRsNumber}
<a href={contributor.attributes.mergedPRsLink} target={"blank"}>
{contributor.attributes.mergedPRsNumber}
</a>
</td>
<td
className={
contributor.issuesNumber > 0
contributor.attributes.issuesNumber > 0
? "d-none d-sm-table-cell"
: `${styles["disabled-link"]} d-none d-sm-table-cell`
}
colSpan="1"
>
<a href={contributor.issuesLink} target={"blank"}>
{contributor.issuesNumber}
<a href={contributor.attributes.issuesLink} target={"blank"}>
{contributor.attributes.issuesNumber}
</a>
</td>
</tr>
Expand All @@ -127,10 +127,10 @@ export async function getLeaderboardProps(communityId, leaderboardSize) {
let communityName = null;
let communities = await fetchAPI("/communities");

communities.forEach((community) => {
if (community.communityId === communityId) {
contributors = community.contributors;
communityName = community.communityName;
communities.data.forEach((community) => {
if (community.attributes.communityId === communityId) {
contributors = community.attributes.contributors;
communityName = community.attributes.communityName;
}
});

Expand Down
36 changes: 18 additions & 18 deletions app/components/leaderboardcompact.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,56 @@ export function LeaderboardCompact({ contributors, leaderboardSize }) {
</td>
<td scope="row" colSpan="1">
<Image
src={contributor.avatarUrl}
title={contributor.username}
alt={contributor.username}
src={contributor.attributes.avatarUrl}
title={contributor.attributes.username}
alt={contributor.attributes.username}
height={42}
width={42}
/>
</td>
<td colSpan="2">
<a href={contributor.profileUrl}>
<span>{contributor.username}</span>
<a href={contributor.attributes.profileUrl}>
<span>{contributor.attributes.username}</span>
</a>
</td>
<td
className={
contributor.openPRsNumber > 0
contributor.attributes.openPRsNumber > 0
? "d-none d-sm-table-cell"
: `${styles["disabled-link"]} d-none d-sm-table-cell`
}
colSpan="1"
>
<a
href={contributor.openPRsLink}
href={contributor.attributes.openPRsLink}
target={"blank"}
className="leader-board-link"
>
{contributor.openPRsNumber}
{contributor.attributes.openPRsNumber}
</a>
</td>
<td
className={
contributor.mergedPRsNumber > 0
contributor.attributes.mergedPRsNumber > 0
? "d-none d-sm-table-cell"
: `${styles["disabled-link"]} d-none d-sm-table-cell`
}
colSpan="1"
>
<a href={contributor.mergedPRsLink} target={"blank"}>
{contributor.mergedPRsNumber}
<a href={contributor.attributes.mergedPRsLink} target={"blank"}>
{contributor.attributes.mergedPRsNumber}
</a>
</td>
<td
className={
contributor.issuesNumber > 0
contributor.attributes.issuesNumber > 0
? "d-none d-sm-table-cell"
: `${styles["disabled-link"]} d-none d-sm-table-cell`
}
colSpan="1"
>
<a href={contributor.issuesLink} target={"blank"}>
{contributor.issuesNumber}
<a href={contributor.attributes.issuesLink} target={"blank"}>
{contributor.attributes.issuesNumber}
</a>
</td>
</tr>
Expand All @@ -106,10 +106,10 @@ export async function getLeaderboardCompactProps(communityId,leaderboardSize){
let communityName = null;
let communities = await fetchAPI("/communities");

communities.forEach((community) => {
if (community.communityId === communityId) {
contributors = community.contributors;
communityName = community.communityName;
communities.data.forEach((community) => {
if (community.attributes.communityId === communityId) {
contributors = community.attributes.contributors;
communityName = community.attributes.communityName;
}
});

Expand Down
16 changes: 8 additions & 8 deletions app/lib/leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { fetchAPI } from "./api";

export const contributorList = (contributors) => {
contributors = contributors.sort((contributor1, contributor2) => {
if (contributor1.mergedPRsNumber === contributor2.mergedPRsNumber) {
if (contributor1.openPRsNumber === contributor2.openPRsNumber) {
if (contributor1.issuesNumber < contributor2.issuesNumber) {
contributors = contributors.data.sort((contributor1, contributor2) => {
if (contributor1.attributes.mergedPRsNumber === contributor2.attributes.mergedPRsNumber) {
if (contributor1.attributes.openPRsNumber === contributor2.attributes.openPRsNumber) {
if (contributor1.attributes.issuesNumber < contributor2.attributes.issuesNumber) {
return 1;
}
return -1;
}
if (contributor1.openPRsNumber < contributor2.openPRsNumber) {
if (contributor1.attributes.openPRsNumber < contributor2.attributes.openPRsNumber) {
return 1;
}
return -1;
}

if (contributor1.mergedPRsNumber < contributor2.mergedPRsNumber) {
if (contributor1.attributes.mergedPRsNumber < contributor2.attributes.mergedPRsNumber) {
return 1;
}
return -1;
Expand All @@ -26,9 +26,9 @@ export const contributorList = (contributors) => {
export const getCommunityIds = async () => {
let communities = await fetchAPI("/communities");
let paths = [];
communities.forEach((community) => {
communities.data.forEach((community) => {
paths.push({
params: { id: community.communityId },
params: { id: community.attributes.communityId },
});
});
return paths;
Expand Down
4 changes: 2 additions & 2 deletions cms/config/fetchContributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports.getCommunityContributors = async (
if (contributorCount === 0) {
await strapi
.service("api::g-so-c-contributor.g-so-c-contributor")
.create({ data: { contributor } });
.create({ data: contributor });
} else {
await strapi
.db.query("api::g-so-c-contributor.g-so-c-contributor")
Expand All @@ -64,7 +64,7 @@ module.exports.getCommunityContributors = async (
username: contributor.username,
community: community.id,
},
data: { contributor },
data: contributor,
});
}
});
Expand Down
17 changes: 16 additions & 1 deletion cms/src/api/community/controllers/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('api::community.community');
module.exports = createCoreController('api::community.community', ({ strapi }) => ({

async find(ctx) {
// some custom logic here

// Calling the default core action
const entity = await await strapi.entityService.findMany('api::community.community', {
populate: '*'
})
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);

// some more custom logic

return this.transformResponse(sanitizedEntity);
},
}));

0 comments on commit 0b38b3e

Please sign in to comment.