Skip to content

Commit

Permalink
fix: adapt frontend to the new database structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-escience committed Sep 9, 2022
1 parent 27f7851 commit 63a1092
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions database/100-create-api-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ BEGIN
RETURN QUERY
SELECT
project_for_organisation.organisation,
COUNT(*) AS project_cnt
COUNT(DISTINCT project) AS project_cnt
FROM
project_for_organisation
WHERE
Expand All @@ -347,7 +347,7 @@ BEGIN
RETURN QUERY
SELECT
project_for_organisation.organisation,
COUNT(*) AS project_cnt
COUNT(DISTINCT project) AS project_cnt
FROM
project_for_organisation
GROUP BY project_for_organisation.organisation;
Expand Down Expand Up @@ -496,7 +496,7 @@ CREATE FUNCTION projects_by_organisation(organisation_id UUID) RETURNS TABLE (
$$
BEGIN
RETURN QUERY
SELECT
SELECT DISTINCT ON (project.id)
project.id,
project.slug,
project.title,
Expand Down
3 changes: 3 additions & 0 deletions frontend/components/projects/edit/organisations/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2022 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 dv4all
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -143,6 +145,7 @@ export default function ProjectOrganisations({slug}: { slug: string }) {
const resp = await deleteOrganisationFromProject({
project: project.id,
organisation: organisation.id,
role: 'participating',
token: session.token
})
if (resp.status === 200) {
Expand Down
9 changes: 4 additions & 5 deletions frontend/utils/editProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export async function updateProjectInfo({project, projectLinks, projectImage, fu
deleteOrganisationFromProject({
project: item.project,
organisation: item.organisation,
role: 'funding',
token: session.token
})
)
Expand Down Expand Up @@ -452,8 +453,6 @@ export async function addOrganisationToProject({project, organisation, role, ses
method: 'POST',
headers: {
...createJsonHeaders(session.token),
// this will add new items and update existing
'Prefer': 'resolution=merge-duplicates'
},
body: JSON.stringify({
project,
Expand Down Expand Up @@ -503,11 +502,11 @@ export async function patchProjectForOrganisation({project, organisation, data,
}
}

export async function deleteOrganisationFromProject({project,organisation,token}:
{ project: string, organisation:string, token:string }) {
export async function deleteOrganisationFromProject({project, organisation, role, token}:
{ project: string, organisation:string, role: OrganisationRole, token:string }) {
try {
// POST
const url = `/api/v1/project_for_organisation?project=eq.${project}&organisation=eq.${organisation}`
const url = `/api/v1/project_for_organisation?project=eq.${project}&organisation=eq.${organisation}&role=eq.${role}`
const resp = await fetch(url, {
method: 'DELETE',
headers: {
Expand Down

0 comments on commit 63a1092

Please sign in to comment.