fix: delete team while it is active

This commit is contained in:
Andras Bacsai 2022-08-26 18:39:13 +00:00
parent 3884483bca
commit 4c5e71f33c
3 changed files with 21 additions and 3 deletions

3
.gitignore vendored
View File

@ -11,4 +11,5 @@ dist
client
apps/api/db/*.db
local-serve
apps/api/db/migration.db-journal
apps/api/db/migration.db-journal
apps/api/core*

View File

@ -158,8 +158,10 @@ export async function getTeam(request: FastifyRequest<OnlyId>, reply: FastifyRep
});
const team = await prisma.team.findUnique({ where: { id }, include: { permissions: true } });
const invitations = await prisma.teamInvitation.findMany({ where: { teamId: team.id } });
const { teams } = await prisma.user.findUnique({ where: { id: userId }, include: { teams: true } })
return {
team,
teams,
permissions,
invitations
};
@ -275,10 +277,10 @@ export async function inviteToTeam(request: FastifyRequest<InviteToTeam>, reply:
if (!userFound) {
throw {
message: `No user found with '${email}' email address.`
};
};
}
const uid = userFound.id;
if (uid === userId) {
if (uid === userId) {
throw {
message: `Invitation to yourself? Whaaaaat?`
};

View File

@ -25,18 +25,33 @@
</script>
<script lang="ts">
export let teams: any;
import { page } from '$app/stores';
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
import { appSession } from '$lib/store';
import { t } from '$lib/translations';
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
import { goto } from '$app/navigation';
import Cookies from 'js-cookie';
const { id } = $page.params;
async function deleteTeam() {
const sure = confirm('Are you sure you want to delete this team?');
if (sure) {
try {
await del(`/iam/team/${id}`, { id });
const switchTeam = teams.find((team: any) => team.id !== id)
const payload = await get(`/user?teamId=${switchTeam.id}`);
if (payload.token) {
Cookies.set('token', payload.token, {
path: '/'
});
$appSession.teamId = payload.teamId;
$appSession.userId = payload.userId;
$appSession.permission = payload.permission;
$appSession.isAdmin = payload.isAdmin;
return window.location.assign('/iam');
}
return await goto('/iam', { replaceState: true });
} catch (error) {
return errorNotification(error);