@@ -16,19 +16,17 @@ export const getUser = async (
1616 res : Response ,
1717) : Promise < Response > => {
1818 try {
19- // const token = req.headers.authorization?.split(" ")[1];
19+ const token = req . headers . authorization ?. split ( " " ) [ 1 ] ;
2020
21+ // checking for the authorization token
2122
22- const token = req . headers . authorization ?. split ( " " ) [ 1 ] ;
23-
24- //checking for the authorization token
25- if ( ! token ) {
26- return res . status ( HTTP . OK ) . json ( {
27- message : 'Invalid Token' ,
28- } ) ;
29- }
23+ if ( ! token ) {
24+ return res . status ( HTTP . OK ) . json ( {
25+ message : "Invalid Token" ,
26+ } ) ;
27+ }
3028
31- //const decodedToken = jwt.verify(token, "veriedRefreshedUser");
29+ //const decodedToken = jwt.verify(token, "veriedRefreshedUser");
3230
3331 // if (!token) {
3432 // return res.status(HTTP.OK).json({
@@ -38,7 +36,6 @@ if (!token) {
3836
3937 //const decodedToken = jwt.verify(token, "veriedRefreshedUser");
4038
41-
4239 // return res.status(HTTP.OK).json({
4340 // success: true,
4441 // data: decodedToken
@@ -694,4 +691,241 @@ export const refreshUserToken = async (req: Request, res: Response) => {
694691 } catch ( error ) {
695692 console . log ( error ) ;
696693 }
694+ } ;
695+
696+
697+ //editing the user location profile
698+ export const updateLocation = async (
699+ req : Request ,
700+ res : Response ,
701+ ) : Promise < Response > => {
702+ try {
703+ const { id } = req . params ;
704+ const {
705+
706+ location,
707+ address,
708+ placeOfBirth,
709+ LGA ,
710+ stateOfOrigin
711+ } = req . body ;
712+
713+ const user = await userModel . findByIdAndUpdate (
714+ id ,
715+ {
716+ location,
717+ address,
718+ placeOfBirth,
719+ LGA ,
720+ stateOfOrigin,
721+ } ,
722+ { new : true } ,
723+ ) ;
724+
725+ return res . status ( HTTP . OK ) . json ( {
726+ message : "Updating user's location info" ,
727+ data : user ,
728+ } ) ;
729+ } catch ( err ) {
730+ new mainAppErrorHandler ( {
731+ message : `Unable to update user` ,
732+ status : HTTP . BAD_REQUEST ,
733+ name : "user update Error" ,
734+ isSuccess : false ,
735+ } ) ;
736+
737+ return res . status ( HTTP . BAD_REQUEST ) . json ( {
738+ message : "Error Found" ,
739+ data : err ,
740+ } ) ;
741+ }
742+ } ;
743+
744+ //editing the user Religious profile
745+ export const religiousUpdate = async (
746+ req : Request ,
747+ res : Response ,
748+ ) : Promise < Response > => {
749+ try {
750+ const { id } = req . params ;
751+ const { religion } = req . body ;
752+
753+ const user = await userModel . findByIdAndUpdate (
754+ id ,
755+ {
756+ religion,
757+ } ,
758+ { new : true } ,
759+ ) ;
760+
761+ return res . status ( HTTP . OK ) . json ( {
762+ message : "Updating user's location info" ,
763+ data : user ,
764+ } ) ;
765+ } catch ( err ) {
766+ new mainAppErrorHandler ( {
767+ message : `Unable to update user` ,
768+ status : HTTP . BAD_REQUEST ,
769+ name : "user update Error" ,
770+ isSuccess : false ,
771+ } ) ;
772+
773+ return res . status ( HTTP . BAD_REQUEST ) . json ( {
774+ message : "Error Found" ,
775+ data : err ,
776+ } ) ;
777+ }
778+ } ;
779+
780+ //editing the user Academic profile
781+ export const academicUpdate = async (
782+ req : Request ,
783+ res : Response ,
784+ ) : Promise < Response > => {
785+ try {
786+ const { id } = req . params ;
787+ const {
788+ primarySchool,
789+ secondarySchool,
790+ college
791+ } = req . body ;
792+
793+ const user = await userModel . findByIdAndUpdate (
794+ id ,
795+ {
796+ primarySchool,
797+ secondarySchool,
798+ college,
799+ } ,
800+ { new : true } ,
801+ ) ;
802+
803+ return res . status ( HTTP . OK ) . json ( {
804+ message : "Updating user's academic info" ,
805+ data : user ,
806+ } ) ;
807+ } catch ( err ) {
808+ new mainAppErrorHandler ( {
809+ message : `Unable to update user` ,
810+ status : HTTP . BAD_REQUEST ,
811+ name : "user update Error" ,
812+ isSuccess : false ,
813+ } ) ;
814+
815+ return res . status ( HTTP . BAD_REQUEST ) . json ( {
816+ message : "Error Found" ,
817+ data : err ,
818+ } ) ;
819+ }
820+ } ;
821+
822+ //editing the user Professional profile
823+ export const professionalUpdate = async (
824+ req : Request ,
825+ res : Response ,
826+ ) : Promise < Response > => {
827+ try {
828+ const { id } = req . params ;
829+ const {
830+ profession
831+ } = req . body ;
832+
833+ const user = await userModel . findByIdAndUpdate (
834+ id ,
835+ {
836+ profession,
837+ } ,
838+ { new : true } ,
839+ ) ;
840+
841+ return res . status ( HTTP . OK ) . json ( {
842+ message : "Updating user's academic info" ,
843+ data : user ,
844+ } ) ;
845+ } catch ( err ) {
846+ new mainAppErrorHandler ( {
847+ message : `Unable to update user` ,
848+ status : HTTP . BAD_REQUEST ,
849+ name : "user update Error" ,
850+ isSuccess : false ,
851+ } ) ;
852+
853+ return res . status ( HTTP . BAD_REQUEST ) . json ( {
854+ message : "Error Found" ,
855+ data : err ,
856+ } ) ;
857+ }
858+ } ;
859+
860+ //editing the user Bio profile
861+ export const bioUpdate = async (
862+ req : Request ,
863+ res : Response ,
864+ ) : Promise < Response > => {
865+ try {
866+ const { id } = req . params ;
867+ const {
868+ bio
869+ } = req . body ;
870+
871+ const user = await userModel . findByIdAndUpdate (
872+ id ,
873+ {
874+ bio,
875+ } ,
876+ { new : true } ,
877+ ) ;
878+
879+ return res . status ( HTTP . OK ) . json ( {
880+ message : "Updating user's academic info" ,
881+ data : user ,
882+ } ) ;
883+ } catch ( err ) {
884+ new mainAppErrorHandler ( {
885+ message : `Unable to update user` ,
886+ status : HTTP . BAD_REQUEST ,
887+ name : "user update Error" ,
888+ isSuccess : false ,
889+ } ) ;
890+
891+ return res . status ( HTTP . BAD_REQUEST ) . json ( {
892+ message : "Error Found" ,
893+ data : err ,
894+ } ) ;
895+ }
896+ } ;
897+
898+ //editing the user music profile
899+ export const musicUpdate = async (
900+ req : Request ,
901+ res : Response ,
902+ ) : Promise < Response > => {
903+ try {
904+ const { id } = req . params ;
905+ const {
906+ music
907+ } = req . body ;
908+
909+ const user = await userModel . findById ( id )
910+
911+ user ?. music ?. push ( ...user ?. music , music ) ;
912+ // user.save()
913+
914+ return res . status ( HTTP . OK ) . json ( {
915+ message : "Updating user's academic info" ,
916+ data : user ,
917+ } ) ;
918+ } catch ( err ) {
919+ new mainAppErrorHandler ( {
920+ message : `Unable to update user` ,
921+ status : HTTP . BAD_REQUEST ,
922+ name : "user update Error" ,
923+ isSuccess : false ,
924+ } ) ;
925+
926+ return res . status ( HTTP . BAD_REQUEST ) . json ( {
927+ message : "Error Found" ,
928+ data : err ,
929+ } ) ;
930+ }
697931} ;
0 commit comments