Add website/reports to top nav.
This commit is contained in:
@@ -28,13 +28,45 @@ export async function deleteReport(reportId: string): Promise<Report> {
|
||||
|
||||
export async function getReports(
|
||||
ReportSearchFilter: ReportSearchFilter,
|
||||
options?: { include?: Prisma.ReportInclude },
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
const { userId, websiteId, filter, filterType = REPORT_FILTER_TYPES.all } = ReportSearchFilter;
|
||||
const {
|
||||
userId,
|
||||
websiteId,
|
||||
includeTeams,
|
||||
filter,
|
||||
filterType = REPORT_FILTER_TYPES.all,
|
||||
} = ReportSearchFilter;
|
||||
|
||||
const where: Prisma.ReportWhereInput = {
|
||||
...(userId && { userId: userId }),
|
||||
...(websiteId && { websiteId: websiteId }),
|
||||
...(filter && {
|
||||
AND: {
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
...(userId && { userId: userId }),
|
||||
},
|
||||
{
|
||||
...(includeTeams && {
|
||||
website: {
|
||||
teamWebsite: {
|
||||
some: {
|
||||
team: {
|
||||
teamUser: {
|
||||
some: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
...((filterType === REPORT_FILTER_TYPES.all ||
|
||||
@@ -98,7 +130,7 @@ export async function getReports(
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters(ReportSearchFilter);
|
||||
@@ -106,6 +138,7 @@ export async function getReports(
|
||||
const reports = await prisma.client.report.findMany({
|
||||
where,
|
||||
...pageFilters,
|
||||
...(options?.include && { include: options.include }),
|
||||
});
|
||||
const count = await prisma.client.report.count({
|
||||
where,
|
||||
@@ -122,7 +155,18 @@ export async function getReportsByUserId(
|
||||
userId: string,
|
||||
filter: SearchFilter<ReportSearchFilterType>,
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
return getReports({ userId, ...filter });
|
||||
return getReports(
|
||||
{ userId, ...filter },
|
||||
{
|
||||
include: {
|
||||
website: {
|
||||
select: {
|
||||
domain: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function getReportsByWebsiteId(
|
||||
|
||||
@@ -26,29 +26,11 @@ export async function getWebsites(
|
||||
userId,
|
||||
teamId,
|
||||
includeTeams,
|
||||
onlyTeams,
|
||||
filter,
|
||||
filterType = WEBSITE_FILTER_TYPES.all,
|
||||
} = WebsiteSearchFilter;
|
||||
|
||||
const filterQuery = {
|
||||
AND: {
|
||||
OR: [
|
||||
{
|
||||
...((filterType === WEBSITE_FILTER_TYPES.all ||
|
||||
filterType === WEBSITE_FILTER_TYPES.name) && {
|
||||
name: { startsWith: filter, mode: 'insensitive' },
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === WEBSITE_FILTER_TYPES.all ||
|
||||
filterType === WEBSITE_FILTER_TYPES.domain) && {
|
||||
domain: { startsWith: filter, mode: 'insensitive' },
|
||||
}),
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const where: Prisma.WebsiteWhereInput = {
|
||||
...(teamId && {
|
||||
teamWebsite: {
|
||||
@@ -61,28 +43,53 @@ export async function getWebsites(
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
...(userId && {
|
||||
userId,
|
||||
}),
|
||||
...(userId &&
|
||||
!onlyTeams && {
|
||||
userId,
|
||||
}),
|
||||
},
|
||||
{
|
||||
...(includeTeams && {
|
||||
teamWebsite: {
|
||||
some: {
|
||||
team: {
|
||||
teamUser: {
|
||||
some: {
|
||||
userId,
|
||||
...((includeTeams || onlyTeams) && {
|
||||
AND: [
|
||||
{
|
||||
teamWebsite: {
|
||||
some: {
|
||||
team: {
|
||||
teamUser: {
|
||||
some: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
userId: {
|
||||
not: userId,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
...((filterType === WEBSITE_FILTER_TYPES.all ||
|
||||
filterType === WEBSITE_FILTER_TYPES.name) && {
|
||||
name: { startsWith: filter, mode: 'insensitive' },
|
||||
}),
|
||||
},
|
||||
{
|
||||
...((filterType === WEBSITE_FILTER_TYPES.all ||
|
||||
filterType === WEBSITE_FILTER_TYPES.domain) && {
|
||||
domain: { startsWith: filter, mode: 'insensitive' },
|
||||
}),
|
||||
},
|
||||
],
|
||||
},
|
||||
{ ...(filter && filterQuery) },
|
||||
],
|
||||
};
|
||||
|
||||
@@ -108,7 +115,27 @@ export async function getWebsitesByUserId(
|
||||
userId: string,
|
||||
filter?: WebsiteSearchFilter,
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
return getWebsites({ userId, ...filter });
|
||||
return getWebsites(
|
||||
{ userId, ...filter },
|
||||
{
|
||||
include: {
|
||||
teamWebsite: {
|
||||
include: {
|
||||
team: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWebsitesByTeamId(
|
||||
|
||||
Reference in New Issue
Block a user