diff --git a/lang/de.json b/lang/de.json index 0ab92e04c3..9d99493424 100644 --- a/lang/de.json +++ b/lang/de.json @@ -158,5 +158,6 @@ "Information": "Informatie", "No account registered with this email": "Server werkt niet/verkeerde url", "Dismiss": "afwijzen", - "No organizations found Please contact your admin": "Geen organisaties gevonden! Neem contact op met uw beheerder" + "No organizations found Please contact your admin": "Geen organisaties gevonden! Neem contact op met uw beheerder", + "Notification Feature is not installed": "Meddelelsesfunktionen er ikke installeret" } diff --git a/lang/en.json b/lang/en.json index 3173d58276..08a9f20e60 100644 --- a/lang/en.json +++ b/lang/en.json @@ -12,6 +12,8 @@ "Enter your password": "Enter your password", "Forgot password": "Forgot password", "Login": "Login", + + "Notification Feature is not installed": "Notification Feature is not installed", "Sit back relax, we'll": "Sit back relax, we'll", "Recover": "Recover", "your password": "your password", diff --git a/lang/es.json b/lang/es.json index 2040c1c944..ede5804a14 100644 --- a/lang/es.json +++ b/lang/es.json @@ -14,6 +14,9 @@ "Login": "Acceso", "Sit back relax, we'll": "Siéntese, ", "Recover": "", + + "Notification Feature is not installed": "La función de notificación no está instalada", + "your password": "relájese, recuperaremos su contraseña", "Recover Password": "Recupera tu contraseña", "Select Language": "Seleccione el idioma", diff --git a/lang/fr.json b/lang/fr.json index b6691ae33e..430055d0ae 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -9,6 +9,8 @@ "Change Password": "Changer le mot de passe", "Email Hint": "test@test.org", + "Notification Feature is not installed": "La fonction de notification n'est pas installée", + "Enter your registered Email": "Entrez votre email enregistré", "Enter your password": "Tapez votre mot de passe", "Forgot password": "Mot de passe oublié", diff --git a/lang/hi.json b/lang/hi.json index 5a07a26679..6c7cce6420 100644 --- a/lang/hi.json +++ b/lang/hi.json @@ -19,6 +19,7 @@ "Select Language": "भाषा का चयन करें", "Default": "डिफ़ॉल्ट मान", "Select": "चुनते हैं", + "Notification Feature is not installed": "अधिसूचना सुविधा स्थापित नहीं है", "Selected Organization": "चयनित संगठन", "Continue": "जारी रखें", "Enter Organization URL": "संगठन URL दर्ज करें", diff --git a/lang/ja.json b/lang/ja.json index 0e560d94eb..e5eef865e9 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -14,6 +14,8 @@ "Login": "ログイン", "Sit back relax, we'll": "ゆったりとおくつろぎください。", "Recover": "回復", + + "Notification Feature is not installed": "通知機能がインストールされていません", "your password": "あなたのパスワード", "Recover Password": "パスワードを回復", "Select Language": "言語を選択する", diff --git a/lang/pt.json b/lang/pt.json index 63e60d57be..049d5a36af 100644 --- a/lang/pt.json +++ b/lang/pt.json @@ -13,6 +13,9 @@ "Forgot password": "Esqueceu sua senha", "Login": "Conecte-se", "Sit back relax, we'll": "Sente-se relaxe, vamos", + + "Notification Feature is not installed": "O recurso de notificação não está instalado", + "Recover": "Recuperar", "your password": "sua senha", "Recover Password": "Recuperar senha", diff --git a/lang/zh.json b/lang/zh.json index 8fe85ad074..1d63d591be 100644 --- a/lang/zh.json +++ b/lang/zh.json @@ -14,6 +14,8 @@ "Login": "登录", "Sit back relax, we'll": "高枕无忧, ", "Recover": "", + "Notification Feature is not installed": "未安装通知功能\n", + "your password": "我们会找回您的密码", "Recover Password": "恢复你的密码", "Select Language": "选择语言", diff --git a/lib/services/database_mutation_functions.dart b/lib/services/database_mutation_functions.dart index a85caa40cf..7505cf1bbc 100644 --- a/lib/services/database_mutation_functions.dart +++ b/lib/services/database_mutation_functions.dart @@ -1,6 +1,3 @@ -// ignore_for_file: talawa_api_doc, avoid_dynamic_calls -// ignore_for_file: talawa_good_doc_comments - import 'dart:async'; import 'package:flutter/material.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; @@ -20,34 +17,71 @@ import 'package:talawa/utils/queries.dart'; /// * `refreshAccessToken` /// * `fetchOrgById` class DataBaseMutationFunctions { + /// Client Auth for handling non-authenticated request. late GraphQLClient clientNonAuth; + + /// Client Auth for handling authenticated request. late GraphQLClient clientAuth; + + /// Query passed by fucntion calling this function. late Queries _query; + /// initialization function. + /// + /// **params**: + /// None + /// + /// **returns**: + /// None void init() { clientNonAuth = graphqlConfig.clientToQuery(); clientAuth = graphqlConfig.authClient(); _query = Queries(); } - // initialising default messages for an event. + /// Graphql error for handling. GraphQLError userNotFound = const GraphQLError(message: 'User not found'); + + /// Graphql error for handling. GraphQLError userNotAuthenticated = const GraphQLError(message: 'User is not authenticated'); + + /// Graphql error for handling. GraphQLError emailAccountPresent = const GraphQLError(message: 'Email address already exists'); + + /// Graphql error for handling. GraphQLError wrongCredentials = const GraphQLError(message: 'Invalid credentials'); + + /// Graphql error for handling. GraphQLError organizationNotFound = const GraphQLError(message: 'Organization not found'); + + /// Graphql error for handling. GraphQLError refreshAccessTokenExpiredException = const GraphQLError( message: 'Access Token has expired. Please refresh session.: Undefined location', ); + + /// Graphql error for handling. GraphQLError memberRequestExist = const GraphQLError(message: 'Membership Request already exists'); + /// Graphql error for handling. + GraphQLError notifFeatureNotInstalled = const GraphQLError( + message: + 'Failed to determine project ID: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND', + ); + /// This function is used to check if any exceptions or error encountered. The return type is [boolean]. + /// + /// **params**: + /// * `exception`: OperationException which occur when calling for graphql post request + /// * `showSnackBar`: Tell if the the place where this function is called wants a SnackBar on error + /// + /// **returns**: + /// * `bool?`: returns a bool whether or not their is error, can be null bool? encounteredExceptionOrError( OperationException exception, { bool showSnackBar = true, @@ -65,7 +99,8 @@ class DataBaseMutationFunctions { } return false; } - // looping through graphQL errors. + + /// looping through graphQL errors. debugPrint(exception.graphqlErrors.toString()); for (int i = 0; i < exception.graphqlErrors.length; i++) { // if the error message is "Access Token has expired. Please refresh session.: Undefined location" @@ -80,7 +115,8 @@ class DataBaseMutationFunctions { print('client refreshed'); return true; } - // if the error message is "User is not authenticated" + + /// if the error message is "User is not authenticated" if (exception.graphqlErrors[i].message == userNotAuthenticated.message) { print('client refreshed'); refreshAccessToken(userConfig.currentUser.refreshToken!).then( @@ -90,7 +126,8 @@ class DataBaseMutationFunctions { ); return true; } - // if the error message is "User not found" + + /// if the error message is "User not found" if (exception.graphqlErrors[i].message == userNotFound.message) { if (showSnackBar) { WidgetsBinding.instance.addPostFrameCallback( @@ -102,7 +139,8 @@ class DataBaseMutationFunctions { } return false; } - // if the error message is "Membership Request already exists" + + /// if the error message is "Membership Request already exists" if (exception.graphqlErrors[i].message == memberRequestExist.message) { if (showSnackBar) { WidgetsBinding.instance.addPostFrameCallback( @@ -114,7 +152,8 @@ class DataBaseMutationFunctions { } return false; } - // if the error message is "Invalid credentials" + + /// if the error message is "Invalid credentials" if (exception.graphqlErrors[i].message == wrongCredentials.message) { if (showSnackBar) { WidgetsBinding.instance.addPostFrameCallback( @@ -126,7 +165,8 @@ class DataBaseMutationFunctions { } return false; } - // if the error message is "Organization not found" + + /// if the error message is "Organization not found" if (exception.graphqlErrors[i].message == organizationNotFound.message) { if (showSnackBar) { WidgetsBinding.instance.addPostFrameCallback( @@ -138,7 +178,8 @@ class DataBaseMutationFunctions { } return false; } - // if the error message is "Email address already exists" + + /// if the error message is "Email address already exists" if (exception.graphqlErrors[i].message == emailAccountPresent.message) { if (showSnackBar) { WidgetsBinding.instance.addPostFrameCallback( @@ -150,6 +191,18 @@ class DataBaseMutationFunctions { } return false; } + if (exception.graphqlErrors[i].message == + notifFeatureNotInstalled.message) { + if (showSnackBar) { + WidgetsBinding.instance.addPostFrameCallback( + (_) => navigationService.showTalawaErrorDialog( + "Notification Feature is not installed", + MessageType.error, + ), + ); + } + return false; + } } // if the error is unknown @@ -163,6 +216,13 @@ class DataBaseMutationFunctions { } /// This function is used to run the graph-ql query for authentication. + /// + /// **params**: + /// * `query`: query is used to fetch data in graphql, for more info read graphql docs + /// * `variables`: variables to be passed with query + /// + /// **returns**: + /// * `Future`: it returns Future of dynamic Future gqlAuthQuery( String query, { Map? variables, @@ -185,6 +245,13 @@ class DataBaseMutationFunctions { } /// This function is used to run the graph-ql mutation for authenticated user. + /// + /// **params**: + /// * `mutation`: mutation is used to change/add/delete data in graphql, for more info read graphql docs + /// * `variables`: variables to be passed with mutation + /// + /// **returns**: + /// * `Future`: it returns Future of dynamic Future gqlAuthMutation( String mutation, { Map? variables, @@ -208,6 +275,15 @@ class DataBaseMutationFunctions { } /// This function is used to run the graph-ql mutation to authenticate the non signed-in user. + /// + /// + /// **params**: + /// * `mutation`: mutation is used to change/add/delete data in graphql, for more info read graphql docs + /// * `variables`: variables to be passed with mutation + /// * `reCall`: when not first fetch call + /// + /// **returns**: + /// * `Future`: it returns Future of dynamic Future gqlNonAuthMutation( String mutation, { Map? variables, @@ -232,7 +308,14 @@ class DataBaseMutationFunctions { } /// This function is used to run the graph-ql query for the non signed-in user. - Future gqlNonAuthQuery( + /// + /// **params**: + /// * `query`: query is used to fetch data in graphql, for more info read graphql docs + /// * `variables`: variables to be passed with query + /// + /// **returns**: + /// * `Future?>`: it returns Future of QueryResult, contains all data + Future?> gqlNonAuthQuery( String query, { Map? variables, }) async { @@ -255,6 +338,12 @@ class DataBaseMutationFunctions { } /// This function is used to refresh the Authenication token to access the application. + /// + /// **params**: + /// * `refreshToken`: Needed for authentication + /// + /// **returns**: + /// * `Future`: it returns Future of dynamic Future refreshAccessToken(String refreshToken) async { // run the graphQL mutation final QueryResult result = await clientNonAuth.mutate( @@ -274,8 +363,12 @@ class DataBaseMutationFunctions { } } else if (result.data != null && result.isConcrete) { userConfig.updateAccessToken( - refreshToken: result.data!['refreshToken']['refreshToken'].toString(), - accessToken: result.data!['refreshToken']['accessToken'].toString(), + refreshToken: (result.data!['refreshToken'] + as Map)['refreshToken'] + .toString(), + accessToken: (result.data!['refreshToken'] + as Map)['accessToken'] + .toString(), ); databaseFunctions.init(); return true; @@ -284,6 +377,12 @@ class DataBaseMutationFunctions { } /// This function fetch the organization using the [id] passed. + /// + /// **params**: + /// * `id`: id that identifies a particular org + /// + /// **returns**: + /// * `Future`: it returns Future of dynamic Future fetchOrgById(String id) async { final QueryResult result = await clientNonAuth .mutate(MutationOptions(document: gql(_query.fetchOrgById(id)))); @@ -295,7 +394,9 @@ class DataBaseMutationFunctions { } } else if (result.data != null && result.isConcrete) { return OrgInfo.fromJson( - result.data!['organizations'][0] as Map, + // ignore: collection_methods_unrelated_type + (result.data!['organizations'] as Map)[0] + as Map, ); } return false;