mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
fix search for segments, fix hooks endpoint for cohorts
This commit is contained in:
parent
2f1f704728
commit
65024d4bf7
6 changed files with 43 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import prisma from '@/lib/prisma';
|
||||
import { Prisma, Segment } from '@/generated/prisma/client';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
|
||||
async function findSegment(criteria: Prisma.SegmentFindUniqueArgs): Promise<Segment> {
|
||||
return prisma.client.Segment.findUnique(criteria);
|
||||
|
|
@ -13,16 +14,45 @@ export async function getSegment(segmentId: string): Promise<Segment> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getSegments(
|
||||
criteria: Prisma.SegmentFindManyArgs,
|
||||
filters: QueryFilters,
|
||||
): Promise<PageResult<Segment[]>> {
|
||||
const { search } = filters;
|
||||
const { getSearchParameters, pagedQuery } = prisma;
|
||||
|
||||
const where: Prisma.SegmentWhereInput = {
|
||||
...criteria.where,
|
||||
...getSearchParameters(search, [
|
||||
{
|
||||
name: 'contains',
|
||||
},
|
||||
]),
|
||||
};
|
||||
|
||||
return pagedQuery('segment', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getWebsiteSegment(websiteId: string, segmentId: string): Promise<Segment> {
|
||||
return prisma.client.Segment.findFirst({
|
||||
where: { id: segmentId, websiteId },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getWebsiteSegments(websiteId: string, type: string): Promise<Segment[]> {
|
||||
return prisma.pagedQuery('segment', {
|
||||
where: { websiteId, type },
|
||||
});
|
||||
export async function getWebsiteSegments(
|
||||
websiteId: string,
|
||||
type: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Segment[]>> {
|
||||
return getSegments(
|
||||
{
|
||||
where: {
|
||||
websiteId,
|
||||
type,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createSegment(data: Prisma.SegmentUncheckedCreateInput): Promise<Segment> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue