mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 23:57:12 +01:00
New schema for pixels and links.
This commit is contained in:
parent
c60e8b3d23
commit
88639dfe83
67 changed files with 993 additions and 208 deletions
|
|
@ -1,3 +1,5 @@
|
|||
export * from '@/queries/prisma/link';
|
||||
export * from '@/queries/prisma/pixel';
|
||||
export * from '@/queries/prisma/report';
|
||||
export * from '@/queries/prisma/segment';
|
||||
export * from '@/queries/prisma/team';
|
||||
|
|
|
|||
71
src/queries/prisma/link.ts
Normal file
71
src/queries/prisma/link.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { Prisma, Link } from '@prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
|
||||
async function findLink(criteria: Prisma.LinkFindUniqueArgs): Promise<Link> {
|
||||
return prisma.client.link.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getLink(linkId: string): Promise<Link> {
|
||||
return findLink({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getLinks(
|
||||
criteria: Prisma.LinkFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Link[]>> {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.LinkWhereInput = {
|
||||
...criteria.where,
|
||||
...prisma.getSearchParameters(search, [{ name: 'contains' }]),
|
||||
};
|
||||
|
||||
return prisma.pagedQuery('link', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getUserLinks(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Link[]>> {
|
||||
return getLinks(
|
||||
{
|
||||
where: {
|
||||
userId,
|
||||
deletedAt: null,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getTeamLinks(
|
||||
teamId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Link[]>> {
|
||||
return getLinks(
|
||||
{
|
||||
where: {
|
||||
teamId,
|
||||
deletedAt: null,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createLink(data: Prisma.LinkUncheckedCreateInput): Promise<Link> {
|
||||
return prisma.client.link.create({ data });
|
||||
}
|
||||
|
||||
export async function updateLink(linkId: string, data: any): Promise<Link> {
|
||||
return prisma.client.link.update({ where: { id: linkId }, data });
|
||||
}
|
||||
|
||||
export async function deleteLink(linkId: string): Promise<Link> {
|
||||
return prisma.client.link.delete({ where: { id: linkId } });
|
||||
}
|
||||
69
src/queries/prisma/pixel.ts
Normal file
69
src/queries/prisma/pixel.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import { Prisma, Pixel } from '@prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
|
||||
async function findPixel(criteria: Prisma.PixelFindUniqueArgs): Promise<Pixel> {
|
||||
return prisma.client.pixel.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getPixel(pixelId: string): Promise<Pixel> {
|
||||
return findPixel({
|
||||
where: {
|
||||
id: pixelId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPixels(
|
||||
criteria: Prisma.PixelFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Pixel[]>> {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.PixelWhereInput = {
|
||||
...criteria.where,
|
||||
...prisma.getSearchParameters(search, [{ name: 'contains' }]),
|
||||
};
|
||||
|
||||
return prisma.pagedQuery('pixel', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getUserPixels(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Pixel[]>> {
|
||||
return getPixels(
|
||||
{
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getTeamPixels(
|
||||
teamId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Pixel[]>> {
|
||||
return getPixels(
|
||||
{
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createPixel(data: Prisma.PixelUncheckedCreateInput): Promise<Pixel> {
|
||||
return prisma.client.pixel.create({ data });
|
||||
}
|
||||
|
||||
export async function updatePixel(pixelId: string, data: any): Promise<Pixel> {
|
||||
return prisma.client.pixel.update({ where: { id: pixelId }, data });
|
||||
}
|
||||
|
||||
export async function deletePixel(pixelId: string): Promise<Pixel> {
|
||||
return prisma.client.pixel.delete({ where: { id: pixelId } });
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ export async function getTeam(teamId: string, options: { includeMembers?: boolea
|
|||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
...(includeMembers && { include: { teamUser: true } }),
|
||||
...(includeMembers && { include: { members: true } }),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -47,12 +47,12 @@ export async function getUserTeams(userId: string, filters: QueryFilters) {
|
|||
{
|
||||
where: {
|
||||
deletedAt: null,
|
||||
teamUser: {
|
||||
members: {
|
||||
some: { userId },
|
||||
},
|
||||
},
|
||||
include: {
|
||||
teamUser: {
|
||||
members: {
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
|
|
@ -64,10 +64,10 @@ export async function getUserTeams(userId: string, filters: QueryFilters) {
|
|||
},
|
||||
_count: {
|
||||
select: {
|
||||
website: {
|
||||
websites: {
|
||||
where: { deletedAt: null },
|
||||
},
|
||||
teamUser: {
|
||||
members: {
|
||||
where: {
|
||||
user: { deletedAt: null },
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { Prisma, Website } from '@prisma/client';
|
|||
import redis from '@/lib/redis';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import WebsiteFindManyArgs = Prisma.WebsiteFindManyArgs;
|
||||
import { ROLES } from '@/lib/constants';
|
||||
|
||||
async function findWebsite(criteria: Prisma.WebsiteFindUniqueArgs): Promise<Website> {
|
||||
|
|
@ -27,7 +26,7 @@ export async function getSharedWebsite(shareId: string) {
|
|||
}
|
||||
|
||||
export async function getWebsites(
|
||||
criteria: WebsiteFindManyArgs,
|
||||
criteria: Prisma.WebsiteFindManyArgs,
|
||||
filters: QueryFilters,
|
||||
): Promise<PageResult<Website[]>> {
|
||||
const { search } = filters;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue