2023-02-02 02:08:16 +01:00
|
|
|
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> {
|
2023-02-28 01:01:34 +01:00
|
|
|
return prisma.client.teamWebsite.findFirst({
|
2023-02-02 02:08:16 +01:00
|
|
|
where: {
|
|
|
|
teamId,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getTeamWebsites(teamId: string): Promise<TeamWebsite[]> {
|
2023-02-28 01:01:34 +01:00
|
|
|
return prisma.client.teamWebsite.findMany({
|
2023-02-02 02:08:16 +01:00
|
|
|
where: {
|
|
|
|
teamId,
|
|
|
|
},
|
|
|
|
include: {
|
|
|
|
user: true,
|
|
|
|
website: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function createTeamWebsite(
|
|
|
|
userId: string,
|
|
|
|
teamId: string,
|
|
|
|
websiteId: string,
|
|
|
|
): Promise<TeamWebsite> {
|
2023-02-28 01:01:34 +01:00
|
|
|
return prisma.client.teamWebsite.create({
|
2023-02-02 02:08:16 +01:00
|
|
|
data: {
|
|
|
|
id: uuid(),
|
|
|
|
userId,
|
|
|
|
teamId,
|
|
|
|
websiteId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-03 07:48:30 +01:00
|
|
|
|
|
|
|
export async function deleteTeamWebsite(teamWebsiteId: string): Promise<TeamWebsite> {
|
|
|
|
return prisma.client.teamWebsite.delete({
|
|
|
|
where: {
|
|
|
|
id: teamWebsiteId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|