mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Renamed id routes for API.
This commit is contained in:
parent
53a991176b
commit
4429198397
@ -1,6 +1,6 @@
|
|||||||
import { GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
import { GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
||||||
import LinkButton from 'components/common/LinkButton';
|
import LinkButton from 'components/common/LinkButton';
|
||||||
import { useMessages, useLogin } from 'components/hooks';
|
import { useMessages, useLogin, useNavigation } from 'components/hooks';
|
||||||
import { REPORT_TYPES } from 'lib/constants';
|
import { REPORT_TYPES } from 'lib/constants';
|
||||||
import ReportDeleteButton from './ReportDeleteButton';
|
import ReportDeleteButton from './ReportDeleteButton';
|
||||||
|
|
||||||
@ -8,6 +8,7 @@ export function ReportsTable({ data = [], showDomain }: { data: any[]; showDomai
|
|||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useLogin();
|
const { user } = useLogin();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
||||||
|
const { renderTeamUrl } = useNavigation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GridTable data={data} cardMode={['xs', 'sm', 'md'].includes(breakpoint)}>
|
<GridTable data={data} cardMode={['xs', 'sm', 'md'].includes(breakpoint)}>
|
||||||
@ -33,7 +34,7 @@ export function ReportsTable({ data = [], showDomain }: { data: any[]; showDomai
|
|||||||
{(user.id === userId || user.id === website?.userId) && (
|
{(user.id === userId || user.id === website?.userId) && (
|
||||||
<ReportDeleteButton reportId={id} reportName={name} />
|
<ReportDeleteButton reportId={id} reportName={name} />
|
||||||
)}
|
)}
|
||||||
<LinkButton href={`/reports/${id}`}>
|
<LinkButton href={renderTeamUrl(`/reports/${id}`)}>
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.ArrowRight />
|
<Icons.ArrowRight />
|
||||||
</Icon>
|
</Icon>
|
||||||
|
@ -17,7 +17,7 @@ export function TeamWebsitesTable({
|
|||||||
<GridColumn name="domain" label={formatMessage(labels.domain)} />
|
<GridColumn name="domain" label={formatMessage(labels.domain)} />
|
||||||
<GridColumn name="action" label=" " alignment="end">
|
<GridColumn name="action" label=" " alignment="end">
|
||||||
{row => {
|
{row => {
|
||||||
const { id: websiteId } = row;
|
const { websiteId } = row;
|
||||||
return (
|
return (
|
||||||
<Link href={`/websites/${websiteId}`}>
|
<Link href={`/websites/${websiteId}`}>
|
||||||
<Button>
|
<Button>
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Button, Flexbox, Icon, Icons, Text } from 'react-basics';
|
import { Button, Flexbox, Icon, Icons, Text } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useNavigation } from 'components/hooks';
|
||||||
import ReportsDataTable from 'app/(main)/reports/ReportsDataTable';
|
import ReportsDataTable from 'app/(main)/reports/ReportsDataTable';
|
||||||
|
|
||||||
export function TeamReports({ websiteId }) {
|
export function TeamReports({ websiteId }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
const { renderTeamUrl } = useNavigation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Flexbox alignItems="center" justifyContent="end">
|
<Flexbox alignItems="center" justifyContent="end">
|
||||||
<Link href={`/reports/create`}>
|
<Link href={renderTeamUrl(`/reports/create`)}>
|
||||||
<Button variant="primary">
|
<Button variant="primary">
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Plus />
|
<Icons.Plus />
|
||||||
|
@ -4,7 +4,7 @@ import { UseQueryOptions } from '@tanstack/react-query';
|
|||||||
export function useWebsiteMetrics(
|
export function useWebsiteMetrics(
|
||||||
websiteId: string,
|
websiteId: string,
|
||||||
params?: { [key: string]: any },
|
params?: { [key: string]: any },
|
||||||
options?: Omit<UseQueryOptions, 'queryKey' | 'queryFn'>,
|
options?: Omit<UseQueryOptions & { onDataLoad?: (data: any) => void }, 'queryKey' | 'queryFn'>,
|
||||||
) {
|
) {
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ export function useWebsiteMetrics(
|
|||||||
...filters,
|
...filters,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
options?.onDataLoad?.(data);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
|
@ -11,10 +11,9 @@ export interface DateFilterProps {
|
|||||||
value: string;
|
value: string;
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
endDate: Date;
|
endDate: Date;
|
||||||
offset: number;
|
offset?: number;
|
||||||
className?: string;
|
className?: string;
|
||||||
onChange?: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
selectedUnit?: string;
|
|
||||||
showAllTime?: boolean;
|
showAllTime?: boolean;
|
||||||
alignment?: 'start' | 'center' | 'end';
|
alignment?: 'start' | 'center' | 'end';
|
||||||
}
|
}
|
||||||
@ -23,7 +22,7 @@ export function DateFilter({
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
value,
|
value,
|
||||||
offset,
|
offset = 0,
|
||||||
className,
|
className,
|
||||||
onChange,
|
onChange,
|
||||||
showAllTime = false,
|
showAllTime = false,
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
import { ReactNode, useMemo, useState } from 'react';
|
import { ReactNode, useMemo, useState } from 'react';
|
||||||
import { Loading, Icon, Text, SearchField } from 'react-basics';
|
import { Loading, Icon, Text, SearchField } from 'react-basics';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { percentFilter } from 'lib/filters';
|
|
||||||
import { useDateRange } from 'components/hooks';
|
|
||||||
import { useNavigation } from 'components/hooks';
|
|
||||||
import ErrorMessage from 'components/common/ErrorMessage';
|
import ErrorMessage from 'components/common/ErrorMessage';
|
||||||
import LinkButton from 'components/common/LinkButton';
|
import LinkButton from 'components/common/LinkButton';
|
||||||
import ListTable, { ListTableProps } from './ListTable';
|
|
||||||
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
|
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
|
||||||
|
import { percentFilter } from 'lib/filters';
|
||||||
|
import {
|
||||||
|
useDateRange,
|
||||||
|
useNavigation,
|
||||||
|
useWebsiteMetrics,
|
||||||
|
useMessages,
|
||||||
|
useLocale,
|
||||||
|
useFormat,
|
||||||
|
} from 'components/hooks';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import { useMessages } from 'components/hooks';
|
import ListTable, { ListTableProps } from './ListTable';
|
||||||
import { useLocale } from 'components/hooks';
|
|
||||||
import useFormat from 'components//hooks/useFormat';
|
|
||||||
import styles from './MetricsTable.module.css';
|
import styles from './MetricsTable.module.css';
|
||||||
import useWebsiteMetrics from 'components/hooks/queries/useWebsiteMetrics';
|
|
||||||
|
|
||||||
export interface MetricsTableProps extends ListTableProps {
|
export interface MetricsTableProps extends ListTableProps {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
@ -67,7 +69,7 @@ export function MetricsTable({
|
|||||||
region,
|
region,
|
||||||
city,
|
city,
|
||||||
},
|
},
|
||||||
{ retryDelay: delay || DEFAULT_ANIMATION_DURATION },
|
{ retryDelay: delay || DEFAULT_ANIMATION_DURATION, onDataLoad },
|
||||||
);
|
);
|
||||||
|
|
||||||
const filteredData = useMemo(() => {
|
const filteredData = useMemo(() => {
|
||||||
|
@ -3,7 +3,7 @@ import { getAllowedUnits, getMinimumUnit } from './date';
|
|||||||
import { getWebsiteDateRange } from '../queries';
|
import { getWebsiteDateRange } from '../queries';
|
||||||
|
|
||||||
export async function parseDateRangeQuery(req: NextApiRequest) {
|
export async function parseDateRangeQuery(req: NextApiRequest) {
|
||||||
const { id: websiteId, startAt, endAt, unit } = req.query;
|
const { websiteId, startAt, endAt, unit } = req.query;
|
||||||
|
|
||||||
// All-time
|
// All-time
|
||||||
if (+startAt === 0 && +endAt === 1) {
|
if (+startAt === 0 && +endAt === 1) {
|
||||||
|
@ -9,9 +9,9 @@ import * as yup from 'yup';
|
|||||||
|
|
||||||
export interface UsersRequestQuery extends SearchFilter {}
|
export interface UsersRequestQuery extends SearchFilter {}
|
||||||
export interface UsersRequestBody {
|
export interface UsersRequestBody {
|
||||||
|
userId: string;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
id: string;
|
|
||||||
role: Role;
|
role: Role;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ const schema = {
|
|||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
|
userId: yup.string().uuid(),
|
||||||
username: yup.string().max(255).required(),
|
username: yup.string().max(255).required(),
|
||||||
password: yup.string().required(),
|
password: yup.string().required(),
|
||||||
id: yup.string().uuid(),
|
|
||||||
role: yup
|
role: yup
|
||||||
.string()
|
.string()
|
||||||
.matches(/admin|user|view-only/i)
|
.matches(/admin|user|view-only/i)
|
||||||
|
@ -22,7 +22,7 @@ const schema = {
|
|||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
req: NextApiRequestQueryBody<EventDataStatsRequestQuery>,
|
req: NextApiRequestQueryBody<EventDataStatsRequestQuery>,
|
||||||
res: NextApiResponse<any>,
|
res: NextApiResponse,
|
||||||
) => {
|
) => {
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
@ -12,10 +12,6 @@ import {
|
|||||||
import { getUser, updateUser } from 'queries';
|
import { getUser, updateUser } from 'queries';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface UserPasswordRequestQuery {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UserPasswordRequestBody {
|
export interface UserPasswordRequestBody {
|
||||||
currentPassword: string;
|
currentPassword: string;
|
||||||
newPassword: string;
|
newPassword: string;
|
||||||
@ -29,7 +25,7 @@ const schema = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
req: NextApiRequestQueryBody<UserPasswordRequestQuery, UserPasswordRequestBody>,
|
req: NextApiRequestQueryBody<any, UserPasswordRequestBody>,
|
||||||
res: NextApiResponse<User>,
|
res: NextApiResponse<User>,
|
||||||
) => {
|
) => {
|
||||||
if (process.env.CLOUD_MODE) {
|
if (process.env.CLOUD_MODE) {
|
||||||
@ -40,10 +36,10 @@ export default async (
|
|||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { currentPassword, newPassword } = req.body;
|
const { currentPassword, newPassword } = req.body;
|
||||||
const { id } = req.auth.user;
|
const { id: userId } = req.auth.user;
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const user = await getUser(id, { includePassword: true });
|
const user = await getUser(userId, { includePassword: true });
|
||||||
|
|
||||||
if (!checkPassword(currentPassword, user.password)) {
|
if (!checkPassword(currentPassword, user.password)) {
|
||||||
return badRequest(res, 'Current password is incorrect');
|
return badRequest(res, 'Current password is incorrect');
|
||||||
@ -51,7 +47,7 @@ export default async (
|
|||||||
|
|
||||||
const password = hashPassword(newPassword);
|
const password = hashPassword(newPassword);
|
||||||
|
|
||||||
const updated = await updateUser({ password }, { id });
|
const updated = await updateUser(userId, { password });
|
||||||
|
|
||||||
return ok(res, updated);
|
return ok(res, updated);
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,23 @@
|
|||||||
import { useCors, useValidate } from 'lib/middleware';
|
import { useCors, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
import { NextApiRequestQueryBody } from 'lib/types';
|
||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed } from 'next-basics';
|
import { methodNotAllowed } from 'next-basics';
|
||||||
import userTeams from 'pages/api/users/[id]/teams';
|
import userTeams from 'pages/api/users/[userId]/teams';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface MyTeamsRequestQuery extends SearchFilter {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async (
|
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
||||||
req: NextApiRequestQueryBody<MyTeamsRequestQuery, any>,
|
|
||||||
res: NextApiResponse,
|
|
||||||
) => {
|
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
req.query.id = req.auth.user.id;
|
req.query.userId = req.auth.user.id;
|
||||||
|
|
||||||
return userTeams(req, res);
|
return userTeams(req, res);
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,24 @@
|
|||||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
import { NextApiRequestQueryBody } from 'lib/types';
|
||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed } from 'next-basics';
|
import { methodNotAllowed } from 'next-basics';
|
||||||
import userWebsites from 'pages/api/users/[id]/websites';
|
import userWebsites from 'pages/api/users/[userId]/websites';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface MyWebsitesRequestQuery extends SearchFilter {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async (
|
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
||||||
req: NextApiRequestQueryBody<MyWebsitesRequestQuery, any>,
|
|
||||||
res: NextApiResponse,
|
|
||||||
) => {
|
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
req.query.id = req.auth.user.id;
|
req.query.userId = req.auth.user.id;
|
||||||
|
|
||||||
return userWebsites(req, res);
|
return userWebsites(req, res);
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ import * as yup from 'yup';
|
|||||||
import { REALTIME_RANGE } from 'lib/constants';
|
import { REALTIME_RANGE } from 'lib/constants';
|
||||||
|
|
||||||
export interface RealtimeRequestQuery {
|
export interface RealtimeRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
startAt: number;
|
startAt: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@ -28,7 +28,7 @@ export default async (
|
|||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const { id: websiteId, startAt } = req.query;
|
const { websiteId, startAt } = req.query;
|
||||||
|
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
@ -7,7 +7,7 @@ import { deleteReport, getReport, updateReport } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface ReportRequestQuery {
|
export interface ReportRequestQuery {
|
||||||
id: string;
|
reportId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReportRequestBody {
|
export interface ReportRequestBody {
|
||||||
@ -20,10 +20,10 @@ export interface ReportRequestBody {
|
|||||||
|
|
||||||
const schema: YupRequest = {
|
const schema: YupRequest = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
reportId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
reportId: yup.string().uuid().required(),
|
||||||
websiteId: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
type: yup
|
type: yup
|
||||||
.string()
|
.string()
|
||||||
@ -36,7 +36,7 @@ const schema: YupRequest = {
|
|||||||
.test('len', 'Must not exceed 6000 characters.', val => JSON.stringify(val).length < 6000),
|
.test('len', 'Must not exceed 6000 characters.', val => JSON.stringify(val).length < 6000),
|
||||||
}),
|
}),
|
||||||
DELETE: yup.object().shape({
|
DELETE: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
reportId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: reportId } = req.query;
|
const { reportId } = req.query;
|
||||||
const {
|
const {
|
||||||
user: { id: userId },
|
user: { id: userId },
|
||||||
} = req.auth;
|
} = req.auth;
|
@ -1,14 +1,12 @@
|
|||||||
import { uuid } from 'lib/crypto';
|
import { uuid } from 'lib/crypto';
|
||||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
import { NextApiRequestQueryBody } 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, getReports } from 'queries';
|
import { createReport, getReports } from 'queries';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface ReportsRequestQuery extends SearchFilter {}
|
|
||||||
|
|
||||||
export interface ReportRequestBody {
|
export interface ReportRequestBody {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -60,11 +58,18 @@ export default async (
|
|||||||
const data = await getReports(
|
const data = await getReports(
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
userId: !(websiteId && teamId) ? userId : undefined,
|
website: {
|
||||||
websiteId,
|
id: websiteId,
|
||||||
|
userId: !websiteId && !teamId ? userId : undefined,
|
||||||
|
teamId,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
website: true,
|
website: {
|
||||||
|
select: {
|
||||||
|
domain: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
filters,
|
filters,
|
||||||
|
@ -7,17 +7,17 @@ import { getSharedWebsite } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface ShareRequestQuery {
|
export interface ShareRequestQuery {
|
||||||
id: string;
|
shareId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShareResponse {
|
export interface ShareResponse {
|
||||||
id: string;
|
shareId: string;
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().required(),
|
shareId: yup.string().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ export default async (
|
|||||||
) => {
|
) => {
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: shareId } = req.query;
|
const { shareId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const website = await getSharedWebsite(shareId);
|
const website = await getSharedWebsite(shareId);
|
@ -8,7 +8,7 @@ import { deleteTeam, getTeam, updateTeam } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface TeamRequestQuery {
|
export interface TeamRequestQuery {
|
||||||
id: string;
|
teamId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TeamRequestBody {
|
export interface TeamRequestBody {
|
||||||
@ -18,7 +18,7 @@ export interface TeamRequestBody {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
teamId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
id: yup.string().uuid().required(),
|
||||||
@ -26,7 +26,7 @@ const schema = {
|
|||||||
accessCode: yup.string().max(50),
|
accessCode: yup.string().max(50),
|
||||||
}),
|
}),
|
||||||
DELETE: yup.object().shape({
|
DELETE: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
teamId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: teamId } = req.query;
|
const { teamId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewTeam(req.auth, teamId))) {
|
if (!(await canViewTeam(req.auth, teamId))) {
|
@ -7,7 +7,7 @@ import { deleteTeamUser, getTeamUser, updateTeamUser } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface TeamUserRequestQuery {
|
export interface TeamUserRequestQuery {
|
||||||
id: string;
|
teamId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export interface TeamUserRequestBody {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
DELETE: yup.object().shape({
|
DELETE: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
teamId: yup.string().uuid().required(),
|
||||||
userId: yup.string().uuid().required(),
|
userId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
@ -35,7 +35,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: teamId, userId } = req.query;
|
const { teamId, userId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
if (!(await canUpdateTeam(req.auth, teamId))) {
|
if (!(await canUpdateTeam(req.auth, teamId))) {
|
@ -8,7 +8,7 @@ import { createTeamUser, getTeamUser, getTeamUsers } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface TeamUserRequestQuery extends SearchFilter {
|
export interface TeamUserRequestQuery extends SearchFilter {
|
||||||
id: string;
|
teamId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TeamUserRequestBody {
|
export interface TeamUserRequestBody {
|
||||||
@ -18,7 +18,7 @@ export interface TeamUserRequestBody {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
teamId: yup.string().uuid().required(),
|
||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
@ -37,7 +37,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: teamId } = req.query;
|
const { teamId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewTeam(req.auth, teamId))) {
|
if (!(await canViewTeam(req.auth, teamId))) {
|
@ -9,7 +9,7 @@ import { createWebsite, getTeamWebsites } from 'queries';
|
|||||||
import { uuid } from 'lib/crypto';
|
import { uuid } from 'lib/crypto';
|
||||||
|
|
||||||
export interface TeamWebsiteRequestQuery extends SearchFilter {
|
export interface TeamWebsiteRequestQuery extends SearchFilter {
|
||||||
id: string;
|
teamId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TeamWebsiteRequestBody {
|
export interface TeamWebsiteRequestBody {
|
||||||
@ -20,7 +20,7 @@ export interface TeamWebsiteRequestBody {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
teamId: yup.string().uuid().required(),
|
||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
@ -37,7 +37,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: teamId } = req.query;
|
const { teamId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewTeam(req.auth, teamId))) {
|
if (!(await canViewTeam(req.auth, teamId))) {
|
@ -6,6 +6,7 @@ import { NextApiResponse } from 'next';
|
|||||||
import { methodNotAllowed, notFound, ok } from 'next-basics';
|
import { methodNotAllowed, notFound, ok } from 'next-basics';
|
||||||
import { createTeamUser, findTeam, getTeamUser } from 'queries';
|
import { createTeamUser, findTeam, getTeamUser } from 'queries';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface TeamsJoinRequestBody {
|
export interface TeamsJoinRequestBody {
|
||||||
accessCode: string;
|
accessCode: string;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
|
import * as yup from 'yup';
|
||||||
import { canDeleteUser, canUpdateUser, canViewUser } from 'lib/auth';
|
import { canDeleteUser, canUpdateUser, canViewUser } from 'lib/auth';
|
||||||
import { useAuth, useValidate } from 'lib/middleware';
|
import { useAuth, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, Role, User } from 'lib/types';
|
import { NextApiRequestQueryBody, Role, User } from 'lib/types';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||||
import { deleteUser, getUser, getUserByUsername, updateUser } from 'queries';
|
import { deleteUser, getUser, getUserByUsername, updateUser } from 'queries';
|
||||||
import * as yup from 'yup';
|
|
||||||
|
|
||||||
export interface UserRequestQuery {
|
export interface UserRequestQuery {
|
||||||
id: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserRequestBody {
|
export interface UserRequestBody {
|
||||||
|
userId: string;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
role: Role;
|
role: Role;
|
||||||
@ -18,10 +19,10 @@ export interface UserRequestBody {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
userId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
userId: yup.string().uuid().required(),
|
||||||
username: yup.string().max(255),
|
username: yup.string().max(255),
|
||||||
password: yup.string(),
|
password: yup.string(),
|
||||||
role: yup.string().matches(/admin|user|view-only/i),
|
role: yup.string().matches(/admin|user|view-only/i),
|
||||||
@ -36,28 +37,28 @@ export default async (
|
|||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
user: { id: userId, isAdmin },
|
user: { isAdmin },
|
||||||
} = req.auth;
|
} = req.auth;
|
||||||
const { id } = req.query;
|
const userId: string = req.query.userId;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewUser(req.auth, id))) {
|
if (!(await canViewUser(req.auth, userId))) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await getUser(id);
|
const user = await getUser(userId);
|
||||||
|
|
||||||
return ok(res, user);
|
return ok(res, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
if (!(await canUpdateUser(req.auth, id))) {
|
if (!(await canUpdateUser(req.auth, userId))) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { username, password, role } = req.body;
|
const { username, password, role } = req.body;
|
||||||
|
|
||||||
const user = await getUser(id);
|
const user = await getUser(userId);
|
||||||
|
|
||||||
const data: any = {};
|
const data: any = {};
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ export default async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updated = await updateUser(data, { id });
|
const updated = await updateUser(userId, data);
|
||||||
|
|
||||||
return ok(res, updated);
|
return ok(res, updated);
|
||||||
}
|
}
|
||||||
@ -93,11 +94,11 @@ export default async (
|
|||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id === userId) {
|
if (userId === req.auth.user.id) {
|
||||||
return badRequest(res, 'You cannot delete yourself.');
|
return badRequest(res, 'You cannot delete yourself.');
|
||||||
}
|
}
|
||||||
|
|
||||||
await deleteUser(id);
|
await deleteUser(userId);
|
||||||
|
|
||||||
return ok(res);
|
return ok(res);
|
||||||
}
|
}
|
@ -1,36 +1,27 @@
|
|||||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
import { NextApiRequestQueryBody } from 'lib/types';
|
||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||||
import { getUserWebsites } from 'queries';
|
import { getUserWebsites } from 'queries';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface UserWebsitesRequestQuery extends SearchFilter {
|
|
||||||
id: string;
|
|
||||||
includeTeams?: boolean;
|
|
||||||
onlyTeams?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
userId: yup.string().uuid().required(),
|
||||||
includeTeams: yup.boolean(),
|
includeTeams: yup.boolean(),
|
||||||
onlyTeams: yup.boolean(),
|
onlyTeams: yup.boolean(),
|
||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async (
|
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
||||||
req: NextApiRequestQueryBody<UserWebsitesRequestQuery>,
|
|
||||||
res: NextApiResponse,
|
|
||||||
) => {
|
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { user } = req.auth;
|
const { user } = req.auth;
|
||||||
const { id: userId, page = 1, pageSize, query = '', ...rest } = req.query;
|
const { userId, page = 1, pageSize, query = '', ...rest } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!user.isAdmin && user.id !== userId) {
|
if (!user.isAdmin && user.id !== userId) {
|
@ -7,12 +7,12 @@ import { getActiveVisitors } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface WebsiteActiveRequestQuery {
|
export interface WebsiteActiveRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,14 +24,14 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId } = req.query;
|
const { websiteId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId as string))) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await getActiveVisitors(websiteId);
|
const result = await getActiveVisitors(websiteId as string);
|
||||||
|
|
||||||
return ok(res, result);
|
return ok(res, result);
|
||||||
}
|
}
|
@ -7,12 +7,12 @@ import { getWebsiteDateRange } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface WebsiteDateRangeRequestQuery {
|
export interface WebsiteDateRangeRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId } = req.query;
|
const { websiteId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
@ -9,7 +9,7 @@ import { getEventMetrics } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface WebsiteEventsRequestQuery {
|
export interface WebsiteEventsRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
startAt: string;
|
startAt: string;
|
||||||
endAt: string;
|
endAt: string;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
@ -19,7 +19,7 @@ export interface WebsiteEventsRequestQuery {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
||||||
unit: UnitTypeTest,
|
unit: UnitTypeTest,
|
||||||
@ -36,7 +36,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId, timezone, url } = req.query;
|
const { websiteId, timezone, url } = req.query;
|
||||||
const { startDate, endDate, unit } = await parseDateRangeQuery(req);
|
const { startDate, endDate, unit } = await parseDateRangeQuery(req);
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
@ -7,7 +7,7 @@ import { deleteWebsite, getWebsite, updateWebsite } from 'queries';
|
|||||||
import { SHARE_ID_REGEX } from 'lib/constants';
|
import { SHARE_ID_REGEX } from 'lib/constants';
|
||||||
|
|
||||||
export interface WebsiteRequestQuery {
|
export interface WebsiteRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebsiteRequestBody {
|
export interface WebsiteRequestBody {
|
||||||
@ -20,10 +20,10 @@ import * as yup from 'yup';
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
name: yup.string(),
|
name: yup.string(),
|
||||||
domain: yup.string(),
|
domain: yup.string(),
|
||||||
shareId: yup.string().matches(SHARE_ID_REGEX, { excludeEmptyString: true }).nullable(),
|
shareId: yup.string().matches(SHARE_ID_REGEX, { excludeEmptyString: true }).nullable(),
|
||||||
@ -38,7 +38,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId } = req.query;
|
const { websiteId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
@ -9,7 +9,7 @@ import { parseDateRangeQuery } from 'lib/query';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface WebsiteMetricsRequestQuery {
|
export interface WebsiteMetricsRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
type: string;
|
type: string;
|
||||||
startAt: number;
|
startAt: number;
|
||||||
endAt: number;
|
endAt: number;
|
||||||
@ -30,7 +30,7 @@ export interface WebsiteMetricsRequestQuery {
|
|||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
type: yup.string().required(),
|
type: yup.string().required(),
|
||||||
startAt: yup.number().required(),
|
startAt: yup.number().required(),
|
||||||
endAt: yup.number().required(),
|
endAt: yup.number().required(),
|
||||||
@ -59,7 +59,7 @@ export default async (
|
|||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
id: websiteId,
|
websiteId,
|
||||||
type,
|
type,
|
||||||
url,
|
url,
|
||||||
referrer,
|
referrer,
|
@ -7,7 +7,7 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|||||||
import { getPageviewStats, getSessionStats } from 'queries';
|
import { getPageviewStats, getSessionStats } from 'queries';
|
||||||
|
|
||||||
export interface WebsitePageviewRequestQuery {
|
export interface WebsitePageviewRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
startAt: number;
|
startAt: number;
|
||||||
endAt: number;
|
endAt: number;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
@ -27,7 +27,7 @@ import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().required(),
|
startAt: yup.number().required(),
|
||||||
endAt: yup.number().required(),
|
endAt: yup.number().required(),
|
||||||
unit: UnitTypeTest,
|
unit: UnitTypeTest,
|
||||||
@ -52,19 +52,8 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const {
|
const { websiteId, timezone, url, referrer, title, os, browser, device, country, region, city } =
|
||||||
id: websiteId,
|
req.query;
|
||||||
timezone,
|
|
||||||
url,
|
|
||||||
referrer,
|
|
||||||
title,
|
|
||||||
os,
|
|
||||||
browser,
|
|
||||||
device,
|
|
||||||
country,
|
|
||||||
region,
|
|
||||||
city,
|
|
||||||
} = req.query;
|
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
@ -8,12 +8,12 @@ import { getWebsiteReports } from 'queries';
|
|||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
|
|
||||||
export interface ReportsRequestQuery extends SearchFilter {
|
export interface ReportsRequestQuery extends SearchFilter {
|
||||||
id: string;
|
websiteId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
...pageInfo,
|
...pageInfo,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@ -26,7 +26,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId } = req.query;
|
const { websiteId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
@ -7,12 +7,12 @@ import { resetWebsite } from 'queries';
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
|
|
||||||
export interface WebsiteResetRequestQuery {
|
export interface WebsiteResetRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
POST: yup.object().shape({
|
POST: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId } = req.query;
|
const { websiteId } = req.query;
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
if (!(await canUpdateWebsite(req.auth, websiteId))) {
|
if (!(await canUpdateWebsite(req.auth, websiteId))) {
|
@ -8,7 +8,7 @@ import { parseDateRangeQuery } from 'lib/query';
|
|||||||
import { getWebsiteStats } from 'queries';
|
import { getWebsiteStats } from 'queries';
|
||||||
|
|
||||||
export interface WebsiteStatsRequestQuery {
|
export interface WebsiteStatsRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
startAt: number;
|
startAt: number;
|
||||||
endAt: number;
|
endAt: number;
|
||||||
url?: string;
|
url?: string;
|
||||||
@ -27,7 +27,7 @@ export interface WebsiteStatsRequestQuery {
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().required(),
|
startAt: yup.number().required(),
|
||||||
endAt: yup.number().required(),
|
endAt: yup.number().required(),
|
||||||
url: yup.string(),
|
url: yup.string(),
|
||||||
@ -53,7 +53,7 @@ export default async (
|
|||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
id: websiteId,
|
websiteId,
|
||||||
url,
|
url,
|
||||||
referrer,
|
referrer,
|
||||||
title,
|
title,
|
||||||
@ -65,7 +65,7 @@ export default async (
|
|||||||
country,
|
country,
|
||||||
region,
|
region,
|
||||||
city,
|
city,
|
||||||
} = req.query;
|
}: any & { websiteId: string } = req.query;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
@ -8,7 +8,7 @@ import { getValues } from 'queries';
|
|||||||
import { parseDateRangeQuery } from 'lib/query';
|
import { parseDateRangeQuery } from 'lib/query';
|
||||||
|
|
||||||
export interface ValuesRequestQuery {
|
export interface ValuesRequestQuery {
|
||||||
id: string;
|
websiteId: string;
|
||||||
startAt: number;
|
startAt: number;
|
||||||
endAt: number;
|
endAt: number;
|
||||||
}
|
}
|
||||||
@ -16,7 +16,7 @@ export interface ValuesRequestQuery {
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().required(),
|
startAt: yup.number().required(),
|
||||||
endAt: yup.number().required(),
|
endAt: yup.number().required(),
|
||||||
}),
|
}),
|
||||||
@ -27,7 +27,7 @@ export default async (req: NextApiRequestQueryBody<ValuesRequestQuery>, res: Nex
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { id: websiteId, type } = req.query;
|
const { websiteId, type } = req.query;
|
||||||
const { startDate, endDate } = await parseDateRangeQuery(req);
|
const { startDate, endDate } = await parseDateRangeQuery(req);
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
@ -5,7 +5,7 @@ import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
|||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||||
import { createWebsite } from 'queries';
|
import { createWebsite } from 'queries';
|
||||||
import userWebsites from 'pages/api/users/[id]/websites';
|
import userWebsites from 'pages/api/users/[userId]/websites';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
|
|
||||||
@ -41,11 +41,11 @@ export default async (
|
|||||||
} = req.auth;
|
} = req.auth;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (!req.query.id) {
|
if (!req.query.userId) {
|
||||||
req.query.id = userId;
|
req.query.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return userWebsites(req as any, res);
|
return userWebsites(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
|
@ -84,7 +84,7 @@ export async function getReports(
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
return prisma.pagedQuery('report', { where }, filters);
|
return prisma.pagedQuery('report', { ...criteria, where }, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserReports(
|
export async function getUserReports(
|
||||||
|
@ -50,6 +50,17 @@ export async function createTeamUser(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateTeamUser(teamUserId: string, data: any): Promise<TeamUser> {
|
||||||
|
return prisma.client.teamUser.update(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: teamUserId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function deleteTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
export async function deleteTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
||||||
const { client } = prisma;
|
const { client } = prisma;
|
||||||
|
|
||||||
|
@ -112,12 +112,11 @@ export async function createUser(data: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateUser(
|
export async function updateUser(userId: string, data: Prisma.UserUpdateInput): Promise<User> {
|
||||||
data: Prisma.UserUpdateInput,
|
|
||||||
where: Prisma.UserWhereUniqueInput,
|
|
||||||
): Promise<User> {
|
|
||||||
return prisma.client.user.update({
|
return prisma.client.user.update({
|
||||||
where,
|
where: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
data,
|
data,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
@ -138,7 +138,7 @@ export async function updateWebsite(
|
|||||||
): Promise<Website> {
|
): Promise<Website> {
|
||||||
return prisma.client.website.update({
|
return prisma.client.website.update({
|
||||||
where: {
|
where: {
|
||||||
id: websiteId,
|
websiteId,
|
||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
@ -160,7 +160,7 @@ export async function resetWebsite(
|
|||||||
where: { websiteId },
|
where: { websiteId },
|
||||||
}),
|
}),
|
||||||
client.website.update({
|
client.website.update({
|
||||||
where: { id: websiteId },
|
where: { websiteId },
|
||||||
data: {
|
data: {
|
||||||
resetAt: new Date(),
|
resetAt: new Date(),
|
||||||
},
|
},
|
||||||
@ -200,10 +200,10 @@ export async function deleteWebsite(
|
|||||||
data: {
|
data: {
|
||||||
deletedAt: new Date(),
|
deletedAt: new Date(),
|
||||||
},
|
},
|
||||||
where: { id: websiteId },
|
where: { websiteId },
|
||||||
})
|
})
|
||||||
: client.website.delete({
|
: client.website.delete({
|
||||||
where: { id: websiteId },
|
where: { websiteId },
|
||||||
}),
|
}),
|
||||||
]).then(async data => {
|
]).then(async data => {
|
||||||
if (cache.enabled) {
|
if (cache.enabled) {
|
||||||
|
@ -134,7 +134,7 @@ async function clickhouseQuery(data: {
|
|||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
...args,
|
...args,
|
||||||
website_id: websiteId,
|
website_websiteId,
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
event_id: uuid(),
|
event_id: uuid(),
|
||||||
country: country,
|
country: country,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user