diff --git a/android/app/build.gradle b/android/app/build.gradle index 84afc9c..b5b4dbc 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.mermsemr.providers" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1026 - versionName "1.0.26" + versionCode 1027 + versionName "1.0.27" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/src/app/merms-dash/merms-dash.page.html b/src/app/merms-dash/merms-dash.page.html index 8b1c841..913fff6 100644 --- a/src/app/merms-dash/merms-dash.page.html +++ b/src/app/merms-dash/merms-dash.page.html @@ -56,7 +56,7 @@ -

Rey

+

Rey Dashe

I can handle myself

You will remove these restraints and leave...

diff --git a/src/app/merms-dash/merms-dash.page.ts b/src/app/merms-dash/merms-dash.page.ts index ebe9599..6fa8301 100644 --- a/src/app/merms-dash/merms-dash.page.ts +++ b/src/app/merms-dash/merms-dash.page.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { Router, NavigationExtras } from '@angular/router' import { MermsServiceProviderService } from './../providers/merms-service-provider.service'; +import { MermsSessionService } from './../merms-session.service'; @Component({ @@ -17,17 +18,45 @@ export class MermsDashPage implements OnInit { constructor( private router: Router, - private mermsServiceProviderService: MermsServiceProviderService + private mermsServiceProviderService: MermsServiceProviderService, + private mermsSessionService : MermsSessionService ) { this.welcomeName = "Dr. Something" } ngOnInit() { - alert(100); + this.getDashData(); } + currentProviderData: { + sessionid: string, + member_id: number, + card_count: number + card_type: number + }; + + cardData: any; + getDashData() { - + console.log('MermsServiceProviderService::getDashData() ######## @@@@ ########'); + this.currentProviderData = { + sessionid: this.mermsSessionService.session, + member_id: this.mermsSessionService.member_id, + card_count: 100, + card_type: 22000 + }; + + try { + this.mermsServiceProviderService.genericGetService('provider/recentencounter', this.currentProviderData).subscribe(cardData => { + console.log("card data result 22k: ", this.cardData); + if (cardData.hasOwnProperty('result_list') && Array.isArray(cardData['result_list'])) { + + + } + }); + } catch (e) { + console.log(e); + } } diff --git a/src/app/merms-session.service.ts b/src/app/merms-session.service.ts index 5182ba9..f717277 100644 --- a/src/app/merms-session.service.ts +++ b/src/app/merms-session.service.ts @@ -20,7 +20,7 @@ export class MermsSessionService { top_card = '' // "https://www.float.sg/float/static_top.png"; firstname = '' lastname = '' - session = '' + session = 'YESADUMMUFORNOW' balance = 0 username = '' last_login = '' diff --git a/src/app/providers/merms-service-provider.service.ts b/src/app/providers/merms-service-provider.service.ts index 42e4c4f..00192cd 100644 --- a/src/app/providers/merms-service-provider.service.ts +++ b/src/app/providers/merms-service-provider.service.ts @@ -1,7 +1,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' import { Injectable, Injector } from '@angular/core' //import 'rxjs/add/operator/map' -//import { Observable, from } from 'rxjs' +import { Observable, from } from 'rxjs' import { MermsSessionService } from './../merms-session.service'; //import * as CryptoBrowserify from 'crypto-browserify' //import { CONFIG } from './app-config' @@ -15,30 +15,48 @@ export class MermsServiceProviderService { //config = CONFIG[CONFIG.app.environment]() //apiKey = this.config.apiKey - url = '' - // oauth_url: string = this.config.baseURL + '/SAVVY/oauth2/api' - // account_endpoint: string = this.config.baseURL + '/SAVVY/banklogin/api' - // booking_endpoint: string = this.config.baseURL + '/SAVVY/booking/api' - // advice_endpoint: string = this.config.baseURL + '/SAVVY/advice/api' - // trip_endpoint: string = this.config.baseURL + '/SAVVY/trips/api' - // messaging_endpoint: string = this.config.baseURL + '/SAVVY/messaging/api' - // blog_endpoint: string = this.config.baseURL + '/SAVVY/blog/api' - // clientId: string = CONFIG.clientId - - // encryptionKey: string = this.config.encryptionKey - // encryptionIV: string = this.config.encryptionIV - + url = ''; + apiKey = 'AMEYE'; + clientId = '1010101010'; constructor(public http: HttpClient, - private mermsSessionService:MermsSessionService) { } + private mermsSessionService: MermsSessionService) { + this.url="http://api.dev.mermsemr.com" + } + + + genericPostService(endpoint: string, callData: any) { + if (this.mermsSessionService.session !== '') { + console.log('***** GENERIC SERVICE CALLED *****') + // Session & MemberId needed for all - pass in the header + return this.sendPostRequest('1', '/' + endpoint, callData) + } else { + console.log('***** NO SESSION *****') + return null + } + } + + genericGetService(endpoint: string, callData: any) { + if (this.mermsSessionService.session !== '') { + console.log('***** GENERIC SERVICE CALLED *****') + // Session & MemberId needed for all - pass in the header + return this.sendGetRequest('1', '/' + endpoint, callData) + } else { + console.log('***** NO SESSION *****') + return null + } + } + loginUser(loginData) { // this.http.post(this.url + '/userlogin', loginData); - return this.sendPostRequest('1', '/userlogin', loginData) + return this.sendPostRequest('1', '/userlogin', loginData) } - sendPostRequest(grp: string, endPoint: string, sendData: any) { + + + sendGetRequest(grp: string, endPoint: string, sendData: any) { // grp - will be used to change URL let endpointString = '' console.log('GRP->' + grp) @@ -49,7 +67,15 @@ export class MermsServiceProviderService { } - (async () => { + const httpParams = new HttpParams() + if (sendData) { + for (const k in sendData) { + if (k != null && sendData.hasOwnProperty(k)) { + httpParams.set(k, sendData[k]) + } + } + } + ;(async () => { // const id = Math.floor(100 * Math.random()); const id = (Math.random() * (10000 - 1000) + 1000).toFixed(0) const d1 = new Date() @@ -58,9 +84,136 @@ export class MermsServiceProviderService { const d2 = new Date() console.log('[' + id + '] after semaphore: ' + d2.getTime()) })() + return from( + new Promise((resolve) => { + const httpOptions = { + params: httpParams, + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'Access-Control-Allow-Credentials' : 'true', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PATCH, DELETE, PUT, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With', + authorization: 'Token ' + this.apiKey, + 'client_id': this.clientId, + 'x-session-id': this.mermsSessionService.session, + 'x-devicetoken': this.mermsSessionService.access_token, + + }), + } + // alert(100); + this.http.get(endpointString + endPoint, httpOptions).subscribe( + (data) => { + console.log(data); + console.log("*************************************************"); + let payload = '' + if (data != null && data.hasOwnProperty('payload')) { + + // console.log(payload); + } else { + payload = JSON.stringify(data) + } + let res = {} + try { + res = JSON.parse(payload) + } catch (e) { + console.log(e) + } + if (this.queued > 0) { + this.queued-- + } + this.checkSessionValid(res); + + resolve(res) + }, + (error) => { + if (this.queued > 0) { + this.queued-- + } + resolve(this.getResponseError(error)) + }, + () => { + console.log('OK!') + } + ) + }) + ) } + sendPostRequest(grp: string, endPoint: string, sendData: any) { + // grp - will be used to change URL + let endpointString = '' + console.log('GRP->' + grp) + switch (grp) { + case '1': + endpointString = this.url + break + } + ; (async () => { + // const id = Math.floor(100 * Math.random()); + const id = (Math.random() * (10000 - 1000) + 1000).toFixed(0) + const d1 = new Date() + console.log('[' + id + '] before semaphore: ' + d1.getTime()) + await this.semaphore(id) + const d2 = new Date() + console.log('[' + id + '] after semaphore: ' + d2.getTime()) + })() + return from( + new Promise((resolve) => { + // this.locationTrackerProvider = this.injector.get(LocationTrackerProvider); + const httpOptions = { + headers: new HttpHeaders({ + authorization: 'Token ' + this.apiKey, + 'client_id': this.clientId, + 'x-session-id': this.mermsSessionService.session, + 'x-devicetoken': this.mermsSessionService.access_token, + + }), + } + + this.http + .post(endpointString + endPoint, sendData, httpOptions) + .subscribe( + (data) => { + // console.log(data); + // console.log("*************************************************"); + let payload = '' + if (data != null && data.hasOwnProperty('payload')) { + payload = data['payload']; + // console.log(payload); + } else { + payload = JSON.stringify(data) + } + let res = {} + try { + res = JSON.parse(payload) + } catch (e) { + console.log(e) + } + if (this.queued > 0) { + this.queued-- + } + + this.checkSessionValid(res); + + resolve(res) + }, + (error) => { + if (this.queued > 0) { + this.queued-- + } + resolve(this.getResponseError(error)) + }, + () => { + console.log('OK!') + } + ) + }) + ) + } + + getResponseError(error) { // console.log("Error:" + JSON.stringify(error)); console.log(error) @@ -75,34 +228,34 @@ export class MermsServiceProviderService { authUser(authData) { return this.sendPostRequest('4', '/auth', authData) } -/* - encrypt(iv: string, text: string, password: string) { - const cipher = CryptoBrowserify.createCipheriv('aes-256-ctr', password, iv) - let crypted = cipher.update(text, 'utf8', 'hex') - crypted += cipher.final('hex') - return crypted - } + /* + encrypt(iv: string, text: string, password: string) { + const cipher = CryptoBrowserify.createCipheriv('aes-256-ctr', password, iv) + let crypted = cipher.update(text, 'utf8', 'hex') + crypted += cipher.final('hex') + return crypted + } + + decrypt(iv: string, text: string, password: string) { + const decipher = CryptoBrowserify.createDecipheriv( + 'aes-256-ctr', + password, + iv + ) + let dec = decipher.update(text, 'hex', 'utf8') + dec += decipher.final('utf8') + return dec + } + */ + /** + * Checks if the response from the server returns invalid session error + * + * @param response_data response from the server + */ + checkSessionValid(response_data: any) { - decrypt(iv: string, text: string, password: string) { - const decipher = CryptoBrowserify.createDecipheriv( - 'aes-256-ctr', - password, - iv - ) - let dec = decipher.update(text, 'hex', 'utf8') - dec += decipher.final('utf8') - return dec - } - */ - /** - * Checks if the response from the server returns invalid session error - * - * @param response_data response from the server - */ - checkSessionValid(response_data: any){ - - if("session_valid" in response_data){ - if(response_data['session_valid'] === "INVALID_SESSION") { + if ("session_valid" in response_data) { + if (response_data['session_valid'] === "INVALID_SESSION") { return this.doLogout(); } } @@ -110,8 +263,8 @@ export class MermsServiceProviderService { return true; } - doLogout(){ - // this.floatEventsService.publish('DoLogout', {}); + doLogout() { + // this.floatEventsService.publish('DoLogout', {}); } @@ -129,22 +282,22 @@ export class MermsServiceProviderService { this.lastQueued = sec console.log( '[' + - marker + - '] inside semaphore: wait (queued: ' + - this.queued + - ', lastQueued: ' + - this.lastQueued + - ')' + marker + + '] inside semaphore: wait (queued: ' + + this.queued + + ', lastQueued: ' + + this.lastQueued + + ')' ) await this.delay(1000) console.log( '[' + - marker + - '] inside semaphore: done (queued: ' + - this.queued + - ', lastQueued: ' + - this.lastQueued + - ')' + marker + + '] inside semaphore: done (queued: ' + + this.queued + + ', lastQueued: ' + + this.lastQueued + + ')' ) return } @@ -152,22 +305,22 @@ export class MermsServiceProviderService { this.queued++ console.log( '[' + - marker + - '] inside semaphore: wait (queued: ' + - this.queued + - ', lastQueued: ' + - this.lastQueued + - ')' + marker + + '] inside semaphore: wait (queued: ' + + this.queued + + ', lastQueued: ' + + this.lastQueued + + ')' ) await this.delay(1000 + 1000 * this.queued) console.log( '[' + - marker + - '] inside semaphore: done (queued: ' + - this.queued + - ', lastQueued: ' + - this.lastQueued + - ')' + marker + + '] inside semaphore: done (queued: ' + + this.queued + + ', lastQueued: ' + + this.lastQueued + + ')' ) }