Added types to database/teams

This commit is contained in:
dominicbachmann 2022-04-06 20:34:22 +02:00
parent e9e92c6e9e
commit 68f9bca054

View File

@ -1,9 +1,10 @@
import type { Team, Permission } from '@prisma/client';
import { prisma } from './common'; import { prisma } from './common';
export async function listTeams() { export async function listTeams(): Promise<Team[]> {
return await prisma.team.findMany(); return await prisma.team.findMany();
} }
export async function newTeam({ name, userId }) { export async function newTeam({ name, userId }: { name: string; userId: string }): Promise<Team> {
return await prisma.team.create({ return await prisma.team.create({
data: { data: {
name, name,
@ -12,7 +13,11 @@ export async function newTeam({ name, userId }) {
} }
}); });
} }
export async function getMyTeams({ userId }) { export async function getMyTeams({
userId
}: {
userId: string;
}): Promise<(Permission & { team: Team & { _count: { users: number } } })[]> {
return await prisma.permission.findMany({ return await prisma.permission.findMany({
where: { userId }, where: { userId },
include: { team: { include: { _count: { select: { users: true } } } } } include: { team: { include: { _count: { select: { users: true } } } } }