mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 20:39:44 +01:00
Fixed reports queries.
This commit is contained in:
parent
40970f6c33
commit
87bb9b1e73
@ -6,11 +6,9 @@ export function useReports({ websiteId, teamId }: { websiteId?: string; teamId?:
|
|||||||
const modified = useCache((state: any) => state?.reports);
|
const modified = useCache((state: any) => state?.reports);
|
||||||
const { get, del, useMutation } = useApi();
|
const { get, del, useMutation } = useApi();
|
||||||
const queryResult = useFilterQuery({
|
const queryResult = useFilterQuery({
|
||||||
queryKey: ['reports', { websiteId, modified }],
|
queryKey: ['reports', { websiteId, teamId, modified }],
|
||||||
queryFn: (params: any) => {
|
queryFn: (params: any) => {
|
||||||
const url = websiteId ? `/websites/${websiteId}/reports` : `/reports`;
|
return get('/reports', { websiteId, teamId, ...params });
|
||||||
|
|
||||||
return get(teamId ? `/teams/${teamId}${url}` : url, params);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { mutate } = useMutation({ mutationFn: (reportId: string) => del(`/reports/${reportId}`) });
|
const { mutate } = useMutation({ mutationFn: (reportId: string) => del(`/reports/${reportId}`) });
|
||||||
|
@ -29,9 +29,6 @@ export function ProfileButton() {
|
|||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Profile />
|
<Icons.Profile />
|
||||||
</Icon>
|
</Icon>
|
||||||
<Icon size="sm">
|
|
||||||
<Icons.ChevronDown />
|
|
||||||
</Icon>
|
|
||||||
</Button>
|
</Button>
|
||||||
<Popup position="bottom" alignment={dir === 'rtl' ? 'start' : 'end'}>
|
<Popup position="bottom" alignment={dir === 'rtl' ? 'start' : 'end'}>
|
||||||
<Menu onSelect={handleSelect} className={styles.menu}>
|
<Menu onSelect={handleSelect} className={styles.menu}>
|
||||||
|
@ -63,6 +63,7 @@ export function ListTable({
|
|||||||
{data?.length === 0 && <Empty className={styles.empty} />}
|
{data?.length === 0 && <Empty className={styles.empty} />}
|
||||||
{virtualize && data.length > 0 ? (
|
{virtualize && data.length > 0 ? (
|
||||||
<FixedSizeList
|
<FixedSizeList
|
||||||
|
width="100%"
|
||||||
height={itemCount * ITEM_SIZE}
|
height={itemCount * ITEM_SIZE}
|
||||||
itemCount={data.length}
|
itemCount={data.length}
|
||||||
itemSize={ITEM_SIZE}
|
itemSize={ITEM_SIZE}
|
||||||
|
@ -4,7 +4,7 @@ import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
|||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed, ok } from 'next-basics';
|
import { methodNotAllowed, ok } from 'next-basics';
|
||||||
import { createReport, getUserReports } from 'queries';
|
import { createReport, getReports } from 'queries';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface ReportsRequestQuery extends SearchFilter {}
|
export interface ReportsRequestQuery extends SearchFilter {}
|
||||||
@ -50,13 +50,25 @@ export default async (
|
|||||||
} = req.auth;
|
} = req.auth;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const { page, query, pageSize } = req.query;
|
const { page, query, pageSize, websiteId, teamId } = req.query;
|
||||||
|
const filters = {
|
||||||
const data = await getUserReports(userId, {
|
|
||||||
page,
|
page,
|
||||||
pageSize: +pageSize || undefined,
|
pageSize: +pageSize || undefined,
|
||||||
query,
|
query,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const data = await getReports(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
userId: !(websiteId && teamId) ? userId : undefined,
|
||||||
|
websiteId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
website: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filters,
|
||||||
|
);
|
||||||
|
|
||||||
return ok(res, data);
|
return ok(res, data);
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ export async function getReports(
|
|||||||
const { query, userId, websiteId } = filters;
|
const { query, userId, websiteId } = filters;
|
||||||
|
|
||||||
const where: Prisma.ReportWhereInput = {
|
const where: Prisma.ReportWhereInput = {
|
||||||
...criteria.where,
|
|
||||||
userId,
|
userId,
|
||||||
websiteId,
|
websiteId,
|
||||||
|
...criteria.where,
|
||||||
AND: [
|
AND: [
|
||||||
{
|
{
|
||||||
OR: [
|
OR: [
|
||||||
|
Loading…
Reference in New Issue
Block a user