Clean up teams on user delete.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { NextApiRequestQueryBody, User } from 'lib/types';
|
||||
import { canDeleteUser, canUpdateUser, canViewUser } from 'lib/auth';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { deleteUser, getUser, updateUser, User } from 'queries';
|
||||
import { deleteUser, getUser, updateUser } from 'queries';
|
||||
|
||||
export interface UserRequestQuery {
|
||||
id: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { canCreateUser, canViewUsers } from 'lib/auth';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody, User } from 'lib/types';
|
||||
import { NextApiRequestQueryBody, Roles, User } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, hashPassword, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createUser, getUser, getUsers } from 'queries';
|
||||
@@ -11,6 +11,7 @@ export interface UsersRequestBody {
|
||||
username: string;
|
||||
password: string;
|
||||
id: string;
|
||||
role?: Roles;
|
||||
}
|
||||
|
||||
export default async (
|
||||
@@ -34,7 +35,7 @@ export default async (
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { username, password, id } = req.body;
|
||||
const { username, password, role, id } = req.body;
|
||||
|
||||
const existingUser = await getUser({ username }, { showDeleted: true });
|
||||
|
||||
@@ -46,7 +47,7 @@ export default async (
|
||||
id: id || uuid(),
|
||||
username,
|
||||
password: hashPassword(password),
|
||||
role: ROLES.user,
|
||||
role: role ?? ROLES.user,
|
||||
});
|
||||
|
||||
return ok(res, created);
|
||||
|
||||
Reference in New Issue
Block a user