Skip to content

Commit 35ee23d

Browse files
authored
feat: extend countries endpoint (#276)
return: - consortium name - description - national coordinator deputies - outreach url - partner institutions
1 parent db3045b commit 35ee23d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

app/api/v1/countries/route.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
4747
},
4848
});
4949

50+
const national_coordinator_deputy_role = await db.role.findFirst({
51+
where: { type: "national_coordinator_deputy" },
52+
select: {
53+
id: true,
54+
},
55+
});
56+
5057
const national_representative_role = await db.role.findFirst({
5158
where: { type: "national_representative" },
5259
select: {
@@ -55,6 +62,7 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
5562
});
5663

5764
const national_coordinator_role_id = national_coordinator_role?.id;
65+
const national_coordinator_deputy_role_id = national_coordinator_deputy_role?.id;
5866
const national_representative_role_id = national_representative_role?.id;
5967

6068
const [countries, total] = await Promise.all([
@@ -63,10 +71,18 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
6371
institutions: {
6472
select: {
6573
name: true,
74+
startDate: true,
75+
endDate: true,
6676
types: true,
6777
url: true,
6878
},
6979
},
80+
outreach: {
81+
select: {
82+
type: true,
83+
url: true,
84+
},
85+
},
7086
users: {
7187
select: {
7288
name: true,
@@ -77,6 +93,7 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
7793
where: {
7894
OR: [
7995
{ roleId: { equals: national_coordinator_role_id } },
96+
{ roleId: { equals: national_coordinator_deputy_role_id } },
8097
{ roleId: { equals: national_representative_role_id } },
8198
],
8299
},
@@ -127,13 +144,38 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
127144
.map((contribution) => {
128145
return contribution.person.name.trim();
129146
});
147+
const nationalCoordinatorDeputies = country.contributions
148+
.filter((contribution) => {
149+
return contribution.role.type === "national_coordinator_deputy";
150+
})
151+
.map((contribution) => {
152+
return contribution.person.name.trim();
153+
});
130154
const nationalCoordinators = [
131155
...new Set(nationalCoordinatorUsers.concat(nationalCoordinatorPersons)),
132156
];
157+
const outreachUrl = country.outreach.find((outreach) => {
158+
return outreach.type === "national_website";
159+
})?.url;
160+
const partnerInstitutionsResult = country.institutions.filter((institution) => {
161+
return institution.types.includes("partner_institution");
162+
});
163+
164+
const partnerInstitutions = partnerInstitutionsResult.map((partnerInstitution) => {
165+
const { name, startDate, endDate, url: website } = partnerInstitution;
166+
return {
167+
name,
168+
startDate,
169+
endDate,
170+
website,
171+
};
172+
});
133173

134174
return {
135175
name: country.name,
136176
code: country.code,
177+
consortiumName: country.consortiumName,
178+
description: country.description,
137179
startDate: country.startDate,
138180
endDate: country.endDate,
139181
type: country.type,
@@ -148,6 +190,9 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
148190
urls: nationalCoordinatingInstitution.url,
149191
},
150192
nationalCoordinators,
193+
nationalCoordinatorDeputies,
194+
outreachUrl,
195+
partnerInstitutions,
151196
};
152197
});
153198

0 commit comments

Comments
 (0)