@@ -7,26 +7,49 @@ dotEnv.config();
7
7
8
8
export default class changeUserProfile {
9
9
static async getProfileInformation ( request , response ) {
10
- const myProfile = await models . User . findOne ( { where : { id : request . user . id } } ) ;
11
- return response . status ( 200 ) . json ( { status : 200 , user : returnProfile ( myProfile ) } ) ;
10
+ try {
11
+ const myProfile = await models . User . findOne ( {
12
+ where : { id : request . user . id } ,
13
+ } ) ;
14
+ return response
15
+ . status ( 200 )
16
+ . json ( { status : 200 , user : returnProfile ( myProfile ) } ) ;
17
+ } catch ( error ) {
18
+ return response . status ( 500 ) . json ( { status : 500 , error } ) ;
19
+ }
12
20
}
13
21
14
22
static changeMyProfileInfo ( request , response ) {
15
- request . body . birthDay = validateDate ( request . body . birthDay ) ;
16
- request . body . profileImage = ( typeof request . file === 'undefined' ) ? null : `${ request . file . url } ` ;
17
- return models . User . update ( request . body , { where : { id : request . user . id } } )
18
- . then ( ( ) => models . User . findOne ( { where : { id : request . user . id } } ) )
19
- . then ( ( user ) => {
20
- response . status ( 200 ) . json ( { status : 200 , user : returnProfile ( user ) } ) ;
21
- } ) ;
23
+ try {
24
+ request . body . birthDay = validateDate ( request . body . birthDay ) ;
25
+ request . body . profileImage =
26
+ typeof request . file === 'undefined'
27
+ ? request . body . profileImage
28
+ : `${ request . file . url } ` ;
29
+ return models . User . update ( request . body , {
30
+ where : { id : request . user . id } ,
31
+ } )
32
+ . then ( ( ) => models . User . findOne ( { where : { id : request . user . id } } ) )
33
+ . then ( ( user ) => {
34
+ response . status ( 200 ) . json ( { status : 200 , user : returnProfile ( user ) } ) ;
35
+ } ) ;
36
+ } catch ( error ) {
37
+ return response . status ( 500 ) . json ( { status : 500 , error } ) ;
38
+ }
22
39
}
23
40
24
41
static async rememberMe ( req , res ) {
25
42
try {
26
- const userInfo = await models . User . findOne ( { where : { id : req . user . id } } ) ;
43
+ const userInfo = await models . User . findOne ( {
44
+ where : { id : req . user . id } ,
45
+ } ) ;
27
46
const { password, ...rest } = userInfo . dataValues ;
28
47
req . session . profileInfo = rest ;
29
- return res . status ( 200 ) . send ( { status : 200 , message : 'Your profile information is saved successfully' , data : req . session . profileInfo } ) ;
48
+ return res . status ( 200 ) . send ( {
49
+ status : 200 ,
50
+ message : 'Your profile information is saved successfully' ,
51
+ data : req . session . profileInfo ,
52
+ } ) ;
30
53
} catch ( error ) {
31
54
return res . status ( 500 ) . json ( { status : 500 , error } ) ;
32
55
}
0 commit comments