Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

1.7 KB
Raw Blame
import type { Prisma, Share } from '@/generated/prisma/client';
import prisma from '@/lib/prisma';
import type { PageResult, QueryFilters } from '@/lib/types';

export async function findShare(criteria: Prisma.ShareFindUniqueArgs) {
  return prisma.client.share.findUnique(criteria);
}

export async function getShare(shareId: string) {
  return findShare({
    where: {
      id: shareId,
    },
  });
}

export async function getShareByCode(slug: string) {
  return findShare({
    where: {
      slug,
    },
  });
}

export async function getShareByEntityId(entityId: string) {
  return prisma.client.share.findFirst({
    where: {
      entityId,
    },
    orderBy: {
      createdAt: 'desc',
    },
  });
}

export async function getSharesByEntityId(
  entityId: string,
  filters?: QueryFilters,
): Promise<PageResult<Share[]>> {
  const { pagedQuery } = prisma;

  return pagedQuery(
    'share',
    {
      where: {
        entityId,
      },
      orderBy: {
        createdAt: 'desc',
      },
    },
    filters,
  );
}

export async function createShare(
  data: Prisma.ShareCreateInput | Prisma.ShareUncheckedCreateInput,
) {
  return prisma.client.share.create({
    data,
  });
}

export async function updateShare(
  shareId: string,
  data: Prisma.ShareUpdateInput | Prisma.ShareUncheckedUpdateInput,
) {
  return prisma.client.share.update({
    where: {
      id: shareId,
    },
    data,
  });
}

export async function deleteShare(shareId: string) {
  return prisma.client.share.delete({ where: { id: shareId } });
}

export async function deleteSharesByEntityId(entityId: string) {
  return prisma.client.share.deleteMany({
    where: {
      entityId,
    },
  });
}