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/link.ts | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/queries/prisma/link.ts')
| -rw-r--r-- | src/queries/prisma/link.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/queries/prisma/link.ts b/src/queries/prisma/link.ts new file mode 100644 index 0000000..9b971de --- /dev/null +++ b/src/queries/prisma/link.ts @@ -0,0 +1,66 @@ +import type { Prisma } from '@/generated/prisma/client'; +import prisma from '@/lib/prisma'; +import type { QueryFilters } from '@/lib/types'; + +export async function findLink(criteria: Prisma.LinkFindUniqueArgs) { + return prisma.client.link.findUnique(criteria); +} + +export async function getLink(linkId: string) { + return findLink({ + where: { + id: linkId, + }, + }); +} + +export async function getLinks(criteria: Prisma.LinkFindManyArgs, filters: QueryFilters = {}) { + const { search } = filters; + const { getSearchParameters, pagedQuery } = prisma; + + const where: Prisma.LinkWhereInput = { + ...criteria.where, + ...getSearchParameters(search, [ + { name: 'contains' }, + { url: 'contains' }, + { slug: 'contains' }, + ]), + }; + + return pagedQuery('link', { ...criteria, where }, filters); +} + +export async function getUserLinks(userId: string, filters?: QueryFilters) { + return getLinks( + { + where: { + userId, + deletedAt: null, + }, + }, + filters, + ); +} + +export async function getTeamLinks(teamId: string, filters?: QueryFilters) { + return getLinks( + { + where: { + teamId, + }, + }, + filters, + ); +} + +export async function createLink(data: Prisma.LinkUncheckedCreateInput) { + return prisma.client.link.create({ data }); +} + +export async function updateLink(linkId: string, data: any) { + return prisma.client.link.update({ where: { id: linkId }, data }); +} + +export async function deleteLink(linkId: string) { + return prisma.client.link.delete({ where: { id: linkId } }); +} |