File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -374,3 +374,34 @@ exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
374374 res . status ( 500 ) . send ( 'Error fetching projects data' ) ;
375375 }
376376} ) ;
377+
378+ exports . addUserNameLowercase = functions . https . onRequest ( async ( _ , res ) => {
379+ try {
380+ const userRef = admin . database ( ) . ref ( 'v2/users' ) ;
381+ const snapshot = userRef . once ( 'value' ) ;
382+ const data = ( await snapshot ) . val ( ) ;
383+
384+ if ( data ) {
385+ const newUserData : { [ key : string ] : string } = { } ;
386+
387+ Object . keys ( data ) . forEach ( ( id ) => {
388+ if ( data [ id ] ?. username ) {
389+ const newUserNameKey = data [ id ] ?. username ?. toLowerCase ( ) as string ;
390+ newUserData [ `v2/users/${ id } /userNameKey` ] = newUserNameKey ;
391+ }
392+ } ) ;
393+ // NOTE: Update database with the new username lowercase
394+ await admin . database ( ) . ref ( ) . update ( newUserData ) ;
395+
396+ // Fetch updated data
397+ const updatedSnapshot = await admin . database ( ) . ref ( 'v2/users' ) . once ( 'value' ) ;
398+ const updatedUsersData = updatedSnapshot . val ( ) ;
399+
400+ res . status ( 200 ) . send ( updatedUsersData ) ;
401+ } else {
402+ res . status ( 404 ) . send ( 'No user found' ) ;
403+ }
404+ } catch ( error ) {
405+ res . status ( 500 ) . send ( 'Error fetching user data' ) ;
406+ }
407+ } ) ;
You can’t perform that action at this time.
0 commit comments