Skip to content

Commit

Permalink
fix: All Friends api call
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash7824 committed Aug 31, 2024
1 parent a06a787 commit 584c66f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/app/pages/social/social.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ import { CommonService } from 'src/app/services/common.service';
})
export class SocialComponent implements OnInit{

allUsers: any;
allFriends: any;
constructor(public apiServ: ApiService, public cs: CommonService){}

ngOnInit(){
if(!this.cs.socialLoaded){
this.getAllUsers().then((val: any) => {
this.cs.friendsList = this.allUsers;
this.getAllFriends().then((val: any) => {
this.cs.friendsList = this.allFriends.friends;
this.cs.socialLoaded = true;
})
}
}

getAllUsers() : Promise<any>{
return this.apiServ.get("admin/getAllUsers").then((res: any) => {
this.allUsers = res;
getAllFriends() : Promise<any>{
return this.apiServ.get("social/getAllFriends").then((res: any) => {
this.allFriends = res;
}, (error: any) => console.error(error))
}

searchFriends(ev: any){
let name = ev.target.value;
if(!name){
this.cs.friendsList = this.allUsers;
this.cs.friendsList = this.allFriends;
}

this.cs.friendsList = [];
for(let user of this.allUsers){
let case_sensitive_user_name = user.name.toLowerCase();
for(let friend of this.allFriends){
let case_sensitive_user_name = friend.name.toLowerCase();
if(case_sensitive_user_name.includes(name.toLowerCase())){
if(!this.cs.friendsList.some(friend => friend.name == user.name)){
this.cs.friendsList.push(user);
if(!this.cs.friendsList.some(friend => friend.name == friend.name)){
this.cs.friendsList.push(friend);
}
}
}
Expand Down

0 comments on commit 584c66f

Please sign in to comment.