bug restauCateg = ok

This commit is contained in:
Thomas Cardon 2022-03-09 14:52:09 +01:00
parent 8b70164a9f
commit f7d6b0f691
1 changed files with 42 additions and 39 deletions

View File

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { forkJoin } from 'rxjs';
import { forkJoin, of } from 'rxjs';
import { ApiBackService } from 'src/app/services/api-back.service';
import { TokenService } from 'src/app/services/token.service';
import { Preference } from '../models/preference';
@ -12,33 +12,35 @@ import { Restaurant } from '../models/restaurant';
})
export class RestoPageComponent implements OnInit {
public listRestaurants : Restaurant[];
public listPref : any;
public restaurantPref : any;
public beforeRoute ?: string ;
private userId : number | null;
public listRestaurants: Restaurant[];
public listPref: any;
public restaurantPref: any;
public beforeRoute?: string;
private userId: number | null;
constructor(private apiBackService : ApiBackService,
private tokenService : TokenService) {
constructor(private apiBackService: ApiBackService,
private tokenService: TokenService) {
this.listRestaurants = [];
this.restaurantPref = [];
this.beforeRoute = this.apiBackService.routeParam;
this.userId=0;
this.userId = 0;
}
ngOnInit(): void {
this.restauLiked();
this.listRestaurants = [];
this.userId = this.tokenService.getCurrentUserId();
}
// onEventLike(liked : any, idRestau : number | undefined){
// //this.apiBackService.restoLiked$.next(true);
// console.log(this.userId);
// console.log(idRestau);
// if(liked){
// this.apiBackService.addPreference(this.userId,idRestau).subscribe();
// }else{
@ -46,46 +48,47 @@ export class RestoPageComponent implements OnInit {
// }
// }
saveRestauList(event : any){
saveRestauList(event: any) {
console.log(event);
this.listRestaurants = event;
}
restauLiked(){
restauLiked() {
forkJoin({
restaurants: this.apiBackService.getRestaurants(),
user: this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()),
restauByCat : this.apiBackService.restoByCat
}).subscribe(({restaurants, user, restauByCat}) => {
restauByCat: this.apiBackService.restoByCat
}).subscribe(({ restaurants, user, restauByCat }) => {
if(this.beforeRoute === "filtres"){
if (this.beforeRoute === "filtres") {
this.listRestaurants = this.apiBackService.restoFilter;
}else if(this.beforeRoute === "categories" ){
this.listRestaurants = restauByCat
}else{
this.listRestaurants = restaurants;
}
this.listPref = user.preference;
for (let i = 0; i < this.listPref.length; i++) {
this.restaurantPref.push(this.listPref[i]['preferencePK']['restau']);
}
const listRestauIdLike = this.restaurantPref.map((x: any) => x.id);
this.listRestaurants.forEach((restau: any) => {
if(listRestauIdLike.includes(restau.id))
//console.log(restau);
restau.restauLike = true;
});
} else if (this.beforeRoute === "categories" && restauByCat.length > 0) {
this.listRestaurants = restauByCat
this.apiBackService.restoByCat = of([]);
} else {
this.listRestaurants = restaurants;
}
this.listPref = user.preference;
for (let i = 0; i < this.listPref.length; i++) {
this.restaurantPref.push(this.listPref[i]['preferencePK']['restau']);
}
const listRestauIdLike = this.restaurantPref.map((x: any) => x.id);
this.listRestaurants.forEach((restau: any) => {
if (listRestauIdLike.includes(restau.id))
//console.log(restau);
restau.restauLike = true;
});
}
);