Commit c6778c37 authored by Sofia Aicha Delijaj's avatar Sofia Aicha Delijaj
Browse files

we can edit the requests

parent cceafc93
......@@ -28,7 +28,7 @@ Joueur.auth = (email, password, result) => {
};
Joueur.amiListe = (pseudo, results) => {
sql.query('SELECT DISTINCT pseudo, ami.id_joueur2, accept FROM ami,joueur WHERE (ami.id_joueur2 = joueur.id_joueur AND ami.id_joueur1 = ?) OR (ami.id_joueur1 = joueur.id_joueur AND ami.id_joueur2 = ?)', [pseudo, pseudo], (err, res) => {
sql.query('SELECT DISTINCT pseudo, ami.id_joueur2, ami.id_joueur1, accept FROM ami,joueur WHERE (ami.id_joueur2 = joueur.id_joueur AND ami.id_joueur1 = ?) OR (ami.id_joueur1 = joueur.id_joueur AND ami.id_joueur2 = ?)', [pseudo, pseudo], (err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
......@@ -79,7 +79,7 @@ Joueur.accept = (pseudo, ami, result) => {
};
Joueur.refuse = (pseudo, ami, result) => {
sql.query("DELETE FROM ami WHERE id_joueur1 = ? AND id_joueur2 = ?", [pseudo, ami], (err, res) => {
sql.query("DELETE FROM ami WHERE id_joueur1 = ? AND id_joueur2 = ?", [ami, pseudo], (err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
......@@ -90,7 +90,7 @@ Joueur.refuse = (pseudo, ami, result) => {
return;
}
console.log("deleted Pokemon with id: ", ami, "from team of user with id: ", id_joueur);
console.log("deleted Pokemon with id: ", ami, "from team of user with id: ", pseudo);
result(null, res);
});
};
......
......@@ -31,10 +31,10 @@
<div class="container py-3" *ngIf="requests!=null">
<div *ngFor="let req of requests; let i=index">
<h4>{{req.pseudo}}</h4>
<div class="btn btn-primary" id="ami" (click)="accepter(req.id_joueur2)">
<div class="btn btn-primary" id="ami" (click)="accepter(req)">
<h6>Accepter</h6>
</div>
<div class="btn btn-primary" id="ami" (click)="refuser(req.id_joueur2)">
<div class="btn btn-primary" id="ami" (click)="refuser(req)">
<h6>Refuser</h6>
</div>
</div>
......
......@@ -20,6 +20,9 @@ export class FriendsMenuComponent implements OnInit {
nom: any = {};
results: any[] = [];
requests: any = [];
pseudo: string;
uid;
temp;
constructor(private httpClient: HttpClient) { }
......@@ -47,7 +50,7 @@ export class FriendsMenuComponent implements OnInit {
}
ordre(){
this.httpClient.get('http://localhost:3000/allfriends', { responseType: 'json', withCredentials:true }).subscribe((res => {this.resultat = res; this.isFriend(); this.log=this.resultat.rep; console.log(res)}))
this.httpClient.get('http://localhost:3000/allfriends', { responseType: 'json', withCredentials:true }).subscribe((res => {this.resultat = res; this.isFriend(); console.log(res)}))
}
isFriend(){
......@@ -61,25 +64,35 @@ export class FriendsMenuComponent implements OnInit {
}
accepter(idAmi){
if(idAmi.id_joueur1 == this.uid){
this.temp = idAmi.id_joueur2
} else {
this.temp = idAmi.id_joueur1
}
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/yayami', { id_joueur2: idAmi}, { headers: headers, withCredentials: true}).subscribe(
this.httpClient.post('http://localhost:3000/yayami', { id_joueur2: this.temp}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
}
refuser(idAmi){
if(idAmi.id_joueur1 == this.uid){
this.temp = idAmi.id_joueur2
} else {
this.temp = idAmi.id_joueur1
}
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/nayami', { id_joueur2: idAmi}, { headers: headers, withCredentials: true}).subscribe(
this.httpClient.post('http://localhost:3000/nayami', { id_joueur2: this.temp}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
}
ngOnInit(): void {
liste(){
this.httpClient.get("http://localhost:3000/alljoueurs", { responseType: 'json', withCredentials:true}).
subscribe(res => {this.joueurs = res; this.ordre(); console.log(res)})
this.queryField.valueChanges
......@@ -88,4 +101,13 @@ export class FriendsMenuComponent implements OnInit {
.subscribe(query => this.results = this.suggest(query));
}
ngOnInit(): void {
this.httpClient.get("http://localHost:3000/checkLogin", { responseType: 'json', withCredentials: true}).subscribe( (res: any) => {
this.log = res.res;
this.pseudo = res.body;
this.uid = res.uid;
this.liste();
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment