From 7c45935cb5a6c6ff2d96263940fbb1b649c1aff9 Mon Sep 17 00:00:00 2001 From: umasoodch Date: Thu, 19 Aug 2021 14:29:58 +0300 Subject: [PATCH 1/3] added firestore check in attendance --- .../attend-services/attend-scan.service.ts | 6 +++++- .../attendance-options.component.ts | 18 ++++++++++++++++-- .../app/home/nfc-modal/nfc-modal.component.ts | 5 ++++- .../home/wifi-model/wifi-modal.component.ts | 8 ++++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts index 3e6be17c..fb6b3e5d 100644 --- a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts +++ b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts @@ -239,6 +239,8 @@ export class AttendScanService { public swipeAttendance() { const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); const isPlatformValue = this.platform.is('ios') ? 'QR-IOS' : 'QR-ANDROID'; + const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false); + const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); request.PointType = 1; request.Latitude = this.lat; @@ -255,7 +257,9 @@ export class AttendScanService { console.log('Error inside in swipe attendance'); }) .subscribe((result: Response) => { - this.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); + if (enableFirestore) { + this.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); + } if (this.common.validResponse(result)) { console.log('response'); console.log(result); diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.ts index 198a0c87..59ee9997 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.ts +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.ts @@ -37,6 +37,7 @@ export class AttendanceOptionsComponent implements OnInit { public enableLocationQR = false; public enableLocationNFC = false; public enableLocationWIFI = false; + public enableFirestore = false; public deviceNFC = false; public nfcIOSSuccess = false; public lat = 0; @@ -75,7 +76,6 @@ export class AttendanceOptionsComponent implements OnInit { this.priviligeList = AuthenticationService.servicePrivilage; this.setServicesPrivilage(); this.checkNFCStatus("one"); - this.checkFirebaseDocument(); } public checkFirebaseDocument() { @@ -149,6 +149,18 @@ export class AttendanceOptionsComponent implements OnInit { ) { this.enableLocationWIFI = true; } + + if ( + servicePrivilage.Previlege && + servicePrivilage.ServiceName === "enableFirestore" + ) { + this.enableFirestore = true; + this.common.sharedService.setSharedData(true, 'enableFirestore'); + this.checkFirebaseDocument(); + } else { + this.enableFirestore = false; + this.common.stopLoading(); + } } } @@ -192,7 +204,9 @@ export class AttendanceOptionsComponent implements OnInit { console.log("Error inside in swipe attendance"); }) .subscribe((result: Response) => { - this.attendScanService.processFirebaseDocument('NFC-IOS', result, firestoreDocument.isDocumentAvailable); + if (this.enableFirestore) { + this.attendScanService.processFirebaseDocument('NFC-IOS', result, firestoreDocument.isDocumentAvailable); + } if (this.common.validResponse(result)) { this.ngZone.run(() => { this.nfcIOSSuccess = true; diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts index 817f9cb3..dfd6d710 100644 --- a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts +++ b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts @@ -60,6 +60,7 @@ export class NfcModalComponent implements OnInit { public swipeAttendanceNFC (nfcSerialCode: any) { this.nfcReader.unsubscribe(); + const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false); const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); request.PointType = 2; request.Latitude = this.lat; @@ -73,7 +74,9 @@ export class NfcModalComponent implements OnInit { console.log('Error inside in swipe attendance'); this.modalController.dismiss(); }).subscribe((result: Response) => { - this.attendScanService.processFirebaseDocument('NFC-ANDROID', result, this.isDocumentAvailable); + if (enableFirestore) { + this.attendScanService.processFirebaseDocument('NFC-ANDROID', result, this.isDocumentAvailable); + } if (this.common.validResponse(result)) { this.ngZone.run(() => { this.gifStatus = true; diff --git a/Mohem/src/app/home/wifi-model/wifi-modal.component.ts b/Mohem/src/app/home/wifi-model/wifi-modal.component.ts index acd49c51..1f306af9 100644 --- a/Mohem/src/app/home/wifi-model/wifi-modal.component.ts +++ b/Mohem/src/app/home/wifi-model/wifi-modal.component.ts @@ -138,7 +138,9 @@ export class WifiModalComponent implements OnInit { async swipeAttendanceWifi(code:any) { const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); - const isPlatformValue = this.platform.is('ios') ? 'WIFI-IOS' : 'WIFI-ANDROID'; + const isPlatformValue = this.platform.is('ios') ? 'WIFI-IOS' : 'WIFI-ANDROID'; + const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false); + const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); request.PointType = 3; request.Latitude = this.lat; @@ -157,7 +159,9 @@ export class WifiModalComponent implements OnInit { this.disconnectWifi(); }) .subscribe((result: Response) => { - this.attendScanService.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); + if (enableFirestore) { + this.attendScanService.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); + } this.disconnectWifi(); if (this.common.validResponse(result)) { this.ngZone.run(() => { From 59b08a15b217ae455b218106b2ba52efbbe7b5b8 Mon Sep 17 00:00:00 2001 From: umasoodch Date: Thu, 19 Aug 2021 15:30:07 +0300 Subject: [PATCH 2/3] fixed firestore issues --- .../attend-services/attend-scan.service.ts | 54 +++++------- .../attendance-options.component.ts | 87 ++++++++----------- .../app/home/nfc-modal/nfc-modal.component.ts | 4 +- .../home/wifi-model/wifi-modal.component.ts | 3 +- 4 files changed, 59 insertions(+), 89 deletions(-) diff --git a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts index fb6b3e5d..1b8d1e07 100644 --- a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts +++ b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts @@ -157,7 +157,7 @@ export class AttendScanService { try { let result = {}; await this.firebasex.fetchDocumentInFirestoreCollection(userID, this.collection, (document: any) => { - console.log("Successfully Fetched the document with id ="); + console.log("Successfully Fetched the document with id =" + userID); result = { isDocumentAvailable: true, document: document @@ -175,6 +175,11 @@ export class AttendScanService { }) } catch(error) { console.log(error); + const result = { + isDocumentAvailable: false, + document: null + }; + this.common.sharedService.setSharedData(result, 'firebase-document'); this.common.stopLoading(); } } @@ -198,13 +203,22 @@ export class AttendScanService { } } - public processFirebaseDocument(mode: string, result: any, isDocumentAvailable: boolean) { + public checkDocumentAvailability(resultObject: any) { + const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); + if (firestoreDocument) { + if (firestoreDocument.isDocumentAvailable) { + this.updateFirebaseDocument(resultObject); + } else { + this.createNewDocument(resultObject); + } + } else { + this.createNewDocument(resultObject); + } + } + + public processFirebaseDocument(mode: string, result: any) { try { - console.log(mode); - console.log(result); - console.log(isDocumentAvailable); this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); - console.log(this.userData); const resultObject = { modeOfAttendance: mode, messageStatus: result.MessageStatus, @@ -213,11 +227,7 @@ export class AttendScanService { pointID: result.SWP_AuthenticateAndSwipeUserModel.PointID, branchDescription: result.SWP_AuthenticateAndSwipeUserModel.BranchDescription } - if (isDocumentAvailable) { - this.updateFirebaseDocument(resultObject); - } else { - this.createNewDocument(resultObject); - } + this.checkDocumentAvailability(resultObject); } catch (error) { console.log(error); } @@ -237,7 +247,6 @@ export class AttendScanService { } public swipeAttendance() { - const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); const isPlatformValue = this.platform.is('ios') ? 'QR-IOS' : 'QR-ANDROID'; const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false); @@ -258,7 +267,7 @@ export class AttendScanService { }) .subscribe((result: Response) => { if (enableFirestore) { - this.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); + this.processFirebaseDocument(isPlatformValue, result); } if (this.common.validResponse(result)) { console.log('response'); @@ -268,23 +277,4 @@ export class AttendScanService { } }); } - - // public swipeAttendanceNFC (nfcSerialCode: any) { - // const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); - // request.PointType = 2; - // request.Latitude = 0; - // request.Longitude = 0; - // request.QRValue = ""; - // request.NFCValue = nfcSerialCode; - // request.UID = this.device.uuid; - // request.UserName = this.userData.EMPLOYEE_NUMBER; - // this.attendance_service.attendanceSwipeScanner(request, () => { - // console.log('Error inside in swipe attendance'); - // }).subscribe((result: Response) => { - // if (this.common.validResponse(result)) { - // this.modalController.dismiss(); - - // } - // }); - // } } diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.ts index 59ee9997..5bac44aa 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.ts +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.ts @@ -112,55 +112,40 @@ export class AttendanceOptionsComponent implements OnInit { } public setServicesPrivilage() { - for (const servicePrivilage of AuthenticationService.servicePrivilage) { - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableNFC" - ) { - this.serviceEnableNFC = true; - } - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableQR" - ) { - this.serviceEnableQR = true; - } - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableWIFI" - ) { - this.serviceEnableWifi = true; - } - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableLocationQR" - ) { - this.enableLocationQR = true; - } - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableLocationNFC" - ) { - this.enableLocationNFC = true; - } - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableLocationWIFI" - ) { - this.enableLocationWIFI = true; - } - - if ( - servicePrivilage.Previlege && - servicePrivilage.ServiceName === "enableFirestore" - ) { - this.enableFirestore = true; - this.common.sharedService.setSharedData(true, 'enableFirestore'); - this.checkFirebaseDocument(); - } else { - this.enableFirestore = false; - this.common.stopLoading(); + try { + for (const servicePrivilage of AuthenticationService.servicePrivilage) { + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableNFC") { + this.serviceEnableNFC = true; + } + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableQR") { + this.serviceEnableQR = true; + } + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableWIFI") { + this.serviceEnableWifi = true; + } + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableLocationQR") { + this.enableLocationQR = true; + } + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableLocationNFC") { + this.enableLocationNFC = true; + } + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableLocationWIFI") { + this.enableLocationWIFI = true; + } + + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableFirestore") { + this.enableFirestore = true; + this.common.sharedService.setSharedData(true, 'enableFirestore'); + this.checkFirebaseDocument(); + } else { + this.enableFirestore = false; + this.common.sharedService.setSharedData(false, 'enableFirestore'); + this.common.stopLoading(); + } } + } catch (error) { + console.log(error); + this.common.stopLoading(); } } @@ -177,19 +162,17 @@ export class AttendanceOptionsComponent implements OnInit { } public async nfcModal() { - const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); const modal = await this.modalController.create({ component: NfcModalComponent, showBackdrop: true, backdropDismiss: true, - componentProps:{ enableLocationNFC: this.enableLocationNFC, lat: this.lat, longt: this.longt, isDocumentAvailable: firestoreDocument.isDocumentAvailable}, + componentProps:{ enableLocationNFC: this.enableLocationNFC, lat: this.lat, longt: this.longt}, }); modal.cssClass = "nfc-modal"; await modal.present(); } public swipeAttendanceNFC(nfcSerialCode: any) { - const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); request.PointType = 2; request.Latitude = this.lat; @@ -205,7 +188,7 @@ export class AttendanceOptionsComponent implements OnInit { }) .subscribe((result: Response) => { if (this.enableFirestore) { - this.attendScanService.processFirebaseDocument('NFC-IOS', result, firestoreDocument.isDocumentAvailable); + this.attendScanService.processFirebaseDocument('NFC-IOS', result); } if (this.common.validResponse(result)) { this.ngZone.run(() => { diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts index dfd6d710..c5d761ef 100644 --- a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts +++ b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts @@ -20,7 +20,6 @@ export class NfcModalComponent implements OnInit { public gifStatus = false; public nfcReader: any; public enableLocationNFC: boolean; - public isDocumentAvailable: boolean; public lat: number; public longt: number; @@ -39,7 +38,6 @@ export class NfcModalComponent implements OnInit { this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); this.startAndroidNfc(); console.log(this.enableLocationNFC); - console.log(this.isDocumentAvailable); } ionViewDidLeave() { @@ -75,7 +73,7 @@ export class NfcModalComponent implements OnInit { this.modalController.dismiss(); }).subscribe((result: Response) => { if (enableFirestore) { - this.attendScanService.processFirebaseDocument('NFC-ANDROID', result, this.isDocumentAvailable); + this.attendScanService.processFirebaseDocument('NFC-ANDROID', result); } if (this.common.validResponse(result)) { this.ngZone.run(() => { diff --git a/Mohem/src/app/home/wifi-model/wifi-modal.component.ts b/Mohem/src/app/home/wifi-model/wifi-modal.component.ts index 1f306af9..196f8eee 100644 --- a/Mohem/src/app/home/wifi-model/wifi-modal.component.ts +++ b/Mohem/src/app/home/wifi-model/wifi-modal.component.ts @@ -137,7 +137,6 @@ export class WifiModalComponent implements OnInit { } async swipeAttendanceWifi(code:any) { - const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false); const isPlatformValue = this.platform.is('ios') ? 'WIFI-IOS' : 'WIFI-ANDROID'; const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false); @@ -160,7 +159,7 @@ export class WifiModalComponent implements OnInit { }) .subscribe((result: Response) => { if (enableFirestore) { - this.attendScanService.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); + this.attendScanService.processFirebaseDocument(isPlatformValue, result); } this.disconnectWifi(); if (this.common.validResponse(result)) { From 160a7437be21ae342a354da766f82a7a879000e1 Mon Sep 17 00:00:00 2001 From: umasoodch Date: Sun, 22 Aug 2021 09:37:49 +0300 Subject: [PATCH 3/3] fixed empty array issue --- .../services/attend-services/attend-scan.service.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts index 1b8d1e07..a90cb735 100644 --- a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts +++ b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts @@ -188,7 +188,13 @@ export class AttendScanService { try { let currentFirebaseDocument = this.common.sharedService.getSharedData('firebase-document'); let currentSwipeArray = currentFirebaseDocument.document.swipeData; - currentSwipeArray.push(resultObject); + if (currentSwipeArray) { + currentSwipeArray.push(resultObject); + } else { + let swipeData = []; + swipeData.push(resultObject); + currentSwipeArray = swipeData; + } const updatedDocument = { swipeData: currentSwipeArray };