mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 08:37:13 +01:00
Refactored queries.
This commit is contained in:
parent
f36a689817
commit
8904b7b4ed
27 changed files with 137 additions and 144 deletions
|
|
@ -4,7 +4,7 @@ import { canDeleteTeam, canUpdateTeam, canViewTeam } from 'lib/auth';
|
|||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { deleteTeam, getTeam, updateTeam } from 'queries';
|
||||
import { deleteTeam, getTeamById, updateTeam } from 'queries';
|
||||
|
||||
export interface TeamRequestQuery {
|
||||
id: string;
|
||||
|
|
@ -28,7 +28,7 @@ export default async (
|
|||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const user = await getTeam({ id: teamId });
|
||||
const user = await getTeamById(teamId, { includeTeamUser: true });
|
||||
|
||||
return ok(res, user);
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ export default async (
|
|||
const { name, accessCode } = req.body;
|
||||
const data = { name, accessCode };
|
||||
|
||||
const updated = await updateTeam(data, { id: teamId });
|
||||
const updated = await updateTeam(teamId, data);
|
||||
|
||||
return ok(res, updated);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { useAuth } from 'lib/middleware';
|
|||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createTeamUser, getTeamUsers, getUser } from 'queries';
|
||||
import { createTeamUser, getTeamUsers, getUserByUsername } from 'queries';
|
||||
|
||||
export interface TeamUserRequestQuery {
|
||||
id: string;
|
||||
|
|
@ -40,7 +40,7 @@ export default async (
|
|||
const { email, roleId: roleId } = req.body;
|
||||
|
||||
// Check for User
|
||||
const user = await getUser({ username: email });
|
||||
const user = await getUserByUsername(email);
|
||||
|
||||
if (!user) {
|
||||
return badRequest(res, 'The User does not exists.');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { NextApiRequestQueryBody } from 'lib/types';
|
|||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, notFound } from 'next-basics';
|
||||
import { createTeamUser, getTeam, getTeamUser } from 'queries';
|
||||
import { createTeamUser, getTeamByAccessCode, getTeamUser } from 'queries';
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
export interface TeamsJoinRequestBody {
|
||||
|
|
@ -19,7 +19,7 @@ export default async (
|
|||
if (req.method === 'POST') {
|
||||
const { accessCode } = req.body;
|
||||
|
||||
const team = await getTeam({ accessCode });
|
||||
const team = await getTeamByAccessCode(accessCode);
|
||||
|
||||
if (!team) {
|
||||
return notFound(res, 'message.team-not-found');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue