umami/queries/admin/team.ts

57 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-18 09:27:42 +01:00
import { Prisma, Team, TeamUser } from '@prisma/client';
2022-11-18 07:27:33 +01:00
import prisma from 'lib/prisma';
2022-11-18 09:27:42 +01:00
export async function createTeam(data: Prisma.TeamCreateInput): Promise<Team> {
2022-11-18 07:27:33 +01:00
return prisma.client.role.create({
data,
});
}
2022-11-18 09:27:42 +01:00
export async function getTeam(where: Prisma.TeamWhereUniqueInput): Promise<Team> {
2022-11-18 07:27:33 +01:00
return prisma.client.role.findUnique({
where,
});
}
2022-11-18 09:27:42 +01:00
export async function getTeams(where: Prisma.TeamWhereInput): Promise<Team[]> {
2022-11-18 07:27:33 +01:00
return prisma.client.role.findMany({
where,
});
}
export async function getTeamsByUserId(userId: string): Promise<
(TeamUser & {
team: Team;
})[]
> {
return prisma.client.teamUser.findMany({
where: {
userId,
},
include: {
team: true,
},
});
}
export async function updateTeam(
2022-11-18 09:27:42 +01:00
data: Prisma.TeamUpdateInput,
where: Prisma.TeamWhereUniqueInput,
): Promise<Team> {
2022-11-18 07:27:33 +01:00
return prisma.client.role.update({
data,
where,
});
}
2022-11-18 09:27:42 +01:00
export async function deleteTeam(teamId: string): Promise<Team> {
2022-11-18 07:27:33 +01:00
return prisma.client.role.update({
data: {
isDeleted: true,
},
where: {
id: teamId,
},
});
}