mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-30 13:41:50 +02:00
Added different methods to get user websites and teams.
This commit is contained in:
parent
5189486d6f
commit
f4aa8f9661
15
pages/api/me/teams.ts
Normal file
15
pages/api/me/teams.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { useCors } from 'lib/middleware';
|
||||||
|
import { NextApiRequestQueryBody } from 'lib/types';
|
||||||
|
import { NextApiResponse } from 'next';
|
||||||
|
import { methodNotAllowed } from 'next-basics';
|
||||||
|
import userTeams from 'pages/api/users/[id]/teams';
|
||||||
|
|
||||||
|
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
||||||
|
await useCors(req, res);
|
||||||
|
|
||||||
|
if (req.method === 'GET') {
|
||||||
|
return userTeams(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
return methodNotAllowed(res);
|
||||||
|
};
|
|
@ -1,21 +1,18 @@
|
||||||
import { useAuth, useCors } from 'lib/middleware';
|
import { useAuth, useCors } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody } from 'lib/types';
|
import { NextApiRequestQueryBody } from 'lib/types';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed, ok } from 'next-basics';
|
import { methodNotAllowed } from 'next-basics';
|
||||||
import { getUserWebsites } from 'queries';
|
|
||||||
|
import userWebsites from 'pages/api/users/[id]/websites';
|
||||||
|
|
||||||
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
|
||||||
const {
|
|
||||||
user: { id: userId },
|
|
||||||
} = req.auth;
|
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const websites = await getUserWebsites(userId);
|
req.query.id = req.auth.user.id;
|
||||||
|
|
||||||
return ok(res, websites);
|
return userWebsites(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return methodNotAllowed(res);
|
return methodNotAllowed(res);
|
||||||
|
|
34
pages/api/users/[id]/teams.ts
Normal file
34
pages/api/users/[id]/teams.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { useAuth, useCors } from 'lib/middleware';
|
||||||
|
import { NextApiRequestQueryBody } from 'lib/types';
|
||||||
|
import { NextApiResponse } from 'next';
|
||||||
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||||
|
import { getUserTeams } from 'queries';
|
||||||
|
|
||||||
|
export interface UserWebsitesRequestBody {
|
||||||
|
name: string;
|
||||||
|
domain: string;
|
||||||
|
shareId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async (
|
||||||
|
req: NextApiRequestQueryBody<any, UserWebsitesRequestBody>,
|
||||||
|
res: NextApiResponse,
|
||||||
|
) => {
|
||||||
|
await useCors(req, res);
|
||||||
|
await useAuth(req, res);
|
||||||
|
|
||||||
|
const { user } = req.auth;
|
||||||
|
const { id: userId } = req.query;
|
||||||
|
|
||||||
|
if (req.method === 'GET') {
|
||||||
|
if (!user.isAdmin && user.id !== userId) {
|
||||||
|
return unauthorized(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
const teams = await getUserTeams(userId);
|
||||||
|
|
||||||
|
return ok(res, teams);
|
||||||
|
}
|
||||||
|
|
||||||
|
return methodNotAllowed(res);
|
||||||
|
};
|
|
@ -16,7 +16,6 @@ export default async (
|
||||||
) => {
|
) => {
|
||||||
await useCors(req, res);
|
await useCors(req, res);
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
|
||||||
const { user } = req.auth;
|
const { user } = req.auth;
|
||||||
const { id: userId } = req.query;
|
const { id: userId } = req.query;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { useAuth, useCors } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody } from 'lib/types';
|
import { NextApiRequestQueryBody } 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, getUserWebsites } from 'queries';
|
import { createWebsite } from 'queries';
|
||||||
|
import userWebsites from 'pages/api/users/[id]/websites';
|
||||||
|
|
||||||
export interface WebsitesRequestBody {
|
export interface WebsitesRequestBody {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -24,9 +25,9 @@ export default async (
|
||||||
} = req.auth;
|
} = req.auth;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const websites = await getUserWebsites(userId);
|
req.query.id = userId;
|
||||||
|
|
||||||
return ok(res, websites);
|
return userWebsites(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user