@@ -878,3 +878,50 @@ export const userRemoveCongregation = async (req: Request, res: Response) => {
878878 res . locals . message = 'admin removed a user from a congregation' ;
879879 res . status ( 200 ) . json ( result ) ;
880880} ;
881+
882+ export const updateBasicCongregationInfo = async ( req : Request , res : Response ) => {
883+ const errors = validationResult ( req ) ;
884+
885+ if ( ! errors . isEmpty ( ) ) {
886+ const msg = formatError ( errors ) ;
887+
888+ res . locals . type = 'warn' ;
889+ res . locals . message = `invalid input: ${ msg } ` ;
890+
891+ res . status ( 400 ) . json ( { message : 'error_api_bad-request' } ) ;
892+
893+ return ;
894+ }
895+
896+ const { id } = req . params ;
897+
898+ if ( ! id || id === 'undefined' ) {
899+ res . locals . type = 'warn' ;
900+ res . locals . message = 'the congregation request id params is undefined' ;
901+ res . status ( 400 ) . json ( { message : 'REQUEST_ID_INVALID' } ) ;
902+
903+ return ;
904+ }
905+
906+ const cong = CongregationsList . findById ( id ) ;
907+
908+ if ( ! cong ) {
909+ res . locals . type = 'warn' ;
910+ res . locals . message = 'no congregation could not be found with the provided id' ;
911+ res . status ( 404 ) . json ( { message : 'CONGREGATION_NOT_FOUND' } ) ;
912+ return ;
913+ }
914+
915+ const settings = structuredClone ( cong . settings ) ;
916+
917+ settings . cong_name = req . body . name as string ;
918+ settings . cong_number = req . body . number as string ;
919+
920+ await cong . saveSettings ( settings ) ;
921+
922+ const result = await adminCongregationsGet ( ) ;
923+
924+ res . locals . type = 'info' ;
925+ res . locals . message = `admin update basic info for congregation ${ id } ` ;
926+ res . status ( 200 ) . json ( result ) ;
927+ } ;
0 commit comments