mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
Fix usage.
This commit is contained in:
parent
98a0a83ccf
commit
25dd94b551
@ -2,7 +2,7 @@ import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getAllWebsites, getEventDataUsage, getEventUsage } from 'queries';
|
||||
import { getAllUserWebsitesIncludingTeamOwner, getEventDataUsage, getEventUsage } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
|
||||
export interface UserUsageRequestQuery {
|
||||
@ -50,7 +50,7 @@ export default async (
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const websites = await getAllWebsites(userId);
|
||||
const websites = await getAllUserWebsitesIncludingTeamOwner(userId);
|
||||
|
||||
const websiteIds = websites.map(a => a.id);
|
||||
|
||||
|
@ -3,6 +3,7 @@ import redis from '@umami/redis-client';
|
||||
import prisma from 'lib/prisma';
|
||||
import { PageResult, PageParams } from 'lib/types';
|
||||
import WebsiteFindManyArgs = Prisma.WebsiteFindManyArgs;
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
async function findWebsite(criteria: Prisma.WebsiteFindUniqueArgs): Promise<Website> {
|
||||
return prisma.client.website.findUnique(criteria);
|
||||
@ -52,6 +53,27 @@ export async function getAllWebsites(userId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAllUserWebsitesIncludingTeamOwner(userId: string) {
|
||||
return prisma.client.website.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ userId },
|
||||
{
|
||||
team: {
|
||||
deletedAt: null,
|
||||
teamUser: {
|
||||
some: {
|
||||
role: ROLES.teamOwner,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getUserWebsites(
|
||||
userId: string,
|
||||
filters?: PageParams,
|
||||
|
Loading…
Reference in New Issue
Block a user