2023-05-29 06:37:34 +02:00
|
|
|
import { Prisma, Report } from '@prisma/client';
|
|
|
|
import prisma from 'lib/prisma';
|
|
|
|
|
|
|
|
export async function createReport(data: Prisma.ReportUncheckedCreateInput): Promise<Report> {
|
|
|
|
return prisma.client.report.create({ data });
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getReportById(reportId: string): Promise<Report> {
|
|
|
|
return prisma.client.report.findUnique({
|
|
|
|
where: {
|
|
|
|
id: reportId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-30 07:03:34 +02:00
|
|
|
export async function getUserReports(userId: string): Promise<Report[]> {
|
2023-05-29 06:37:34 +02:00
|
|
|
return prisma.client.report.findMany({
|
2023-07-30 07:03:34 +02:00
|
|
|
where: {
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getWebsiteReports(websiteId: string): Promise<Report[]> {
|
|
|
|
return prisma.client.report.findMany({
|
|
|
|
where: {
|
|
|
|
websiteId,
|
|
|
|
},
|
2023-05-29 06:37:34 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateReport(
|
2023-07-30 07:03:34 +02:00
|
|
|
reportId: string,
|
2023-05-29 06:37:34 +02:00
|
|
|
data: Prisma.ReportUpdateInput,
|
|
|
|
): Promise<Report> {
|
2023-07-30 07:03:34 +02:00
|
|
|
return prisma.client.report.update({ where: { id: reportId }, data });
|
2023-05-29 06:37:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 07:03:34 +02:00
|
|
|
export async function deleteReport(reportId: string): Promise<Report> {
|
|
|
|
return prisma.client.report.delete({ where: { id: reportId } });
|
2023-05-29 06:37:34 +02:00
|
|
|
}
|