Add activity service
parent
b6a8296eee
commit
894f8c498d
@ -1,23 +0,0 @@
|
|||||||
|
|
||||||
export interface Action {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
points: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Actionlist {
|
|
||||||
|
|
||||||
Actions: Action[] = [
|
|
||||||
{ id: 0, name: 'collect a lot of trash', points: 25},
|
|
||||||
{ id: 1, name: 'collect a bit of trash', points: 10 },
|
|
||||||
{ id: 2, name: 'do trash seperation', points: 5 },
|
|
||||||
{ id: 3, name: 'plant a tree', points: 2 },
|
|
||||||
{ id: 4, name: 'beautify your surroundings', points: 8 },
|
|
||||||
{ id: 5, name: 'reduce waste', points: 5 },
|
|
||||||
{ id: 6, name: 'reduce CO2 emission', points: 5 },
|
|
||||||
{ id: 7, name: 'eat a vegetarian meal', points: 2 },
|
|
||||||
{ id: 8, name: 'don\'t use the car', points: 10 },
|
|
||||||
{ id: 9, name: 'buy a fair trade / local product', points: 1 },
|
|
||||||
{ id: 10, name: 'donate money to an environment organisation ', points: 10 },
|
|
||||||
];
|
|
||||||
}
|
|
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
export interface Action {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
points: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Activitylist {
|
||||||
|
Actions: Action[] = new Array();
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ActivityService } from './activity.service';
|
||||||
|
|
||||||
|
describe('ActivityService', () => {
|
||||||
|
beforeEach(() => TestBed.configureTestingModule({}));
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
const service: ActivityService = TestBed.get(ActivityService);
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,72 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
import { Activitylist } from 'src/app/models/activity';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { Http } from '@angular/http';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class ActivityService {
|
||||||
|
|
||||||
|
private activitylist = new BehaviorSubject<Activitylist>(new Activitylist());
|
||||||
|
currentActivityList = this.activitylist.asObservable();
|
||||||
|
|
||||||
|
constructor(private http: Http) { }
|
||||||
|
|
||||||
|
changeUserInfo(pActivitylist: Activitylist) {
|
||||||
|
this.activitylist.next(pActivitylist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getActivitys() {
|
||||||
|
const headers = new Headers();
|
||||||
|
headers.set('Content-Type', 'application/json');
|
||||||
|
this.http.post(environment.graphQLUrl, this.buildJson()).subscribe(result => {
|
||||||
|
// push onto subject
|
||||||
|
this.activitylist.next(this.renderActivity(result.json()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public buildJson(id: string): any {
|
||||||
|
const body = {query: `query($userId: ID) {
|
||||||
|
getUser(userId:$userId){
|
||||||
|
id
|
||||||
|
handle
|
||||||
|
name
|
||||||
|
profilePicture
|
||||||
|
points
|
||||||
|
level
|
||||||
|
friendCount
|
||||||
|
groupCount
|
||||||
|
joinedAt
|
||||||
|
friends{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
posts{
|
||||||
|
id,
|
||||||
|
content,
|
||||||
|
htmlContent,
|
||||||
|
upvotes,
|
||||||
|
downvotes,
|
||||||
|
userVote,
|
||||||
|
deletable,
|
||||||
|
author{
|
||||||
|
name,
|
||||||
|
handle,
|
||||||
|
id},
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`, variables: {
|
||||||
|
userId: id,
|
||||||
|
}};
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public renderActivity(response: any): Activitylist {
|
||||||
|
const activitylist = new Activitylist();
|
||||||
|
// activitylist.push();
|
||||||
|
return activitylist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
@import '~@angular/material/theming'
|
@import '~@angular/material/theming'
|
||||||
|
|
||||||
$primary: mat-palette($mat-light-green);
|
$primary: mat-palette($mat-light-green)
|
||||||
$primary-color: mat-color($primary);
|
$primary-color: mat-color($primary)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue