File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
client/components/UpdateUserModal Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -753,7 +753,19 @@ export function authRoutes(fastify: FastifyInstance) {
753753 const token = checkToken ( bearer ) ;
754754 if ( token ) {
755755 const { id, role } = request . body as { id : string ; role : boolean } ;
756-
756+ // check for atleast one admin on role downgrade
757+ if ( role === false ) {
758+ const admins = await prisma . user . findMany ( {
759+ where : { isAdmin : true } ,
760+ } ) ;
761+ if ( admins . length === 1 ) {
762+ reply . code ( 400 ) . send ( {
763+ message : "Atleast one admin is required" ,
764+ success : false
765+ } ) ;
766+ return ;
767+ }
768+ }
757769 await prisma . user . update ( {
758770 where : { id } ,
759771 data : {
Original file line number Diff line number Diff line change 11import { Dialog , Transition } from "@headlessui/react" ;
22import { XMarkIcon } from "@heroicons/react/24/outline" ;
3+ import { notifications } from "@mantine/notifications" ;
34import { getCookie } from "cookies-next" ;
45import { useRouter } from "next/router" ;
56import { Fragment , useState } from "react" ;
@@ -22,6 +23,24 @@ export default function UpdateUserModal({ user }) {
2223 role : admin ,
2324 id : user . id ,
2425 } ) ,
26+ } )
27+ . then ( ( res ) => res . json ( ) )
28+ . then ( ( res ) => {
29+ if ( res . success === true ) {
30+ notifications . show ( {
31+ title : "User Updated" ,
32+ message : "User updated succesfully" ,
33+ color : "green" ,
34+ autoClose : 5000 ,
35+ } ) ;
36+ } else {
37+ notifications . show ( {
38+ title : "Error" ,
39+ message : res . message ,
40+ color : "red" ,
41+ autoClose : 5000 ,
42+ } ) ;
43+ }
2544 } ) ;
2645 // .then(() => router.reload());
2746 }
You can’t perform that action at this time.
0 commit comments