fix: delete team while it is active
This commit is contained in:
parent
3884483bca
commit
4c5e71f33c
3
.gitignore
vendored
3
.gitignore
vendored
@ -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*
|
@ -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?`
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user