mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into feat/um-290-update-clickhouse-client
This commit is contained in:
commit
8e240af9e8
325 changed files with 2853 additions and 3296 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { Prisma, Report } from '@prisma/client';
|
||||
import { REPORT_FILTER_TYPES } from 'lib/constants';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, ReportSearchFilter } from 'lib/types';
|
||||
|
||||
|
|
@ -27,27 +26,21 @@ export async function deleteReport(reportId: string): Promise<Report> {
|
|||
}
|
||||
|
||||
export async function getReports(
|
||||
ReportSearchFilter: ReportSearchFilter,
|
||||
params: ReportSearchFilter,
|
||||
options?: { include?: Prisma.ReportInclude },
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
const {
|
||||
userId,
|
||||
websiteId,
|
||||
includeTeams,
|
||||
filter,
|
||||
filterType = REPORT_FILTER_TYPES.all,
|
||||
} = ReportSearchFilter;
|
||||
const { query, userId, websiteId, includeTeams } = params;
|
||||
|
||||
const mode = prisma.getSearchMode();
|
||||
|
||||
const where: Prisma.ReportWhereInput = {
|
||||
...(userId && { userId: userId }),
|
||||
...(websiteId && { websiteId: websiteId }),
|
||||
userId,
|
||||
websiteId,
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
...(userId && { userId: userId }),
|
||||
userId,
|
||||
},
|
||||
{
|
||||
...(includeTeams && {
|
||||
|
|
@ -71,71 +64,53 @@ export async function getReports(
|
|||
{
|
||||
OR: [
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
filterType === REPORT_FILTER_TYPES.name) && {
|
||||
name: {
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
{
|
||||
description: {
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: {
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
{
|
||||
user: {
|
||||
username: {
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
website: {
|
||||
name: {
|
||||
startsWith: filter,
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
filterType === REPORT_FILTER_TYPES.description) && {
|
||||
description: {
|
||||
startsWith: filter,
|
||||
website: {
|
||||
domain: {
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
filterType === REPORT_FILTER_TYPES.type) && {
|
||||
type: {
|
||||
startsWith: filter,
|
||||
...mode,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
filterType === REPORT_FILTER_TYPES['user:username']) && {
|
||||
user: {
|
||||
username: {
|
||||
startsWith: filter,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
filterType === REPORT_FILTER_TYPES['website:name']) && {
|
||||
website: {
|
||||
name: {
|
||||
startsWith: filter,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
filterType === REPORT_FILTER_TYPES['website:domain']) && {
|
||||
website: {
|
||||
domain: {
|
||||
startsWith: filter,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters(ReportSearchFilter);
|
||||
const [pageFilters, pageInfo] = prisma.getPageFilters(params);
|
||||
|
||||
const reports = await prisma.client.report.findMany({
|
||||
where,
|
||||
|
|
@ -150,13 +125,13 @@ export async function getReports(
|
|||
return {
|
||||
data: reports,
|
||||
count,
|
||||
...getParameters,
|
||||
...pageInfo,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getReportsByUserId(
|
||||
userId: string,
|
||||
filter: ReportSearchFilter,
|
||||
filter?: ReportSearchFilter,
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
return getReports(
|
||||
{ userId, ...filter },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Prisma, Team } from '@prisma/client';
|
||||
import { ROLES, TEAM_FILTER_TYPES } from 'lib/constants';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, TeamSearchFilter } from 'lib/types';
|
||||
|
|
@ -82,10 +82,10 @@ export async function deleteTeam(
|
|||
}
|
||||
|
||||
export async function getTeams(
|
||||
TeamSearchFilter: TeamSearchFilter,
|
||||
filters: TeamSearchFilter,
|
||||
options?: { include?: Prisma.TeamInclude },
|
||||
): Promise<FilterResult<Team[]>> {
|
||||
const { userId, filter, filterType = TEAM_FILTER_TYPES.all } = TeamSearchFilter;
|
||||
const { userId, query } = filters;
|
||||
const mode = prisma.getSearchMode();
|
||||
|
||||
const where: Prisma.TeamWhereInput = {
|
||||
|
|
@ -94,29 +94,24 @@ export async function getTeams(
|
|||
some: { userId },
|
||||
},
|
||||
}),
|
||||
...(filter && {
|
||||
...(query && {
|
||||
AND: {
|
||||
OR: [
|
||||
{
|
||||
...((filterType === TEAM_FILTER_TYPES.all || filterType === TEAM_FILTER_TYPES.name) && {
|
||||
name: { startsWith: filter, ...mode },
|
||||
}),
|
||||
name: { startsWith: query, ...mode },
|
||||
},
|
||||
{
|
||||
...((filterType === TEAM_FILTER_TYPES.all ||
|
||||
filterType === TEAM_FILTER_TYPES['user:username']) && {
|
||||
teamUser: {
|
||||
some: {
|
||||
role: ROLES.teamOwner,
|
||||
user: {
|
||||
username: {
|
||||
startsWith: filter,
|
||||
...mode,
|
||||
},
|
||||
teamUser: {
|
||||
some: {
|
||||
role: ROLES.teamOwner,
|
||||
user: {
|
||||
username: {
|
||||
startsWith: query,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
@ -125,7 +120,7 @@ export async function getTeams(
|
|||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters({
|
||||
orderBy: 'name',
|
||||
...TeamSearchFilter,
|
||||
...filters,
|
||||
});
|
||||
|
||||
const teams = await prisma.client.team.findMany({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Prisma } from '@prisma/client';
|
||||
import cache from 'lib/cache';
|
||||
import { ROLES, USER_FILTER_TYPES } from 'lib/constants';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, Role, User, UserSearchFilter } from 'lib/types';
|
||||
import { getRandomChars } from 'next-basics';
|
||||
|
|
@ -37,10 +37,10 @@ export async function getUserByUsername(username: string, options: GetUserOption
|
|||
}
|
||||
|
||||
export async function getUsers(
|
||||
searchFilter: UserSearchFilter,
|
||||
params: UserSearchFilter,
|
||||
options?: { include?: Prisma.UserInclude },
|
||||
): Promise<FilterResult<User[]>> {
|
||||
const { teamId, filter, filterType = USER_FILTER_TYPES.all } = searchFilter;
|
||||
const { teamId, query } = params;
|
||||
const mode = prisma.getSearchMode();
|
||||
|
||||
const where: Prisma.UserWhereInput = {
|
||||
|
|
@ -51,17 +51,14 @@ export async function getUsers(
|
|||
},
|
||||
},
|
||||
}),
|
||||
...(filter && {
|
||||
...(query && {
|
||||
AND: {
|
||||
OR: [
|
||||
{
|
||||
...((filterType === USER_FILTER_TYPES.all ||
|
||||
filterType === USER_FILTER_TYPES.username) && {
|
||||
username: {
|
||||
startsWith: filter,
|
||||
...mode,
|
||||
},
|
||||
}),
|
||||
username: {
|
||||
contains: query,
|
||||
...mode,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
@ -70,7 +67,7 @@ export async function getUsers(
|
|||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters({
|
||||
orderBy: 'username',
|
||||
...searchFilter,
|
||||
...params,
|
||||
});
|
||||
|
||||
const users = await prisma.client.user
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Prisma, Website } from '@prisma/client';
|
||||
import cache from 'lib/cache';
|
||||
import { ROLES, WEBSITE_FILTER_TYPES } from 'lib/constants';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, WebsiteSearchFilter } from 'lib/types';
|
||||
|
||||
|
|
@ -19,17 +19,10 @@ export async function getWebsiteByShareId(shareId: string) {
|
|||
}
|
||||
|
||||
export async function getWebsites(
|
||||
WebsiteSearchFilter: WebsiteSearchFilter,
|
||||
filters: WebsiteSearchFilter,
|
||||
options?: { include?: Prisma.WebsiteInclude },
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
const {
|
||||
userId,
|
||||
teamId,
|
||||
includeTeams,
|
||||
onlyTeams,
|
||||
filter,
|
||||
filterType = WEBSITE_FILTER_TYPES.all,
|
||||
} = WebsiteSearchFilter;
|
||||
const { userId, teamId, includeTeams, onlyTeams, query } = filters;
|
||||
const mode = prisma.getSearchMode();
|
||||
|
||||
const where: Prisma.WebsiteWhereInput = {
|
||||
|
|
@ -76,27 +69,23 @@ export async function getWebsites(
|
|||
],
|
||||
},
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
...((filterType === WEBSITE_FILTER_TYPES.all ||
|
||||
filterType === WEBSITE_FILTER_TYPES.name) && {
|
||||
name: { startsWith: filter, ...mode },
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === WEBSITE_FILTER_TYPES.all ||
|
||||
filterType === WEBSITE_FILTER_TYPES.domain) && {
|
||||
domain: { startsWith: filter, ...mode },
|
||||
}),
|
||||
},
|
||||
],
|
||||
OR: query
|
||||
? [
|
||||
{
|
||||
name: { contains: query, ...mode },
|
||||
},
|
||||
{
|
||||
domain: { contains: query, ...mode },
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters({
|
||||
orderBy: 'name',
|
||||
...WebsiteSearchFilter,
|
||||
...filters,
|
||||
});
|
||||
|
||||
const websites = await prisma.client.website.findMany({
|
||||
|
|
@ -115,10 +104,10 @@ export async function getWebsites(
|
|||
|
||||
export async function getWebsitesByUserId(
|
||||
userId: string,
|
||||
filter?: WebsiteSearchFilter,
|
||||
filters?: WebsiteSearchFilter,
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
return getWebsites(
|
||||
{ userId, ...filter },
|
||||
{ userId, ...filters },
|
||||
{
|
||||
include: {
|
||||
teamWebsite: {
|
||||
|
|
@ -143,12 +132,12 @@ export async function getWebsitesByUserId(
|
|||
|
||||
export async function getWebsitesByTeamId(
|
||||
teamId: string,
|
||||
filter?: WebsiteSearchFilter,
|
||||
filters?: WebsiteSearchFilter,
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
return getWebsites(
|
||||
{
|
||||
teamId,
|
||||
...filter,
|
||||
...filters,
|
||||
includeTeams: true,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export async function getRetention(
|
|||
filters: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
timezone?: string;
|
||||
},
|
||||
]
|
||||
) {
|
||||
|
|
@ -23,7 +23,7 @@ async function relationalQuery(
|
|||
filters: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
timezone?: string;
|
||||
},
|
||||
): Promise<
|
||||
{
|
||||
|
|
@ -103,7 +103,7 @@ async function clickhouseQuery(
|
|||
filters: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
timezone: string;
|
||||
timezone?: string;
|
||||
},
|
||||
): Promise<
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue