Clean up teams on user delete.

This commit is contained in:
Brian Cao 2023-03-02 22:48:30 -08:00
parent 82f0bc3d2b
commit 8684781624
8 changed files with 90 additions and 14 deletions

View file

@ -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;

View file

@ -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);