mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
98
src/queries/admin/teamUser.ts
Normal file
98
src/queries/admin/teamUser.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import { Prisma, TeamUser } from '@prisma/client';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getTeamUserById(teamUserId: string): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.findUnique({
|
||||
where: {
|
||||
id: teamUserId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.findFirst({
|
||||
where: {
|
||||
teamId,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTeamUsers(
|
||||
teamId: string,
|
||||
): Promise<(TeamUser & { user: { id: string; username: string } })[]> {
|
||||
return prisma.client.teamUser.findMany({
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createTeamUser(
|
||||
userId: string,
|
||||
teamId: string,
|
||||
role: string,
|
||||
): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId,
|
||||
teamId,
|
||||
role,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateTeamUser(
|
||||
teamUserId: string,
|
||||
data: Prisma.TeamUserUpdateInput,
|
||||
): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.update({
|
||||
where: {
|
||||
id: teamUserId,
|
||||
},
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
||||
const { client, transaction } = prisma;
|
||||
|
||||
return transaction([
|
||||
client.teamWebsite.deleteMany({
|
||||
where: {
|
||||
teamId: teamId,
|
||||
website: {
|
||||
userId: userId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
client.teamUser.deleteMany({
|
||||
where: {
|
||||
teamId,
|
||||
userId,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
export async function deleteTeamUserByUserId(
|
||||
userId: string,
|
||||
teamId: string,
|
||||
): Promise<Prisma.BatchPayload> {
|
||||
return prisma.client.teamUser.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue