From bf8acced6c13c5f130f43bebb7f0a6bd4c3f3679 Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sun, 8 Nov 2020 17:37:26 +0000 Subject: [PATCH] Clear up API code a little --- src/app/providers/api-service.ts | 45 ++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index 865a397..b2cbc80 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -55,18 +55,19 @@ export class ApiService { this.apiUrl + '/login', data ).pipe( - map( - result => { - const json = result; - this.setSessionKey(json.session_key); - this.setUserInfo( - json.email, - json.display_name || json.name - ); - this.setUserType(json.user_type); - return json; - } - )); + map( + result => { + const json = result; + this.setSessionKey(json.session_key); + this.setUserInfo( + json.email, + json.display_name || json.name, + ); + this.setUserType(json.user_type); + return json; + } + ) + ); } public logout() { @@ -92,16 +93,28 @@ export class ApiService { data.package_name = 'Foodloop Web'; data.version_code = 'dev'; data.version_number = 'dev'; - console.log(this.apiUrl + '/feedback'); return this.http.post( this.apiUrl + '/feedback', data ); } - // Sends push notifications + // Push notifications + + public addDeviceToken(data) { + const key = this.sessionKey; + return this.http.post( + this.apiUrl + '/add-device-token', + { + session_key: key, + token: data + } + ); + } public sendMessage(data) { + data.devicetoken = environment.deviceToken; + data.sender = localStorage.getItem('displayname'); return this.http.post( this.apiUrl + '/send-message', data @@ -269,9 +282,7 @@ export class ApiService { // Pulls user info to store locally on login - public setUserInfo( - email: string, - display_name: string) { + public setUserInfo(email: string, display_name: string) { localStorage.setItem('email', email); localStorage.setItem('displayname', display_name); }