import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; /* Generated class for StoreDetailsProvider. See https://angular.io/docs/ts/latest/guide/dependency-injection.html for more info on providers and Angular 2 DI. */ @Injectable() export class StoreCheckinProvider { public checkinResponse: any; constructor(public http: Http) {} checkin(userId: number, storeName: String, currentProvider: string) { // Contrary to common provider implementation, this provider does not // cache the response of a checkin request from the API. // This ensures that each checkin request receives an up-to-date and valid // reponse. return new Promise(resolve => { this.http.get(currentProvider + storeName + '/users/' + userId + '/checkin') .map(res => res.json()) .subscribe(data => { // we've got back the raw data, now generate the core schedule data // and save the data for later reference this.checkinResponse = data; resolve(this.checkinResponse); }, (err) => { console.error('Error checking in userId: ' + userId + ' in storeId: ' + storeName + ' with:', err); }); }); } }