From ce2757f514669f6220e1ddeb37d10c002630948f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 13 Apr 2022 21:06:22 +0200 Subject: [PATCH] fix: Teams view --- src/routes/iam/index.json.ts | 15 +++++--- src/routes/iam/index.svelte | 72 ++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/routes/iam/index.json.ts b/src/routes/iam/index.json.ts index fa44e55ba..6ff142eb3 100644 --- a/src/routes/iam/index.json.ts +++ b/src/routes/iam/index.json.ts @@ -13,20 +13,25 @@ export const get: RequestHandler = async (event) => { select: { id: true, email: true, teams: true } }); let accounts = []; + let allTeams = []; if (teamId === '0') { accounts = await db.prisma.user.findMany({ select: { id: true, email: true, teams: true } }); + allTeams = await db.prisma.team.findMany({ + where: { users: { none: { id: userId } } }, + include: { permissions: true } + }); } - - const teams = await db.prisma.permission.findMany({ - where: { userId: teamId === '0' ? undefined : userId }, - include: { team: { include: { _count: { select: { users: true } } } } } + const ownTeams = await db.prisma.team.findMany({ + where: { users: { some: { id: userId } } }, + include: { permissions: true } }); const invitations = await db.prisma.teamInvitation.findMany({ where: { uid: userId } }); return { status: 200, body: { - teams, + ownTeams, + allTeams, invitations, account, accounts diff --git a/src/routes/iam/index.svelte b/src/routes/iam/index.svelte index 1ebfaac60..7590385cf 100644 --- a/src/routes/iam/index.svelte +++ b/src/routes/iam/index.svelte @@ -36,18 +36,8 @@ if (accounts.length === 0) { accounts.push(account); } - export let teams; - - const ownTeams = teams.filter((team) => { - if (team.team.id === $session.teamId) { - return team; - } - }); - const otherTeams = teams.filter((team) => { - if (team.team.id !== $session.teamId) { - return team; - } - }); + export let ownTeams; + export let allTeams; async function resetPassword(id) { const sure = window.confirm('Are you sure you want to reset the password?'); @@ -167,49 +157,51 @@
Teams