fixed firestore issues

enad-Q1
umasoodch 5 years ago
parent 7c45935cb5
commit 59b08a15b2

@ -157,7 +157,7 @@ export class AttendScanService {
try { try {
let result = {}; let result = {};
await this.firebasex.fetchDocumentInFirestoreCollection(userID, this.collection, (document: any) => { 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 = { result = {
isDocumentAvailable: true, isDocumentAvailable: true,
document: document document: document
@ -175,6 +175,11 @@ export class AttendScanService {
}) })
} catch(error) { } catch(error) {
console.log(error); console.log(error);
const result = {
isDocumentAvailable: false,
document: null
};
this.common.sharedService.setSharedData(result, 'firebase-document');
this.common.stopLoading(); 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 { try {
console.log(mode);
console.log(result);
console.log(isDocumentAvailable);
this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false);
console.log(this.userData);
const resultObject = { const resultObject = {
modeOfAttendance: mode, modeOfAttendance: mode,
messageStatus: result.MessageStatus, messageStatus: result.MessageStatus,
@ -213,11 +227,7 @@ export class AttendScanService {
pointID: result.SWP_AuthenticateAndSwipeUserModel.PointID, pointID: result.SWP_AuthenticateAndSwipeUserModel.PointID,
branchDescription: result.SWP_AuthenticateAndSwipeUserModel.BranchDescription branchDescription: result.SWP_AuthenticateAndSwipeUserModel.BranchDescription
} }
if (isDocumentAvailable) { this.checkDocumentAvailability(resultObject);
this.updateFirebaseDocument(resultObject);
} else {
this.createNewDocument(resultObject);
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
@ -237,7 +247,6 @@ export class AttendScanService {
} }
public swipeAttendance() { public swipeAttendance() {
const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false);
const isPlatformValue = this.platform.is('ios') ? 'QR-IOS' : 'QR-ANDROID'; const isPlatformValue = this.platform.is('ios') ? 'QR-IOS' : 'QR-ANDROID';
const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false); const enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false);
@ -258,7 +267,7 @@ export class AttendScanService {
}) })
.subscribe((result: Response) => { .subscribe((result: Response) => {
if (enableFirestore) { if (enableFirestore) {
this.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); this.processFirebaseDocument(isPlatformValue, result);
} }
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {
console.log('response'); 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();
// }
// });
// }
} }

@ -112,55 +112,40 @@ export class AttendanceOptionsComponent implements OnInit {
} }
public setServicesPrivilage() { public setServicesPrivilage() {
for (const servicePrivilage of AuthenticationService.servicePrivilage) { try {
if ( for (const servicePrivilage of AuthenticationService.servicePrivilage) {
servicePrivilage.Previlege && if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableNFC") {
servicePrivilage.ServiceName === "enableNFC" this.serviceEnableNFC = true;
) { }
this.serviceEnableNFC = true; if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableQR") {
} this.serviceEnableQR = true;
if ( }
servicePrivilage.Previlege && if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableWIFI") {
servicePrivilage.ServiceName === "enableQR" this.serviceEnableWifi = true;
) { }
this.serviceEnableQR = true; if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableLocationQR") {
} this.enableLocationQR = true;
if ( }
servicePrivilage.Previlege && if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableLocationNFC") {
servicePrivilage.ServiceName === "enableWIFI" this.enableLocationNFC = true;
) { }
this.serviceEnableWifi = true; if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableLocationWIFI") {
} this.enableLocationWIFI = 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 ( if (servicePrivilage.Previlege && servicePrivilage.ServiceName === "enableFirestore") {
servicePrivilage.Previlege && this.enableFirestore = true;
servicePrivilage.ServiceName === "enableFirestore" this.common.sharedService.setSharedData(true, 'enableFirestore');
) { this.checkFirebaseDocument();
this.enableFirestore = true; } else {
this.common.sharedService.setSharedData(true, 'enableFirestore'); this.enableFirestore = false;
this.checkFirebaseDocument(); this.common.sharedService.setSharedData(false, 'enableFirestore');
} else { this.common.stopLoading();
this.enableFirestore = false; }
this.common.stopLoading();
} }
} catch (error) {
console.log(error);
this.common.stopLoading();
} }
} }
@ -177,19 +162,17 @@ export class AttendanceOptionsComponent implements OnInit {
} }
public async nfcModal() { public async nfcModal() {
const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false);
const modal = await this.modalController.create({ const modal = await this.modalController.create({
component: NfcModalComponent, component: NfcModalComponent,
showBackdrop: true, showBackdrop: true,
backdropDismiss: 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"; modal.cssClass = "nfc-modal";
await modal.present(); await modal.present();
} }
public swipeAttendanceNFC(nfcSerialCode: any) { public swipeAttendanceNFC(nfcSerialCode: any) {
const firestoreDocument = this.common.sharedService.getSharedData('firebase-document', false);
const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest();
request.PointType = 2; request.PointType = 2;
request.Latitude = this.lat; request.Latitude = this.lat;
@ -205,7 +188,7 @@ export class AttendanceOptionsComponent implements OnInit {
}) })
.subscribe((result: Response) => { .subscribe((result: Response) => {
if (this.enableFirestore) { if (this.enableFirestore) {
this.attendScanService.processFirebaseDocument('NFC-IOS', result, firestoreDocument.isDocumentAvailable); this.attendScanService.processFirebaseDocument('NFC-IOS', result);
} }
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {
this.ngZone.run(() => { this.ngZone.run(() => {

@ -20,7 +20,6 @@ export class NfcModalComponent implements OnInit {
public gifStatus = false; public gifStatus = false;
public nfcReader: any; public nfcReader: any;
public enableLocationNFC: boolean; public enableLocationNFC: boolean;
public isDocumentAvailable: boolean;
public lat: number; public lat: number;
public longt: number; public longt: number;
@ -39,7 +38,6 @@ export class NfcModalComponent implements OnInit {
this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false);
this.startAndroidNfc(); this.startAndroidNfc();
console.log(this.enableLocationNFC); console.log(this.enableLocationNFC);
console.log(this.isDocumentAvailable);
} }
ionViewDidLeave() { ionViewDidLeave() {
@ -75,7 +73,7 @@ export class NfcModalComponent implements OnInit {
this.modalController.dismiss(); this.modalController.dismiss();
}).subscribe((result: Response) => { }).subscribe((result: Response) => {
if (enableFirestore) { if (enableFirestore) {
this.attendScanService.processFirebaseDocument('NFC-ANDROID', result, this.isDocumentAvailable); this.attendScanService.processFirebaseDocument('NFC-ANDROID', result);
} }
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {
this.ngZone.run(() => { this.ngZone.run(() => {

@ -137,7 +137,6 @@ export class WifiModalComponent implements OnInit {
} }
async swipeAttendanceWifi(code:any) { 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 enableFirestore = this.common.sharedService.getSharedData('enableFirestore', false);
@ -160,7 +159,7 @@ export class WifiModalComponent implements OnInit {
}) })
.subscribe((result: Response) => { .subscribe((result: Response) => {
if (enableFirestore) { if (enableFirestore) {
this.attendScanService.processFirebaseDocument(isPlatformValue, result, firestoreDocument.isDocumentAvailable); this.attendScanService.processFirebaseDocument(isPlatformValue, result);
} }
this.disconnectWifi(); this.disconnectWifi();
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {

Loading…
Cancel
Save