@@ -4,37 +4,34 @@ import { ApiResponse, StatusMessageType } from "../types";
4
4
import { handleCustomError , handleServerError } from "../utils" ;
5
5
6
6
export async function updateRoleHandler ( req : Request , res : Response ) {
7
- const em = req . orm . em . fork ( ) ;
8
- const body = req . body ;
7
+ const em = req . orm . em . fork ( ) ;
8
+ const body = req . body ;
9
9
10
- try {
11
- if ( body . role !== Role . USER && body . role !== Role . ADMIN ) {
12
- return handleCustomError (
13
- res ,
14
- {
15
- message : "Invalid role specified" ,
16
- type : StatusMessageType . ERROR
17
- }
18
- ) ;
19
- }
20
-
21
- const loadedProfile = await em . findOneOrFail ( Profile , {
22
- uid : body . uid
23
- } ) ;
10
+ try {
11
+ if ( body . role !== Role . USER && body . role !== Role . ADMIN ) {
12
+ return handleCustomError ( res , {
13
+ message : "Invalid role specified" ,
14
+ type : StatusMessageType . ERROR ,
15
+ } ) ;
16
+ }
24
17
25
- loadedProfile . role = body . role ;
18
+ const loadedProfile = await em . findOneOrFail ( Profile , {
19
+ uid : body . uid ,
20
+ } ) ;
26
21
27
- await em . flush ( ) ;
22
+ loadedProfile . role = body . role ;
28
23
29
- const response : ApiResponse = {
30
- statusMessage : {
31
- message : "Role updated successfully" ,
32
- type : StatusMessageType . SUCCESS ,
33
- } ,
34
- payload : loadedProfile ,
35
- } ;
36
- res . status ( 200 ) . send ( response ) ;
37
- } catch ( err : any ) {
38
- handleServerError ( err , res ) ;
39
- }
24
+ await em . flush ( ) ;
25
+
26
+ const response : ApiResponse = {
27
+ statusMessage : {
28
+ message : "Role updated successfully" ,
29
+ type : StatusMessageType . SUCCESS ,
30
+ } ,
31
+ payload : loadedProfile ,
32
+ } ;
33
+ res . status ( 200 ) . send ( response ) ;
34
+ } catch ( err : any ) {
35
+ handleServerError ( err , res ) ;
36
+ }
40
37
}
0 commit comments