From ea29de6f7b5695b872770f1a15aba788f67e2088 Mon Sep 17 00:00:00 2001 From: panpan2 Date: Thu, 15 Jun 2017 21:36:56 +0100 Subject: [PATCH] Add functionality to follow user on user's profile --- aurelia-app/src/components/profile.html | 2 +- aurelia-app/src/components/profile.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/aurelia-app/src/components/profile.html b/aurelia-app/src/components/profile.html index 28b9a6d..cafbfad 100644 --- a/aurelia-app/src/components/profile.html +++ b/aurelia-app/src/components/profile.html @@ -23,7 +23,7 @@

${owner.name} ${owner.surname} | ${name}

${j.name} CHECK WHO I'M FOLLOWING -
+
${f.name}
diff --git a/aurelia-app/src/components/profile.js b/aurelia-app/src/components/profile.js index dae83ec..81a37f3 100644 --- a/aurelia-app/src/components/profile.js +++ b/aurelia-app/src/components/profile.js @@ -1,31 +1,37 @@ import { RestApi } from 'services/api' import {AuthService} from 'aurelia-authentication'; import {Login} from "./login/login"; +import {Config} from "aurelia-api"; + export class Profile { - static inject = [RestApi, AuthService, Login] + static inject = [RestApi, AuthService, Login, Config] - constructor(restApi, authService, login) { + constructor(restApi, authService, login, config) { this.restApi = restApi this.authService = authService this.login = login + this.apiEndpoint = config.getEndpoint('api') } activate(params, routeConfig) { this.restApi.getJourneysOfUser(params.id).then(journeys => this.journeys = journeys) return this.restApi.getUser(params.id).then(user => { - Object.assign(this, ...user); + this.user = user; }) } follow() { if (!this.authService.authenticated) { - console.log('you are not auth') this.login.authenticate('facebook') - } else { - console.log('you are auth') + if (!this.authService.authenticated) { + return + } } + return this.authService.getMe().then( + profile => this.apiEndpoint.post(`/users/${profile.id}/followers`, { "id": this.user.id }) + ) } }