Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/umami-software/umami into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscao633 committed Aug 15, 2023
2 parents 979ea33 + 14df1e5 commit a16b0ce
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
14 changes: 14 additions & 0 deletions lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FILTER_COLUMNS, SESSION_COLUMNS, OPERATORS } from './constants';
import { loadWebsite } from './load';
import { maxDate } from './date';
import { QueryFilters, QueryOptions, SearchFilter } from './types';
import { Prisma } from '@prisma/client';

const MYSQL_DATE_FORMATS = {
minute: '%Y-%m-%d %H:%i:00',
Expand Down Expand Up @@ -189,6 +190,18 @@ function getPageFilters(filters: SearchFilter<any>): [
];
}

function getSearchMode(): { mode?: Prisma.QueryMode } {
const db = getDatabaseType();

if (db === POSTGRESQL) {
return {
mode: 'insensitive',
};
}

return {};
}

export default {
...prisma,
getAddMinutesQuery,
Expand All @@ -198,5 +211,6 @@ export default {
getFilterQuery,
parseFilters,
getPageFilters,
getSearchMode,
rawQuery,
};
14 changes: 8 additions & 6 deletions queries/admin/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export async function getReports(
filterType = REPORT_FILTER_TYPES.all,
} = ReportSearchFilter;

const mode = prisma.getSearchMode();

const where: Prisma.ReportWhereInput = {
...(userId && { userId: userId }),
...(websiteId && { websiteId: websiteId }),
Expand Down Expand Up @@ -73,7 +75,7 @@ export async function getReports(
filterType === REPORT_FILTER_TYPES.name) && {
name: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
}),
},
Expand All @@ -82,7 +84,7 @@ export async function getReports(
filterType === REPORT_FILTER_TYPES.description) && {
description: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
}),
},
Expand All @@ -91,7 +93,7 @@ export async function getReports(
filterType === REPORT_FILTER_TYPES.type) && {
type: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
}),
},
Expand All @@ -101,7 +103,7 @@ export async function getReports(
user: {
username: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
},
}),
Expand All @@ -112,7 +114,7 @@ export async function getReports(
website: {
name: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
},
}),
Expand All @@ -123,7 +125,7 @@ export async function getReports(
website: {
domain: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
},
}),
Expand Down
6 changes: 4 additions & 2 deletions queries/admin/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export async function getTeams(
options?: { include?: Prisma.TeamInclude },
): Promise<FilterResult<Team[]>> {
const { userId, filter, filterType = TEAM_FILTER_TYPES.all } = TeamSearchFilter;
const mode = prisma.getSearchMode();

const where: Prisma.TeamWhereInput = {
...(userId && {
teamUser: {
Expand All @@ -97,7 +99,7 @@ export async function getTeams(
OR: [
{
...((filterType === TEAM_FILTER_TYPES.all || filterType === TEAM_FILTER_TYPES.name) && {
name: { startsWith: filter, mode: 'insensitive' },
name: { startsWith: filter, ...mode },
}),
},
{
Expand All @@ -109,7 +111,7 @@ export async function getTeams(
user: {
username: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion queries/admin/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export async function getUsers(
options?: { include?: Prisma.UserInclude },
): Promise<FilterResult<User[]>> {
const { teamId, filter, filterType = USER_FILTER_TYPES.all } = UserSearchFilter;
const mode = prisma.getSearchMode();

const where: Prisma.UserWhereInput = {
...(teamId && {
teamUser: {
Expand All @@ -57,7 +59,7 @@ export async function getUsers(
filterType === USER_FILTER_TYPES.username) && {
username: {
startsWith: filter,
mode: 'insensitive',
...mode,
},
}),
},
Expand Down
5 changes: 3 additions & 2 deletions queries/admin/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function getWebsites(
filter,
filterType = WEBSITE_FILTER_TYPES.all,
} = WebsiteSearchFilter;
const mode = prisma.getSearchMode();

const where: Prisma.WebsiteWhereInput = {
...(teamId && {
Expand Down Expand Up @@ -79,13 +80,13 @@ export async function getWebsites(
{
...((filterType === WEBSITE_FILTER_TYPES.all ||
filterType === WEBSITE_FILTER_TYPES.name) && {
name: { startsWith: filter, mode: 'insensitive' },
name: { startsWith: filter, ...mode },
}),
},
{
...((filterType === WEBSITE_FILTER_TYPES.all ||
filterType === WEBSITE_FILTER_TYPES.domain) && {
domain: { startsWith: filter, mode: 'insensitive' },
domain: { startsWith: filter, ...mode },
}),
},
],
Expand Down

0 comments on commit a16b0ce

Please sign in to comment.