fix: delete team while it is active
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,4 +11,5 @@ dist
|
|||||||
client
|
client
|
||||||
apps/api/db/*.db
|
apps/api/db/*.db
|
||||||
local-serve
|
local-serve
|
||||||
apps/api/db/migration.db-journal
|
apps/api/db/migration.db-journal
|
||||||
|
apps/api/core*
|
@@ -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 team = await prisma.team.findUnique({ where: { id }, include: { permissions: true } });
|
||||||
const invitations = await prisma.teamInvitation.findMany({ where: { teamId: team.id } });
|
const invitations = await prisma.teamInvitation.findMany({ where: { teamId: team.id } });
|
||||||
|
const { teams } = await prisma.user.findUnique({ where: { id: userId }, include: { teams: true } })
|
||||||
return {
|
return {
|
||||||
team,
|
team,
|
||||||
|
teams,
|
||||||
permissions,
|
permissions,
|
||||||
invitations
|
invitations
|
||||||
};
|
};
|
||||||
@@ -275,10 +277,10 @@ export async function inviteToTeam(request: FastifyRequest<InviteToTeam>, reply:
|
|||||||
if (!userFound) {
|
if (!userFound) {
|
||||||
throw {
|
throw {
|
||||||
message: `No user found with '${email}' email address.`
|
message: `No user found with '${email}' email address.`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const uid = userFound.id;
|
const uid = userFound.id;
|
||||||
if (uid === userId) {
|
if (uid === userId) {
|
||||||
throw {
|
throw {
|
||||||
message: `Invitation to yourself? Whaaaaat?`
|
message: `Invitation to yourself? Whaaaaat?`
|
||||||
};
|
};
|
||||||
|
@@ -25,18 +25,33 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
export let teams: any;
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
|
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
|
||||||
import { appSession } from '$lib/store';
|
import { appSession } from '$lib/store';
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
|
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
import Cookies from 'js-cookie';
|
||||||
const { id } = $page.params;
|
const { id } = $page.params;
|
||||||
|
|
||||||
async function deleteTeam() {
|
async function deleteTeam() {
|
||||||
const sure = confirm('Are you sure you want to delete this team?');
|
const sure = confirm('Are you sure you want to delete this team?');
|
||||||
if (sure) {
|
if (sure) {
|
||||||
try {
|
try {
|
||||||
await del(`/iam/team/${id}`, { id });
|
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 });
|
return await goto('/iam', { replaceState: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorNotification(error);
|
return errorNotification(error);
|
||||||
|
Reference in New Issue
Block a user