umami/queries/admin/teamUser.ts

57 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-28 22:08:48 +01:00
import { Prisma, TeamUser } from '@prisma/client';
import { uuid } from 'lib/crypto';
2022-11-18 07:27:33 +01:00
import prisma from 'lib/prisma';
2022-12-07 03:36:41 +01:00
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[]> {
return prisma.client.teamUser.findMany({
where: {
teamId,
},
});
}
2022-11-18 09:27:42 +01:00
export async function createTeamUser(
userId: string,
teamId: string,
role: string,
2022-11-28 22:08:48 +01:00
): Promise<TeamUser> {
return prisma.client.teamUser.create({
data: {
id: uuid(),
userId,
teamId,
role,
2022-11-28 22:08:48 +01:00
},
});
2022-11-18 07:27:33 +01:00
}
export async function updateTeamUser(
data: Prisma.TeamUserUpdateInput,
where: Prisma.TeamUserWhereUniqueInput,
): Promise<TeamUser> {
return prisma.client.teamUser.update({
data,
where,
});
}
export async function deleteTeamUser(teamUserId: string): Promise<TeamUser> {
return prisma.client.teamUser.update({
data: {
2022-12-07 03:36:41 +01:00
deletedAt: new Date(),
2022-11-18 07:27:33 +01:00
},
where: {
id: teamUserId,
},
});
}