From cc6bd126c06423c92187bc63a7ad41b175f52470 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Thu, 28 Sep 2023 19:12:24 -0700 Subject: [PATCH] Fix relationship issue --- backend/endpoints/v1/organizations/index.js | 2 +- backend/models/organization.js | 18 ++++++++---------- frontend/src/components/Sidebar/index.tsx | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/backend/endpoints/v1/organizations/index.js b/backend/endpoints/v1/organizations/index.js index dcc7702..aec31dd 100644 --- a/backend/endpoints/v1/organizations/index.js +++ b/backend/endpoints/v1/organizations/index.js @@ -97,7 +97,7 @@ function organizationEndpoints(app) { response.sendStatus(403).end(); return; } - const organizations = await Organization.where({ id: { not: null } }); + const organizations = await Organization.where({}); response.status(200).json({ organizations, error: null }); } catch (e) { console.log(e.message, e); diff --git a/backend/models/organization.js b/backend/models/organization.js index 2e9f883..bebd64a 100644 --- a/backend/models/organization.js +++ b/backend/models/organization.js @@ -87,14 +87,13 @@ const Organization = { getWithOwner: async function (userId, clause = {}) { try { + const orgIds = ( + await OrganizationUser.where({ user_id: Number(userId) }) + ).map((record) => record.organization_id); const result = await prisma.organizations.findFirst({ where: { ...clause, - organization_users: { - every: { - user_id: Number(userId), - }, - }, + id: { in: orgIds }, }, }); return result; @@ -135,14 +134,13 @@ const Organization = { orderBy = null ) { try { + const orgIds = ( + await OrganizationUser.where({ user_id: Number(userId) }) + ).map((record) => record.organization_id); const results = await prisma.organizations.findMany({ where: { + id: { in: orgIds }, ...clause, - organization_users: { - every: { - user_id: Number(userId), - }, - }, }, ...(limit ? { take: limit } : {}), ...(orderBy ? { orderBy } : {}), diff --git a/frontend/src/components/Sidebar/index.tsx b/frontend/src/components/Sidebar/index.tsx index 3589851..2e3fab6 100644 --- a/frontend/src/components/Sidebar/index.tsx +++ b/frontend/src/components/Sidebar/index.tsx @@ -329,7 +329,7 @@ export default function Sidebar({ to={paths.organizationSettings(organization)} className={`group relative flex items-center gap-2.5 rounded-sm px-4 py-2 font-medium text-bodydark1 duration-300 ease-in-out hover:bg-graydark dark:hover:bg-meta-4 ${ (pathname === '/' || - pathname.includes('users')) && + pathname.includes('settings')) && 'bg-graydark dark:bg-meta-4' }`} >