mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 14:47:14 +01:00
Hook up teamMemberDelete and teamDelete.
This commit is contained in:
parent
c3426a67ee
commit
701bde53b7
7 changed files with 150 additions and 21 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Prisma, Team } from '@prisma/client';
|
||||
import cache from 'lib/cache';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import prisma from 'lib/prisma';
|
||||
import { Website, User, Roles } from 'lib/types';
|
||||
|
||||
|
|
@ -134,6 +135,19 @@ export async function deleteUser(
|
|||
websiteIds = websites.map(a => a.id);
|
||||
}
|
||||
|
||||
const teams = await client.team.findMany({
|
||||
where: {
|
||||
teamUser: {
|
||||
some: {
|
||||
userId,
|
||||
role: ROLES.teamOwner,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const teamIds = teams.map(a => a.id);
|
||||
|
||||
return prisma
|
||||
.transaction([
|
||||
client.websiteEvent.deleteMany({
|
||||
|
|
@ -144,21 +158,39 @@ export async function deleteUser(
|
|||
}),
|
||||
client.teamWebsite.deleteMany({
|
||||
where: {
|
||||
website: {
|
||||
userId,
|
||||
OR: [
|
||||
{
|
||||
websiteId: {
|
||||
in: websiteIds,
|
||||
},
|
||||
},
|
||||
{
|
||||
teamId: {
|
||||
in: teamIds,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
client.teamWebsite.deleteMany({
|
||||
where: {
|
||||
teamId: {
|
||||
in: teamIds,
|
||||
},
|
||||
},
|
||||
}),
|
||||
client.teamUser.deleteMany({
|
||||
where: {
|
||||
team: {
|
||||
userId,
|
||||
teamId: {
|
||||
in: teamIds,
|
||||
},
|
||||
},
|
||||
}),
|
||||
client.team.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
id: {
|
||||
in: teamIds,
|
||||
},
|
||||
},
|
||||
}),
|
||||
cloudMode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue