fixed firestore issues

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

@ -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();
// }
// });
// }
}

@ -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(() => {

@ -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(() => {

@ -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)) {

Loading…
Cancel
Save