diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/queries/prisma/report.ts | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/queries/prisma/report.ts')
| -rw-r--r-- | src/queries/prisma/report.ts | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/queries/prisma/report.ts b/src/queries/prisma/report.ts new file mode 100644 index 0000000..4a5b755 --- /dev/null +++ b/src/queries/prisma/report.ts @@ -0,0 +1,89 @@ +import { Prisma } from '@/generated/prisma/client'; +import prisma from '@/lib/prisma'; +import type { QueryFilters } from '@/lib/types'; + +import ReportFindManyArgs = Prisma.ReportFindManyArgs; + +async function findReport(criteria: Prisma.ReportFindUniqueArgs) { + return prisma.client.report.findUnique(criteria); +} + +export async function getReport(reportId: string) { + return findReport({ + where: { + id: reportId, + }, + }); +} + +export async function getReports(criteria: ReportFindManyArgs, filters: QueryFilters = {}) { + const { search } = filters; + + const where: Prisma.ReportWhereInput = { + ...criteria.where, + ...prisma.getSearchParameters(search, [ + { name: 'contains' }, + { description: 'contains' }, + { type: 'contains' }, + { + user: { + username: 'contains', + }, + }, + { + website: { + name: 'contains', + }, + }, + { + website: { + domain: 'contains', + }, + }, + ]), + }; + + return prisma.pagedQuery('report', { ...criteria, where }, filters); +} + +export async function getUserReports(userId: string, filters?: QueryFilters) { + return getReports( + { + where: { + userId, + }, + include: { + website: { + select: { + domain: true, + userId: true, + }, + }, + }, + }, + filters, + ); +} + +export async function getWebsiteReports(websiteId: string, filters: QueryFilters = {}) { + return getReports( + { + where: { + websiteId, + }, + }, + filters, + ); +} + +export async function createReport(data: Prisma.ReportUncheckedCreateInput) { + return prisma.client.report.create({ data }); +} + +export async function updateReport(reportId: string, data: any) { + return prisma.client.report.update({ where: { id: reportId }, data }); +} + +export async function deleteReport(reportId: string) { + return prisma.client.report.delete({ where: { id: reportId } }); +} |