umami/queries/admin/teamWebsite.ts
2023-03-02 22:48:30 -08:00

48 lines
985 B
TypeScript

import { TeamWebsite } from '@prisma/client';
import { uuid } from 'lib/crypto';
import prisma from 'lib/prisma';
export async function getTeamWebsite(teamId: string, userId: string): Promise<TeamWebsite> {
return prisma.client.teamWebsite.findFirst({
where: {
teamId,
userId,
},
});
}
export async function getTeamWebsites(teamId: string): Promise<TeamWebsite[]> {
return prisma.client.teamWebsite.findMany({
where: {
teamId,
},
include: {
user: true,
website: true,
},
});
}
export async function createTeamWebsite(
userId: string,
teamId: string,
websiteId: string,
): Promise<TeamWebsite> {
return prisma.client.teamWebsite.create({
data: {
id: uuid(),
userId,
teamId,
websiteId,
},
});
}
export async function deleteTeamWebsite(teamWebsiteId: string): Promise<TeamWebsite> {
return prisma.client.teamWebsite.delete({
where: {
id: teamWebsiteId,
},
});
}