From da7d7b29f93b600fa4f11f048cca1da72f106326 Mon Sep 17 00:00:00 2001 From: Sujith Date: Mon, 4 Mar 2024 19:01:00 +0530 Subject: [PATCH] Issue #ED- Issue #ED-2894 fix: Delete user endpoint after masked changes --- package.json | 2 +- src/app/profile/profile.page.ts | 140 +++++++++++++++++--------------- 2 files changed, 75 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index dd4138880d..277c2c758c 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "@project-sunbird/sunbird-epub-player-v9": "5.2.1", "@project-sunbird/sunbird-pdf-player-v9": "5.1.1", "@project-sunbird/sunbird-quml-player-web-component": "3.0.3", - "@project-sunbird/sunbird-sdk": "7.0.17", + "@project-sunbird/sunbird-sdk": "7.0.18", "@project-sunbird/sunbird-video-player-web-component": "^1.0.1", "chart.js": "^2.9.4", "chartjs-plugin-datalabels": "^0.7.0", diff --git a/src/app/profile/profile.page.ts b/src/app/profile/profile.page.ts index 97a4741bea..f996fc5c81 100644 --- a/src/app/profile/profile.page.ts +++ b/src/app/profile/profile.page.ts @@ -85,9 +85,8 @@ import { urlConstants } from '../manage-learn/core/constants/urlConstants'; import { UnnatiDataService } from '../manage-learn/core/services/unnati-data.service'; import { ToastService, statusType } from '../manage-learn/core'; import { UtilityService } from '../../services/utility-service'; -// import { DeleteUserService } from '../../services/delete-user.service'; import { LogoutHandlerService } from '../../services/handlers/logout-handler.service'; -import { error } from 'console'; +import { DeleteUserRequest } from '@project-sunbird/sunbird-sdk/profile/def/delete-user-request'; @Component({ selector: 'app-profile', templateUrl: './profile.page.html', @@ -574,72 +573,81 @@ export class ProfilePage implements OnInit { ID.DELETE_CLICKED); const baseUrl = await this.utilityService.getBuildConfigValue('BASE_URL'); - const deeplinkValue = await this.utilityService.getBuildConfigValue('URL_SCHEME'); - - const formattedBaseUrl = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/'; - - const deleteEndpoint = 'profile/delete-user'; - - const modifiedDeeplinkValue = deeplinkValue + '://mobile'; - - const url = new URL(formattedBaseUrl + deleteEndpoint); - url.searchParams.append('deeplink', modifiedDeeplinkValue); - - - customtabs.launchInBrowser( - url.toString(), - (callbackUrl) => { - const params = new URLSearchParams(callbackUrl); // Parse the callbackUrl as URLSearchParams - const userId = params.get('userId'); // Get the value of 'userId' parameter - this.profileService.getActiveProfileSession().toPromise() //getting active profile uid - .then(async (profile) => { - try { - const userDeleted = await this.isUserDeleted(profile.uid); //checking whether this user is already deleted - if(profile.uid === userId && userDeleted) { //if active profile uid and user is deleted - this.loader = this.commonUtilService.getLoader(); - if (this.loader) { - this.logoutHandler.onLogout(); - await this.profileService.deleteProfileData(profile.uid).toPromise() //deleting local data - .then((result) => { - if (result) { - console.log('Profile data deleted successfully'); - } else { - console.log('Unable to delete profile data'); - } - }); - } - } - else { - console.log('userID does not match') - } - } catch (error) { - console.error('Error occurred while deleting profile data:', error); - } - }) - .catch((error) => { - console.error('Error occurred while getting active profile session:', error); - }); - }, - (error) => { - console.error('Error launching Custom Tab:', error); + const deeplinkValue = await this.utilityService.getBuildConfigValue('URL_SCHEME'); + const formattedBaseUrl = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/'; + const deleteEndpoint = 'guest-profile/delete-user'; + + var data = {type: '', value : ''}; + if(this.profile.maskedEmail) { + data.type = 'email'; + data.value = this.profile.maskedEmail; + } else if (this.profile.maskedPhone) { + data.type = 'phone'; + data.value = this.profile.maskedPhone; } - ); -} -async isUserDeleted(userId: string):Promise { - - try { - const req: ServerProfileDetailsRequest = { - userId: userId, - requiredFields: ProfileConstants.REQUIRED_FIELDS, - from: CachedItemRequestSourceFrom.SERVER, - forceRefresh: true - }; - const profileResponse = await this.profileService.getServerProfilesDetails(req).toPromise(); - return !profileResponse; - }catch { - return true; - } + const modifiedDeeplinkValue = deeplinkValue + '://mobile'; + const url = new URL(formattedBaseUrl + deleteEndpoint); + url.searchParams.append('deeplink', modifiedDeeplinkValue); + url.searchParams.append('userId', this.profile.userId); + url.searchParams.append('type', data.type); + url.searchParams.append('value', data.value); + + customtabs.launchInBrowser( + url.toString(), + (callbackUrl) => { + const params = new URLSearchParams(callbackUrl); // Parse the callbackUrl as URLSearchParams + const userId = params.get('userId'); // Get the value of 'userId' parameter + this.profileService.getActiveProfileSession().toPromise() //getting active profile uid + .then(async (profile) => { + try { + if(profile.uid === userId) { //if active profile uid and user is deleted + this.loader = this.commonUtilService.getLoader(); + if (this.loader) { + this.logoutHandler.onLogout(); + let req: DeleteUserRequest; + if(profile.uid) { + req = { + userId: profile.uid + }; + } + else{ + console.log('profile does not exists'); + } + await this.profileService.deleteUser(req).toPromise() + .then((result) => { + if(result) { + console.log('profile deleted succesfully'); + this.profileService.deleteProfileData(profile.uid).toPromise() //deleting local data + .then((result) => { + if (result) { + console.log('Profile data deleted successfully'); + } else { + console.log('Unable to delete profile data'); + } + }); + } + else { + console.log('unable to delete profile'); + } + }) + } + } + else { + console.log('userID does not match') + } + } catch (error) { + console.error('Error occurred while deleting profile', error); + } + }) + .catch((error) => { + console.error('Error occurred while getting active profile session:', error); + }); + }, + (error) => { + console.error('Error launching Custom Tab:', error); + } + ); }