Skip to content

Commit 156018f

Browse files
committed
feat: contributions a contributor needs helped with
1 parent 235154b commit 156018f

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

api/src/contribution/repository.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ export class ContributionRepository {
3636
return camelCased;
3737
}
3838

39+
public async findForContributor(contributorId: string) {
40+
const statement = sql`
41+
SELECT
42+
${contributionsTable.id},
43+
${contributionsTable.title}
44+
FROM
45+
${contributionsTable}
46+
INNER JOIN
47+
${contributorsTable} ON ${contributionsTable.contributorId} = ${contributorsTable.id}
48+
WHERE
49+
${contributorsTable.id} = ${contributorId}
50+
ORDER BY
51+
${contributionsTable.updatedAt} DESC
52+
`;
53+
54+
const raw = await this.postgresService.db.execute(statement);
55+
const entries = Array.from(raw);
56+
const unStringifiedRaw = unStringifyDeep(entries);
57+
const camelCased = camelCaseObject(unStringifiedRaw);
58+
return camelCased;
59+
}
60+
3961
public async upsert(contribution: ContributionRow) {
4062
return await this.postgresService.db
4163
.insert(contributionsTable)

api/src/contributor/controller.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { Service } from "typedi";
44
import { ContributorRepository } from "./repository";
55
import { GetContributorResponse, GetContributorsResponse } from "./types";
66
import { ProjectRepository } from "src/project/repository";
7+
import { ContributionRepository } from "src/contribution/repository";
78

89
@Service()
910
@Controller("/Contributors")
1011
export class ContributorController {
1112
constructor(
1213
private readonly contributorRepository: ContributorRepository,
1314
private readonly projectRepository: ProjectRepository,
15+
private readonly contributionRepository: ContributionRepository,
1416
) {}
1517

1618
@Get("/")
@@ -24,9 +26,10 @@ export class ContributorController {
2426

2527
@Get("/:id")
2628
public async getContributor(@Param("id") id: string): Promise<GetContributorResponse> {
27-
const [contributor, projects] = await Promise.all([
29+
const [contributor, projects, contributions] = await Promise.all([
2830
this.contributorRepository.findWithStats(id),
2931
this.projectRepository.findForContributor(id),
32+
this.contributionRepository.findForContributor(id),
3033
]);
3134

3235
if (!contributor) throw new NotFoundError("Contributor not found");
@@ -35,8 +38,7 @@ export class ContributorController {
3538
contributor: {
3639
...contributor,
3740
projects,
38-
// @TODO-ZM: Add contributions
39-
// contributions,
41+
contributions,
4042
},
4143
};
4244
}

api/src/contributor/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ContributionEntity } from "@dzcode.io/models/dist/contribution";
12
import { ContributorEntity } from "@dzcode.io/models/dist/contributor";
23
import { ProjectEntity } from "@dzcode.io/models/dist/project";
34
import { GeneralResponse } from "src/app/types";
@@ -25,5 +26,6 @@ export interface GetContributorResponse extends GeneralResponse {
2526
ranking: number;
2627
}
2728
>;
29+
contributions: Array<Pick<ContributionEntity, "id" | "title" | "type">>;
2830
};
2931
}

web/src/components/locale/dictionary.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ Besides the open tasks on [/Contribute](/Contribute) page, you can also contribu
251251
en: "Contributed to projects",
252252
ar: "ساهم في المشاريع",
253253
},
254+
"contributor-needs-help": {
255+
en: "Needs help with",
256+
ar: "يحتاج مساعدة في",
257+
},
254258
"projects-title": {
255259
en: "Browse a growing list of Algerian open-source projects | DzCode i/o",
256260
ar: "تصفح قائمة المشاريع الجزائرية مفتوحة المصدر | DzCode i / o",

web/src/pages/team/contributor/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { useParams } from "react-router-dom";
44
import { Link } from "src/components/link";
55
import { Loading } from "src/components/loading";
66
import { Locale, useLocale } from "src/components/locale";
7+
import { Markdown } from "src/components/markdown";
78
import { Redirect } from "src/components/redirect";
89
import { TryAgain } from "src/components/try-again";
910
import { fetchContributorAction } from "src/redux/actions/contributor";
1011
import { useAppDispatch, useAppSelector } from "src/redux/store";
12+
import { getContributionURL } from "src/utils/contribution";
1113
import { getContributorURL } from "src/utils/contributor";
1214
import { getProjectURL } from "src/utils/project";
1315

@@ -100,6 +102,24 @@ export default function Page(): JSX.Element {
100102
</div>
101103
</>
102104
) : null}
105+
{contributor.contributions.length > 0 ? (
106+
<>
107+
<h2 className="text-lg font-bold">
108+
<Locale contributor-needs-help />
109+
</h2>
110+
<div className="flex flex-row gap-4 flex-wrap">
111+
{contributor.contributions.map((contribution, contributionIndex) => (
112+
<Link
113+
key={contributionIndex}
114+
href={getContributionURL(contribution)}
115+
className="card card-compact bg-base-200 rounded-lg p-4 w-full md:w-auto"
116+
>
117+
<Markdown content={contribution.title} />
118+
</Link>
119+
))}
120+
</div>
121+
</>
122+
) : null}
103123
</div>
104124
)}
105125
</div>

0 commit comments

Comments
 (0)