<commit_before>import { Recipe } from './../models/recipe';
import { Injectable } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { UserInterface } from '../interfaces/user';

@Injectable()
export class UserData {
    private db: AngularFireDatabase;
    private firebaseCollection: FirebaseListObservable<any[]>;
    public items;

    constructor(db: AngularFireDatabase) {
        this.db = db;
        this.firebaseCollection = this.db.list('/users');
    }

    getAll() {
        this.firebaseCollection
            .subscribe(items => {
                this.items = items;
            });

        return this.items;
    }

    // need to add some notifications, not console outputs
    add(userId: string, user: UserInterface): void {
        const path = `users/${userId}`;

        this.db.object(path)
            .set(user)
            .catch(error => console.log(error));
    }

    private update(userId: number, data: object): void {
        const path = `users/${userId}`;

        this.db.object(path)
            .update(data)
            .catch(error => console.log(error));
    }

    getUserByUid(id: number) {
    }
}<commit_msg>logic for retrieving user profile image url from firebase storage added<commit_after>import { Recipe } from './../models/recipe';
import { Injectable } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { UserInterface } from '../interfaces/user';
import * as firebase from 'firebase';

@Injectable()
export class UserData {
    private db: AngularFireDatabase;
    private firebaseCollection: FirebaseListObservable<any[]>;
    public items;
    public user;
    public userProfileImage;

    constructor(db: AngularFireDatabase) {
        this.db = db;
        this.firebaseCollection = this.db.list('/users');
    }

    getAll() {
        this.firebaseCollection
            .subscribe(items => {
                this.items = items;
            });

        return this.items;
    }

    // need to add some notifications, not console outputs
    add(userId: string, user: UserInterface): void {
        const path = `users/${userId}`;

        this.db.object(path)
            .set(user)
            .catch(error => console.log(error));
    }

    private update(userId: number, data: object): void {
        const path = `users/${userId}`;

        this.db.object(path)
            .update(data)
            .catch(error => console.log(error));
    }

    getUserByUid(userId: string) {
        const path = `users/${userId}`;
        return this.db.object(path);
    }

    getUserProfileImageUrl(userId: string) {
        const subscription = this.getUserByUid(userId)
            .subscribe(user => this.user = user);

        const imageName = this.user.profileImage.name;
        const userStorageRef = firebase.storage().ref().child(`images/users/` + userId + '/' + imageName);
        return userStorageRef.getDownloadURL()
            .then(url => {
                console.log(this.user);
                return url;
            });
    }
}
{'fraction_non_alphanumeric': 0.1266347687400319, 'fraction_numerical': 0.0006379585326953748, 'mean_word_length': 2.3576017130620985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2476668', 'n_tokens_mistral': 891, 'n_tokens_neox': 882, 'n_words': 200}