mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-30 13:41:50 +02:00
Fix Typo.
This commit is contained in:
parent
5aa8187e42
commit
f5eb974d8d
87
pages/api/teams/[id]/index.ts
Normal file
87
pages/api/teams/[id]/index.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getTeam, deleteTeam, updateTeam } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { Team } from '@prisma/client';
|
||||
|
||||
export interface TeamRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface TeamRequestBody {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<TeamRequestQuery, TeamRequestBody>,
|
||||
res: NextApiResponse<Team>,
|
||||
) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const {
|
||||
user: { id: userId, isAdmin },
|
||||
} = req.auth;
|
||||
const { id } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (id !== userId && !isAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const user = await getTeam({ id });
|
||||
|
||||
return ok(res, user);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { username, password } = req.body;
|
||||
|
||||
if (id !== userId && !isAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const user = await getTeam({ id });
|
||||
|
||||
const data: any = {};
|
||||
|
||||
if (password) {
|
||||
data.password = hashPassword(password);
|
||||
}
|
||||
|
||||
// Only admin can change these fields
|
||||
if (isAdmin) {
|
||||
data.username = username;
|
||||
}
|
||||
|
||||
// Check when username changes
|
||||
if (data.username && user.username !== data.username) {
|
||||
const userByTeamname = await getTeam({ username });
|
||||
|
||||
if (userByTeamname) {
|
||||
return badRequest(res, 'Team already exists');
|
||||
}
|
||||
}
|
||||
|
||||
const updated = await updateTeam(data, { id });
|
||||
|
||||
return ok(res, updated);
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (id === userId) {
|
||||
return badRequest(res, 'You cannot delete your own user.');
|
||||
}
|
||||
|
||||
if (!isAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
await deleteTeam(id);
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
0
pages/api/teams/index.ts
Normal file
0
pages/api/teams/index.ts
Normal file
|
@ -5,17 +5,17 @@ import { NextApiResponse } from 'next';
|
|||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { User } from 'interface/api/models';
|
||||
|
||||
export interface UserReqeustQuery {
|
||||
export interface UserRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface UserReqeustBody {
|
||||
export interface UserRequestBody {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<UserReqeustQuery, UserReqeustBody>,
|
||||
req: NextApiRequestQueryBody<UserRequestQuery, UserRequestBody>,
|
||||
res: NextApiResponse<User>,
|
||||
) => {
|
||||
await useAuth(req, res);
|
||||
|
|
|
@ -7,18 +7,18 @@ import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
|||
import { NextApiResponse } from 'next';
|
||||
import { Website } from 'interface/api/models';
|
||||
|
||||
export interface WebsiteReqeustQuery {
|
||||
export interface WebsiteRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface WebsiteReqeustBody {
|
||||
export interface WebsiteRequestBody {
|
||||
name: string;
|
||||
domain: string;
|
||||
shareId: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteReqeustQuery, WebsiteReqeustBody>,
|
||||
req: NextApiRequestQueryBody<WebsiteRequestQuery, WebsiteRequestBody>,
|
||||
res: NextApiResponse<Website | any>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
@ -36,7 +36,7 @@ function getColumn(type) {
|
|||
return type;
|
||||
}
|
||||
|
||||
export interface WebsiteMetricsReqeustQuery {
|
||||
export interface WebsiteMetricsRequestQuery {
|
||||
id: string;
|
||||
type: string;
|
||||
start_at: number;
|
||||
|
@ -50,7 +50,7 @@ export interface WebsiteMetricsReqeustQuery {
|
|||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteMetricsReqeustQuery>,
|
||||
req: NextApiRequestQueryBody<WebsiteMetricsRequestQuery>,
|
||||
res: NextApiResponse<WebsiteMetric[]>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
@ -10,7 +10,7 @@ import { getPageviewStats } from 'queries';
|
|||
|
||||
const unitTypes = ['year', 'month', 'hour', 'day'];
|
||||
|
||||
export interface WebsitePageviewReqeustQuery {
|
||||
export interface WebsitePageviewRequestQuery {
|
||||
id: string;
|
||||
websiteId: string;
|
||||
start_at: number;
|
||||
|
@ -26,7 +26,7 @@ export interface WebsitePageviewReqeustQuery {
|
|||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsitePageviewReqeustQuery>,
|
||||
req: NextApiRequestQueryBody<WebsitePageviewRequestQuery>,
|
||||
res: NextApiResponse<WebsitePageviews>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
@ -6,12 +6,12 @@ import { TYPE_WEBSITE } from 'lib/constants';
|
|||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
||||
export interface WebsiteResetReqeustQuery {
|
||||
export interface WebsiteResetRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteResetReqeustQuery>,
|
||||
req: NextApiRequestQueryBody<WebsiteResetRequestQuery>,
|
||||
res: NextApiResponse,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
@ -7,7 +7,7 @@ import { WebsiteStats } from 'interface/api/models';
|
|||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiResponse } from 'next';
|
||||
|
||||
export interface WebsiteStatsReqeustQuery {
|
||||
export interface WebsiteStatsRequestQuery {
|
||||
id: string;
|
||||
type: string;
|
||||
start_at: number;
|
||||
|
@ -21,7 +21,7 @@ export interface WebsiteStatsReqeustQuery {
|
|||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteStatsReqeustQuery>,
|
||||
req: NextApiRequestQueryBody<WebsiteStatsRequestQuery>,
|
||||
res: NextApiResponse<WebsiteStats>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
|
@ -5,18 +5,18 @@ import { NextApiResponse } from 'next';
|
|||
import { getRandomChars, methodNotAllowed, ok } from 'next-basics';
|
||||
import { createWebsiteByUser, getAllWebsites, getWebsitesByUserId } from 'queries';
|
||||
|
||||
export interface WebsitesReqeustQuery {
|
||||
export interface WebsitesRequestQuery {
|
||||
include_all?: boolean;
|
||||
}
|
||||
|
||||
export interface WebsitesReqeustBody {
|
||||
export interface WebsitesRequestBody {
|
||||
name: string;
|
||||
domain: string;
|
||||
enableShareUrl: boolean;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsitesReqeustQuery, WebsitesReqeustBody>,
|
||||
req: NextApiRequestQueryBody<WebsitesRequestQuery, WebsitesRequestBody>,
|
||||
res: NextApiResponse,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
|
|
Loading…
Reference in New Issue
Block a user