|
|
|
@ -1,21 +1,22 @@
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { Injectable, OnInit } from '@angular/core';
|
|
|
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
|
|
|
import { environment } from '../../../environments/environment';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class FriendsService {
|
|
|
|
|
export class FriendsService {
|
|
|
|
|
|
|
|
|
|
private apiURL = environment.apiURL;
|
|
|
|
|
private token = localStorage.getItem('auth_token');
|
|
|
|
|
constructor(private http: HttpClient) { }
|
|
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFriend() {
|
|
|
|
|
console.log("getFriends");
|
|
|
|
|
const url = `${this.apiURL}/friends`;
|
|
|
|
|
const headers = new HttpHeaders({
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: 'Bearer ' + this.token,
|
|
|
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
|
|
|
});
|
|
|
|
|
return this.http.get<any[]>(url, { headers });
|
|
|
|
|
}
|
|
|
|
@ -24,17 +25,35 @@ export class FriendsService {
|
|
|
|
|
const url = `${this.apiURL}/user/${id}`;
|
|
|
|
|
const headers = new HttpHeaders({
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: 'Bearer ' + this.token,
|
|
|
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
|
|
|
});
|
|
|
|
|
return this.http.get<any>(url, { headers });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
acceptOrDenyFriendById(id: string,choice: string){
|
|
|
|
|
const url = `${this.apiURL}/friend/${id}/${choice}`;
|
|
|
|
|
acceptFriendById(id: string){
|
|
|
|
|
const url = `${this.apiURL}/friend/${id}/accept`;
|
|
|
|
|
const headers = new HttpHeaders({
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: 'Bearer ' + this.token,
|
|
|
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
|
|
|
});
|
|
|
|
|
return this.http.get<any>(url, { headers });
|
|
|
|
|
return this.http.patch<any>(url, [], { headers });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
denyFriendById(id: string){
|
|
|
|
|
const url = `${this.apiURL}/friend/${id}/deny`;
|
|
|
|
|
const headers = new HttpHeaders({
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
|
|
|
});
|
|
|
|
|
return this.http.post<any>(url, [], { headers });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteFriend(id: string){
|
|
|
|
|
const url = `${this.apiURL}/friend/${id}/delete`;
|
|
|
|
|
const headers = new HttpHeaders({
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: 'Bearer ' + localStorage.getItem('auth_token'),
|
|
|
|
|
});
|
|
|
|
|
return this.http.delete<any>(url, { headers });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|