Merge branch 'julius-dev' of Software_Engineering_I/greenvironment-frontend into master
commit
5b47e44b82
@ -1,37 +1,41 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Headers, Http} from '@angular/http';
|
|
||||||
import {DatasharingService} from '../datasharing.service';
|
|
||||||
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 {HttpClient} from '@angular/common/http';
|
||||||
|
import {BaseService} from '../base.service';
|
||||||
|
|
||||||
|
const graphqlCreateGroupQuery = `mutation($name: String!) {
|
||||||
|
createGroup(name: $name) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class SocialService {
|
export class SocialService extends BaseService {
|
||||||
|
|
||||||
users: Array<User>;
|
|
||||||
constructor(private http: Http, private data: DatasharingService, private router: Router) {
|
|
||||||
}
|
|
||||||
|
|
||||||
createGroup(name: string) {
|
constructor(private http: HttpClient) {
|
||||||
const headers = new Headers();
|
super();
|
||||||
headers.set('Content-Type', 'application/json');
|
|
||||||
this.http.post(environment.graphQLUrl, this.buildJsonGroup(name)).subscribe(response => {
|
|
||||||
console.log(response.text()); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public buildJsonGroup(name_: String): any {
|
/**
|
||||||
const body = {
|
* Builds the body for a group creation request
|
||||||
query: `mutation($name: String!) {
|
* @param name
|
||||||
createGroup(name: $name) {
|
*/
|
||||||
id
|
private static buildGroupCreateBody(name: String): any {
|
||||||
}
|
return {
|
||||||
}`
|
query: graphqlCreateGroupQuery, variables: {
|
||||||
, variables: {
|
name
|
||||||
name: name_
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return body;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
createGroup(name: string) {
|
||||||
|
const body = SocialService.buildGroupCreateBody(name);
|
||||||
|
return this.http.post(environment.graphQLUrl, body, {headers: this.headers});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue