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: HttpClient) {
|
||||||
constructor(private http: Http, private data: DatasharingService, private router: Router) {
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
createGroup(name: string) {
|
/**
|
||||||
const headers = new Headers();
|
* Builds the body for a group creation request
|
||||||
headers.set('Content-Type', 'application/json');
|
* @param name
|
||||||
this.http.post(environment.graphQLUrl, this.buildJsonGroup(name)).subscribe(response => {
|
*/
|
||||||
console.log(response.text()); });
|
private static buildGroupCreateBody(name: String): any {
|
||||||
}
|
return {
|
||||||
|
query: graphqlCreateGroupQuery, variables: {
|
||||||
public buildJsonGroup(name_: String): any {
|
name
|
||||||
const body = {
|
|
||||||
query: `mutation($name: String!) {
|
|
||||||
createGroup(name: $name) {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
, variables: {
|
|
||||||
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