|
|
@ -4,6 +4,7 @@ import {DatasharingService} from '../datasharing.service';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {environment} from 'src/environments/environment';
|
|
|
|
import {environment} from 'src/environments/environment';
|
|
|
|
import { User } from 'src/app/models/user';
|
|
|
|
import { User } from 'src/app/models/user';
|
|
|
|
|
|
|
|
import { GroupInfo } from 'src/app/models/groupinfo';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
@Injectable({
|
|
|
@ -36,6 +37,19 @@ export class RequestService {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public isAllowedToJoinGroup(groupId: number, self: User): boolean {
|
|
|
|
|
|
|
|
// returns false if user is not logged in or is member of the group(Id)
|
|
|
|
|
|
|
|
if (!self.loggedIn) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const group of self.groups) {
|
|
|
|
|
|
|
|
if (group.id === groupId) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public sendFriendRequest(user: User) {
|
|
|
|
public sendFriendRequest(user: User) {
|
|
|
|
this.data.addSentRequestUserID(user.userID);
|
|
|
|
this.data.addSentRequestUserID(user.userID);
|
|
|
|
const headers = new Headers();
|
|
|
|
const headers = new Headers();
|
|
|
@ -45,6 +59,14 @@ export class RequestService {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public joinGroup(group: GroupInfo) {
|
|
|
|
|
|
|
|
const headers = new Headers();
|
|
|
|
|
|
|
|
headers.set('Content-Type', 'application/json');
|
|
|
|
|
|
|
|
this.http.post(environment.graphQLUrl, this.buildJsonJoinGroup(group.id))
|
|
|
|
|
|
|
|
.subscribe(response => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public buildJsonRequest(id_: number, type_: String): any {
|
|
|
|
public buildJsonRequest(id_: number, type_: String): any {
|
|
|
|
const body = {
|
|
|
|
const body = {
|
|
|
|
query: `mutation($id: ID!, $type: RequestType) {
|
|
|
|
query: `mutation($id: ID!, $type: RequestType) {
|
|
|
@ -60,6 +82,20 @@ export class RequestService {
|
|
|
|
return body;
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public buildJsonJoinGroup(id_: number): any {
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
|
|
|
query: `mutation($id: ID!) {
|
|
|
|
|
|
|
|
joinGroup(id: $id) {
|
|
|
|
|
|
|
|
id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`
|
|
|
|
|
|
|
|
, variables: {
|
|
|
|
|
|
|
|
id: id_
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public buildJsonAcceptRequest(id_: number): any {
|
|
|
|
public buildJsonAcceptRequest(id_: number): any {
|
|
|
|
const body = {
|
|
|
|
const body = {
|
|
|
|
query: `mutation($id: ID!) {
|
|
|
|
query: `mutation($id: ID!) {
|
|
|
|