umami/queries/admin/teamUser.ts

63 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Prisma, TeamUser, UserRole } from '@prisma/client';
import { uuid } from 'lib/crypto';
2022-11-18 07:27:33 +01:00
import prisma from 'lib/prisma';
2022-11-18 09:27:42 +01:00
export async function createTeamUser(
userId: string,
teamId: string,
roleId: string,
): Promise<[TeamUser, UserRole]> {
const { client } = prisma;
return client.$transaction([
client.teamUser.create({
data: {
id: uuid(),
userId,
teamId,
},
}),
client.userRole.create({
data: {
id: uuid(),
userId,
teamId,
roleId,
},
}),
]);
2022-11-18 07:27:33 +01:00
}
2022-11-20 09:48:13 +01:00
export async function getTeamUser(where: Prisma.TeamUserWhereInput): Promise<TeamUser> {
return prisma.client.teamUser.findFirst({
2022-11-18 07:27:33 +01:00
where,
});
}
export async function getTeamUsers(where: Prisma.TeamUserWhereInput): Promise<TeamUser[]> {
return prisma.client.teamUser.findMany({
where,
});
}
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: {
isDeleted: true,
},
where: {
id: teamUserId,
},
});
}