Applied tslint auto-fixes

master
Trivernis 5 years ago
parent fbeaf126d7
commit 7c15028178

@ -12,29 +12,29 @@ export class AppComponent implements OnInit {
constructor(private data: DatasharingService, private selfservice: SelfService) { }
userInfo: User
userInfo: User;
loggedIn : boolean = false;
userID : number;
username : string;
handle : string;
email : string;
points : number;
level : number;
loggedIn = false;
userID: number;
username: string;
handle: string;
email: string;
points: number;
level: number;
friendIDs : number[];
groupIDs : number[];
chatIDs : number[];
friendIDs: number[];
groupIDs: number[];
chatIDs: number[];
requestIDs : number[];
requestIDs: number[];
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.userInfo = user;
console.log(this.userInfo);
this.data.changeChatIDs(user.chatIDs)
})
if(this.loggedIn != true){
this.data.changeChatIDs(user.chatIDs);
});
if (this.loggedIn != true) {
this.selfservice.checkIfLoggedIn();
}
}

@ -63,7 +63,7 @@ const appRoutes: Routes = [
{ path: 'register', component: RegisterComponent },
{ path: 'about', component: AboutComponent },
{ path: 'imprint', component: ImprintComponent },
]
];
@NgModule({
declarations: [

@ -15,57 +15,56 @@ import { environment } from 'src/environments/environment';
})
export class AppScaffoldComponent implements OnInit {
loggedIn: boolean = false;
loggedIn = false;
userId: number;
username: string
user: User
levellist: Levellist = new Levellist()
level: string
points: number
username: string;
user: User;
levellist: Levellist = new Levellist();
level: string;
points: number;
profileUrl: string;
dropdownShown: boolean = false
dropdownShown = false;
constructor(private data: DatasharingService,private selfservice: SelfService, private http: Http, private router: Router) { }
constructor(private data: DatasharingService, private selfservice: SelfService, private http: Http, private router: Router) { }
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.user = user
this.user = user;
this.loggedIn = user.loggedIn;
this.userId = user.userID;
this.username = user.username
this.level = this.levellist.getLevelName(user.level)
this.points = user.points
this.username = user.username;
this.level = this.levellist.getLevelName(user.level);
this.points = user.points;
this.profileUrl = '/profile/' + this.userId;
})
});
}
showDropdown() {
if(!this.dropdownShown) {
this.dropdownShown = true
}
else {
this.dropdownShown = false
if (!this.dropdownShown) {
this.dropdownShown = true;
} else {
this.dropdownShown = false;
}
}
logout() {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation {
logout
}`}
}`};
this.http.post(url, body).subscribe(response => {
console.log(response.text())})
this.loggedIn = false
let user = new User()
user.loggedIn = false
this.data.changeUserInfo(user)
this.router.navigate(['login'])
console.log(response.text()); });
this.loggedIn = false;
const user = new User();
user.loggedIn = false;
this.data.changeUserInfo(user);
this.router.navigate(['login']);
}
}

@ -11,7 +11,7 @@ import { Chat } from 'src/app/models/chat';
})
export class ChatComponent implements OnInit {
messages:Array<Chatmessage>
messages: Array<Chatmessage>;
@Output() goBackEvent = new EventEmitter<boolean>();
@Input() childChat: Chat;
@ -19,29 +19,28 @@ export class ChatComponent implements OnInit {
constructor(private chatService: ChatService) { }
ngOnInit() {
this.refresh()
this.refresh();
}
goBack() {
this.goBackEvent.emit(true)
this.goBackEvent.emit(true);
}
sendMessage(pElement) {
this.chatService.sendMessage(this.childChat.id, pElement.value)
.subscribe(response => {
console.log("Message sent")
pElement.value = ""
this.refresh()
})
console.log('Message sent');
pElement.value = '';
this.refresh();
});
}
refresh() {
this.chatService.getMessagesRaw(this.childChat.id)
.subscribe(response =>
{
console.log("Downloading messages ...")
this.messages = this.chatService.renderMessages(response.json())
})
.subscribe(response => {
console.log('Downloading messages ...');
this.messages = this.chatService.renderMessages(response.json());
});
}
}

@ -10,7 +10,7 @@ import { ChatService } from 'src/app/services/chat/chat.service';
})
export class ChatlistComponent implements OnInit {
@Input() childChats: Array<Chat>
@Input() childChats: Array<Chat>;
@Output() showChatEvent = new EventEmitter<Chat>();
@Output() showCreateChatEvent = new EventEmitter<boolean>();
selectedChat: Chat;
@ -18,20 +18,20 @@ export class ChatlistComponent implements OnInit {
constructor(private chatService: ChatService) { }
ngOnInit() {
}
showNewChat() {
this.showCreateChatEvent.emit(true)
this.showCreateChatEvent.emit(true);
}
showChat(pChat: Chat) {
this.selectedChat = pChat
this.showChatEvent.emit(this.selectedChat)
this.selectedChat = pChat;
this.showChatEvent.emit(this.selectedChat);
}
newChat() {
console.error("not implemented")
console.error('not implemented');
}
}

@ -10,7 +10,7 @@ import { ChatService } from 'src/app/services/chat/chat.service';
export class ChatcontactsComponent implements OnInit {
@Output() goBackEvent = new EventEmitter<boolean>();
selectedContact: FriendInfo
selectedContact: FriendInfo;
constructor(private chatService: ChatService) { }
@ -18,17 +18,17 @@ export class ChatcontactsComponent implements OnInit {
}
goBack() {
this.goBackEvent.emit(true)
this.goBackEvent.emit(true);
}
createChat(pFriendInfo: FriendInfo) {
this.selectedContact = pFriendInfo
this.chatService.createNewChat(pFriendInfo.id)
this.goBack()
this.selectedContact = pFriendInfo;
this.chatService.createNewChat(pFriendInfo.id);
this.goBack();
}
contactList() {
console.error("Not Imlemented!")
console.error('Not Imlemented!');
}
}

@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ChatService } from '../../services/chat/chat.service'
import { ChatService } from '../../services/chat/chat.service';
import { ChatComponent } from '../chat/chat.component';
import { Chatinfo } from 'src/app/models/chatinfo';
import { DatasharingService } from 'src/app/services/datasharing.service';
@ -12,12 +12,12 @@ import { Chat } from 'src/app/models/chat';
})
export class ChatmanagerComponent implements OnInit {
showChatlist: boolean = true
showChat: boolean = false
showCreateNewChat: boolean = false
showChatlist = true;
showChat = false;
showCreateNewChat = false;
parentSelectedChat: Chat
parentChats: Array<Chat>
parentSelectedChat: Chat;
parentChats: Array<Chat>;
constructor(private data: DatasharingService, private chatService: ChatService) { }
@ -25,36 +25,36 @@ export class ChatmanagerComponent implements OnInit {
/*this.data.currentChatIDs.subscribe(chatIDs => {
this.parentChatIds = chatIDs
})*/
this.refresh()
this.refresh();
}
goBackToChatlist($event) {
this.showChatlist = $event
this.showChat = false
this.showCreateNewChat = false
this.showChatlist = $event;
this.showChat = false;
this.showCreateNewChat = false;
this.refresh()
this.refresh();
}
showSpecialChat($event) {
this.parentSelectedChat = $event
this.showChatlist = false
this.showChat = true
this.showCreateNewChat = false
this.parentSelectedChat = $event;
this.showChatlist = false;
this.showChat = true;
this.showCreateNewChat = false;
}
showNewChat($event) {
this.showChatlist = false
this.showChat = false
this.showCreateNewChat = $event
this.showChatlist = false;
this.showChat = false;
this.showCreateNewChat = $event;
}
refresh() {
this.chatService.getAllChatsRaw()
.subscribe(response => {
console.log(response)
this.parentChats = this.chatService.renderAllChats(response.json())
})
console.log(response);
this.parentChats = this.chatService.renderAllChats(response.json());
});
}
}

@ -9,16 +9,16 @@ import { Actionlist } from 'src/app/models/actionlist';
styleUrls: ['./feed.component.sass']
})
export class FeedComponent implements OnInit {
checked: boolean //if the "I protected the environment."-box is checked
//points value of the green action
value: any
viewNew: boolean = true
viewMostLiked: boolean = false
checked: boolean; // if the "I protected the environment."-box is checked
// points value of the green action
value: any;
viewNew = true;
viewMostLiked = false;
feedNew: Array<Post>
feedMostLiked: Array<Post>
feedNew: Array<Post>;
feedMostLiked: Array<Post>;
parentSelectedPostList: Array<Post>
parentSelectedPostList: Array<Post>;
actionlist: Actionlist = new Actionlist();
@ -26,46 +26,46 @@ export class FeedComponent implements OnInit {
ngOnInit() {
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json())
this.parentSelectedPostList = this.feedNew
this.feedMostLiked = this.feedNew
console.log(this.feedNew)
})
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew;
console.log(this.feedNew);
});
}
createPost(pElement){
this.feedService.createPost(pElement.value)
pElement.value = ""
createPost(pElement) {
this.feedService.createPost(pElement.value);
pElement.value = '';
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json())
this.parentSelectedPostList = this.feedNew
this.feedMostLiked = this.feedNew})
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew;
this.feedMostLiked = this.feedNew; });
}
showNew() {
console.log("showNew()")
console.log('showNew()');
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json())
this.parentSelectedPostList = this.feedNew})
this.viewNew = true
this.viewMostLiked = false
this.feedNew = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedNew; });
this.viewNew = true;
this.viewMostLiked = false;
}
showMostLiked() {
console.log("showMostLiked()")
console.log('showMostLiked()');
this.feedService.getAllPostsRaw().subscribe(response => {
this.feedMostLiked = this.feedService.renderAllPosts(response.json())
this.parentSelectedPostList = this.feedMostLiked})
this.viewNew = false
this.viewMostLiked = true
this.feedMostLiked = this.feedService.renderAllPosts(response.json());
this.parentSelectedPostList = this.feedMostLiked; });
this.viewNew = false;
this.viewMostLiked = true;
}
refresh($event) {
this.feedService.getAllPostsRaw().subscribe(response => {
this.parentSelectedPostList = this.feedService.renderAllPosts(response.json())
console.log("Refresh")
})
this.parentSelectedPostList = this.feedService.renderAllPosts(response.json());
console.log('Refresh');
});
}
}

@ -9,9 +9,9 @@ import { FeedService } from 'src/app/services/feed/feed.service';
})
export class PostlistComponent implements OnInit {
@Input() childPostList: Array<Post>
@Output() voteEvent = new EventEmitter<boolean>()
selectedPost: Post
@Input() childPostList: Array<Post>;
@Output() voteEvent = new EventEmitter<boolean>();
selectedPost: Post;
constructor(private feedService: FeedService) { }
@ -20,12 +20,12 @@ export class PostlistComponent implements OnInit {
voteUp(pPost: Post) {
this.feedService.upvote(pPost.id).subscribe(response => {
this.voteEvent.emit(true)})
this.voteEvent.emit(true); });
}
voteDown(pPost: Post) {
this.feedService.downvote(pPost.id).subscribe(response => {
this.voteEvent.emit(true)})
this.voteEvent.emit(true); });
}
}

@ -9,15 +9,15 @@ import { FeedService } from 'src/app/services/feed/feed.service';
})
export class HomeComponent implements OnInit {
loggedIn: boolean
loggedIn: boolean;
constructor(private data: DatasharingService, private feedService: FeedService) { }
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.loggedIn = user.loggedIn;
})
this.feedService.getAllPosts()
});
this.feedService.getAllPosts();
}
}

@ -11,7 +11,7 @@ import * as sha512 from 'js-sha512';
styleUrls: ['./login.component.sass']
})
export class LoginComponent implements OnInit {
login: Login
login: Login;
hide = true;
errorOccurred: boolean = false;
errorMessage: string;
@ -31,14 +31,14 @@ export class LoginComponent implements OnInit {
}
onClickSubmit(pEmail: string, pPasswordHash: string) {
console.log('try to login with mail adress:' + pEmail);
console.log('try to login with mail adress:' + pEmail);
this.errorOccurred = false;
this.errorMessage = " ";
this.login.email = pEmail.trim()
this.login.email = pEmail.trim();
this.login.passwordHash = sha512.sha512(pPasswordHash);
console.log(this.login.passwordHash);
console.log(this.login.passwordHash)
console.log(this.login.passwordHash);
this.loginService.login(this.login, error => this.loginError(error.json()));
}

@ -17,16 +17,20 @@ import { OverlayContainer} from '@angular/cdk/overlay';
styleUrls: ['./main-navigation.component.sass']
})
export class MainNavigationComponent implements OnInit {
loggedIn: boolean = false
userId: number
username: string
user: User
levellist: Levellist = new Levellist()
level: string
points: number
profileUrl: string = "/profile/1"
lighttheme : boolean = true
constructor(public overlayContainer: OverlayContainer, private data: DatasharingService, private selfservice: SelfService, private breakpointObserver: BreakpointObserver, private http: Http, private router: Router) {
this.overlay = overlayContainer.getContainerElement();
}
loggedIn = false;
userId: number;
username: string;
user: User;
levellist: Levellist = new Levellist();
level: string;
points: number;
profileUrl = '/profile/1';
lighttheme = true;
overlay;
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
@ -34,22 +38,6 @@ export class MainNavigationComponent implements OnInit {
map(result => result.matches),
shareReplay()
);
constructor(public overlayContainer: OverlayContainer, private data: DatasharingService,private selfservice: SelfService,private breakpointObserver: BreakpointObserver, private http: Http, private router: Router) {
this.overlay = overlayContainer.getContainerElement();
}
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.user = user
this.loggedIn = user.loggedIn;
this.userId = user.userID;
this.username = user.username
this.level = this.levellist.getLevelName(user.level)
this.points = user.points
this.profileUrl = '/profile/' + this.userId;
this.updateLinks();
})
}
navLinksLoggedIn = [
{ path: '', label: 'Home' },
{ path: this.profileUrl, label: 'Profile' },
@ -62,22 +50,36 @@ export class MainNavigationComponent implements OnInit {
{ path: '/imprint', label: 'Imprint' },
{ path: '/login', label: 'Login' },
];
@HostBinding('class') componentCssClass;
ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.user = user;
this.loggedIn = user.loggedIn;
this.userId = user.userID;
this.username = user.username;
this.level = this.levellist.getLevelName(user.level);
this.points = user.points;
this.profileUrl = '/profile/' + this.userId;
this.updateLinks();
});
}
toggleTheme() {
if (this.overlay.classList.contains("dark-theme")) {
this.overlay.classList.remove("dark-theme");
this.overlay.classList.add("light-theme");
this.onSetTheme("light-theme");
} else if (this.overlay.classList.contains("light-theme")) {
this.overlay.classList.remove("light-theme");
this.overlay.classList.add("dark-theme");
this.onSetTheme("dark-theme");
if (this.overlay.classList.contains('dark-theme')) {
this.overlay.classList.remove('dark-theme');
this.overlay.classList.add('light-theme');
this.onSetTheme('light-theme');
} else if (this.overlay.classList.contains('light-theme')) {
this.overlay.classList.remove('light-theme');
this.overlay.classList.add('dark-theme');
this.onSetTheme('dark-theme');
} else {
this.overlay.classList.add("dark-theme");
this.onSetTheme("dark-theme");
this.overlay.classList.add('dark-theme');
this.onSetTheme('dark-theme');
}
}
updateLinks(){
updateLinks() {
this.navLinksLoggedIn = [
{ path: '', label: 'Home' },
{ path: this.profileUrl, label: 'Profile' },
@ -85,28 +87,26 @@ export class MainNavigationComponent implements OnInit {
{ path: '/imprint', label: 'Imprint' },
];
}
@HostBinding('class') componentCssClass;
onSetTheme(theme) {
this.overlayContainer.getContainerElement().classList.add(theme);
this.componentCssClass = theme;
}
logout() {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation {
logout
}`}
}`};
this.http.post(url, body).subscribe(response => {
console.log(response.text())})
this.loggedIn = false
let user = new User()
user.loggedIn = false
this.data.changeUserInfo(user)
this.router.navigate(['login'])
console.log(response.text()); });
this.loggedIn = false;
const user = new User();
user.loggedIn = false;
this.data.changeUserInfo(user);
this.router.navigate(['login']);
}
}

@ -15,28 +15,28 @@ import {MatTableDataSource} from '@angular/material/table';
})
export class ProfileComponent implements OnInit {
actionlist: Actionlist = new Actionlist()
levellist: Levellist = new Levellist()
user: User = new User()
id : string
rankname: string
profileNotFound : boolean = false
displayedColumns = ['points', 'name']
dataSource = new MatTableDataSource(this.actionlist.Actions)
displayedLevelColumns = ['level', 'name']
levelSource = this.levellist.levels
constructor(private router: Router,private http: Http) { }
actionlist: Actionlist = new Actionlist();
levellist: Levellist = new Levellist();
user: User = new User();
id: string;
rankname: string;
profileNotFound = false;
displayedColumns = ['points', 'name'];
dataSource = new MatTableDataSource(this.actionlist.Actions);
displayedLevelColumns = ['level', 'name'];
levelSource = this.levellist.levels;
constructor(private router: Router, private http: Http) { }
@ViewChild(MatSort, {static: true}) sort: MatSort;
ngOnInit() {
this.dataSource.sort = this.sort;
this.id = this.router.url.substr(this.router.url.lastIndexOf("/") + 1);
//let url = './graphql'
let url = environment.graphQLUrl
let headers = new Headers();
this.id = this.router.url.substr(this.router.url.lastIndexOf('/') + 1);
// let url = './graphql'
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson(this.id))
.subscribe(response => {
console.log(response.text());
@ -45,8 +45,8 @@ export class ProfileComponent implements OnInit {
);
}
public updateUserInfo(response : any){
if(response.data.getUser != null){
public updateUserInfo(response: any) {
if (response.data.getUser != null) {
this.profileNotFound = false;
this.user.loggedIn = true;
this.user.userID = response.data.getUser.id;
@ -56,7 +56,7 @@ export class ProfileComponent implements OnInit {
this.user.level = response.data.getUser.level;
this.rankname = this.levellist.getLevelName(this.user.level);
this.user.friendIDs = response.data.getUser.friends;
} else{
} else {
this.profileNotFound = true;
}
}
@ -69,17 +69,17 @@ export class ProfileComponent implements OnInit {
name
profilePicture
points
level
level
friendCount
friends{
id
}
posts{
content
}
}
}
}`, variables: {
userId: this.id
userId: this.id
}};
return body;
}

@ -12,40 +12,40 @@ import * as sha512 from 'js-sha512';
styleUrls: ['./register.component.sass']
})
export class RegisterComponent implements OnInit {
registration: Registration
errorOccurred: boolean = false;
registration: Registration;
errorOccurred = false;
errorMessage: string;
hide1 = true;
hide2 = true;
constructor(private registerService: RegisterService) {
this.registration = {username: null, passwordHash: null, email: null};
}
public registerError(error : any){
public registerError(error: any) {
console.log(error.errors[0].message);
this.errorOccurred = true;
this.errorMessage = error.errors[0].message;
}
onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string,pPasswordHashRepeat: string ) {
onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string, pPasswordHashRepeat: string ) {
this.errorOccurred = false;
this.errorMessage = " ";
if(this.passwordSame(pPasswordHash,pPasswordHashRepeat)){
this.registration.username = pUsername.trim()
this.registration.email = pEmail.trim()
this.errorMessage = ' ';
if (this.passwordSame(pPasswordHash, pPasswordHashRepeat)) {
this.registration.username = pUsername.trim();
this.registration.email = pEmail.trim();
this.registration.passwordHash = sha512.sha512(pPasswordHash);
this.registerService.register(this.registration, error => this.registerError(error.json()));
}
}
passwordSame(pwd: string,pwd2: string){
if(pwd == pwd2){
console.log('password same');
passwordSame(pwd: string, pwd2: string) {
if (pwd == pwd2) {
console.log('password same');
return true;
} else{
} else {
this.errorOccurred = true;
this.errorMessage = "not the same password";
this.errorMessage = 'not the same password';
return false;
}
}

@ -12,30 +12,30 @@ import { environment } from 'src/environments/environment';
})
export class FriendsComponent implements OnInit {
friendIDs: number[] = [29, 27, 30, 31]
friends = new Array<FriendInfo>() //= ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"]
friendIDs: number[] = [29, 27, 30, 31];
friends = new Array<FriendInfo>(); // = ["Friend 1", "Friend 2", "Friend 3", "Friend 4", "Friend 5", "Friend 6"]
constructor(private data: DatasharingService, private http: Http, private router: Router) { }
ngOnInit() {
//this.data.currentUserInfo.subscribe(user => {
// this.data.currentUserInfo.subscribe(user => {
// this.friendIDs = user.friendIDs})
this.getFriendsNames()
this.getFriendsNames();
}
getFriendsNames() {
for(let id of this.friendIDs) {
let url = environment.graphQLUrl
let headers = new Headers();
for (const id of this.friendIDs) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.buildJson(id))
.subscribe(response => {this.readOutFriendsNames(id, response.json())})
.subscribe(response => {this.readOutFriendsNames(id, response.json()); });
}
}
readOutFriendsNames(pId: number, pResponse : any) {
this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name,pResponse.data.getUser.level ))
readOutFriendsNames(pId: number, pResponse: any) {
this.friends.push(new FriendInfo(pId, pResponse.data.getUser.name, pResponse.data.getUser.level ));
}
buildJson(pId: number): any {
@ -45,14 +45,14 @@ export class FriendsComponent implements OnInit {
level
}
}`, variables: {
userId: pId
}}
userId: pId
}};
return body
return body;
}
public showFriendProfile(pFriend: FriendInfo){
this.router.navigate(['profile/' + pFriend.id])
public showFriendProfile(pFriend: FriendInfo) {
this.router.navigate(['profile/' + pFriend.id]);
}
}

@ -7,7 +7,7 @@ import { GroupInfo } from 'src/app/models/groupinfo';
styleUrls: ['./groups.component.sass']
})
export class GroupsComponent implements OnInit {
groups: Array<GroupInfo> = [new GroupInfo(1,"Group 1",[]), new GroupInfo(1,"Group 2",[]), new GroupInfo(1,"Group 3",[]), new GroupInfo(1,"Group 4",[])]
groups: Array<GroupInfo> = [new GroupInfo(1, 'Group 1', []), new GroupInfo(1, 'Group 2', []), new GroupInfo(1, 'Group 3', []), new GroupInfo(1, 'Group 4', [])];
constructor() { }
ngOnInit() {

@ -4,7 +4,7 @@ import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
const uri = 'https://o5x5jzoo7z.sse.codesandbox.io/graphql';
//'https://greenvironment.net/graphql:443'; // <-- add the URL of the GraphQL server here
// 'https://greenvironment.net/graphql:443'; // <-- add the URL of the GraphQL server here
export function createApollo(httpLink: HttpLink) {
return {
link: httpLink.create({uri}),

@ -1,23 +1,23 @@
export interface Action {
id: number
id: number;
name: string;
points: number;
}
export class Actionlist{
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 },
{ 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 },
];
}
}

@ -1,11 +1,11 @@
export class Author {
id: number
name: string
handle: string
id: number;
name: string;
handle: string;
constructor(pId: number, pName: string, pHandle: string) {
this.id = pId
this.name = pName
this.handle = pHandle
this.id = pId;
this.name = pName;
this.handle = pHandle;
}
}
}

@ -1,16 +1,16 @@
import { Chatmessage } from "./chatmessage"
import { Chatmessage } from './chatmessage';
export class Chat {
id: number
memberID: number
memberName: string
messages: Array<Chatmessage>
id: number;
memberID: number;
memberName: string;
messages: Array<Chatmessage>;
constructor(pId: number, pMemberID: number, pMemberName: string, pMessages: Array<Chatmessage>) {
this.id = pId
this.memberID = pMemberID
this.memberName = pMemberName
this.messages = pMessages
this.id = pId;
this.memberID = pMemberID;
this.memberName = pMemberName;
this.messages = pMessages;
}
}
}

@ -3,7 +3,7 @@ export class Chatinfo {
date: string;
constructor(pId: string, pDate: string) {
this.id = pId
this.date = pDate
this.id = pId;
this.date = pDate;
}
}
}

@ -1,11 +1,11 @@
export class Chatmessage {
content: string
date: string
myself: boolean
content: string;
date: string;
myself: boolean;
constructor(pContent: string, pDate: string, pMyself: boolean) {
this.content = pContent
this.date = pDate
this.myself = pMyself
this.content = pContent;
this.date = pDate;
this.myself = pMyself;
}
}
}

@ -2,13 +2,13 @@ import { Levellist } from 'src/app/models/levellist';
export class FriendInfo {
levellist: Levellist = new Levellist();
id: number
name: string
rankname: string
id: number;
name: string;
rankname: string;
constructor(pId: number, pName: string, pLevel: number) {
this.id = pId
this.name = pName
this.id = pId;
this.name = pName;
this.rankname = this.levellist.getLevelName(pLevel);
}
}
}

@ -1,11 +1,11 @@
export class GroupInfo {
id: number
name: string
members: number[]
id: number;
name: string;
members: number[];
constructor(pId: number, pName: string, pMembers: number[]) {
this.id = pId
this.name = pName
this.members = pMembers
this.id = pId;
this.name = pName;
this.members = pMembers;
}
}
}

@ -1,22 +1,22 @@
export class Levellist{
export class Levellist {
levels: {level: number, name: string, points: number}[] = [
{level: 0, name: "Green Horn",points: 0},
{level: 1, name: "Good Willed",points: 100 },
{level: 2, name: "Helper", points: 200 },
{level: 3, name: "World Saver", points: 300 },
{level: 4, name: "Hero of the Green Country", points: 400 },
{level: 5, name: "Champion of the Earth", points: 500 },
{level: 6, name: "Intergallactic Superhero", points: 600 },
{level: 0, name: 'Green Horn', points: 0},
{level: 1, name: 'Good Willed', points: 100 },
{level: 2, name: 'Helper', points: 200 },
{level: 3, name: 'World Saver', points: 300 },
{level: 4, name: 'Hero of the Green Country', points: 400 },
{level: 5, name: 'Champion of the Earth', points: 500 },
{level: 6, name: 'Intergallactic Superhero', points: 600 },
];
getLevelName(lev:number): any{
var name: string = 'not defined';
getLevelName(lev: number): any {
let name = 'not defined';
this.levels.forEach(rank => {
if(lev == rank.level){
if (lev == rank.level) {
name = rank.name;
}
}
});
return name
return name;
}
}
}

@ -1,6 +1,6 @@
import { Hash } from "crypto";
import { Hash } from 'crypto';
export interface Login {
email: string;
passwordHash: string
}
passwordHash: string;
}

@ -1,23 +1,23 @@
import { Author } from "./author"
import { Author } from './author';
export class Post {
id: number
content: string
htmlContent: string
date: string
upvotes: number
downvotes: number
userVote: string
author: Author
id: number;
content: string;
htmlContent: string;
date: string;
upvotes: number;
downvotes: number;
userVote: string;
author: Author;
constructor(pId: number, pContent: string, pHtmlContent: string, pUpvotes: number, pDownvotes: number, pUserVote: string, pDate: string, pAuthor: Author) {
this.id = pId
this.content = pContent
this.htmlContent = pHtmlContent
this.upvotes = pUpvotes
this.downvotes = pDownvotes
this.userVote = pUserVote
this.date = pDate
this.author = pAuthor
this.id = pId;
this.content = pContent;
this.htmlContent = pHtmlContent;
this.upvotes = pUpvotes;
this.downvotes = pDownvotes;
this.userVote = pUserVote;
this.date = pDate;
this.author = pAuthor;
}
}
}

@ -1,5 +1,5 @@
export interface Registration {
username: string;
email: string;
passwordHash: string
}
passwordHash: string;
}

@ -1,15 +1,15 @@
export class User {
loggedIn : boolean
userID : number
username : string
handle : string
email : string
points : number
level : number
friendIDs : number[]
groupIDs : number[]
chatIDs : number[]
requestIDs : number[]
}
constructor(
public userID: number,
public loggedIn: boolean,
public username: string,
public handle: string,
public email: string,
public points: number,
public level: number,
public friendIDs: number[],
public groupIDs: number[],
public chatIDs: number[],
public requestIDs: number[],
) {}
}

@ -12,212 +12,211 @@ import { environment } from 'src/environments/environment';
})
export class ChatService {
arr: number[]
ownID: number
chats: Array<Chat> = []
arr: number[];
ownID: number;
chats: Array<Chat> = [];
constructor(private http: Http, private data: DatasharingService) {
this.data.currentUserInfo.subscribe(user => {
this.ownID = user.userID})
this.ownID = user.userID; });
}
public getAllChats(): Array<Chat> {
console.log("Getting all chats ..")
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
console.log('Getting all chats ..');
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetAllChats())
.subscribe(response => {
this.chats = this.renderAllChats(response.json())
this.chats = this.renderAllChats(response.json());
});
return this.chats
return this.chats;
}
public getAllChatsRaw(): any {
console.log("Getting all chats ..")
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForGetAllChats())
console.log('Getting all chats ..');
const url = 'https://greenvironment.net/graphql';
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetAllChats());
}
public getChatsByID(pChatIDs: number[]): Array<Chat> {
this.chats = []
console.log("Getting chats by ID..")
this.chats = [];
console.log('Getting chats by ID..');
for (const chatId of pChatIDs) {
const url = environment.graphQLUrl;
for(let chatId of pChatIDs) {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetChatsByID(chatId))
.subscribe(response => {
this.updateChat(response.json())
})
this.updateChat(response.json());
});
}
return this.chats
return this.chats;
}
public getChatsByIDRaw(pChatIDs: number[]): any {
console.log("Getting chats by ID..")
console.log('Getting chats by ID..');
for(let chatId of pChatIDs) {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
for (const chatId of pChatIDs) {
const url = 'https://greenvironment.net/graphql';
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetChatsByID(chatId))
.subscribe(response => {
this.updateChat(response.json())
})
this.updateChat(response.json());
});
}
return this.chats
return this.chats;
}
public createNewChat(pUserID: number) {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForNewChat(pUserID))
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForNewChat(pUserID));
}
public requestAllChatPartners(): Array<FriendInfo> {
let url = environment.graphQLUrl
let chatPartners: Array<FriendInfo>
let temp
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const url = environment.graphQLUrl;
let chatPartners: Array<FriendInfo>;
let temp;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForRequestOfAllChatPartners())
.subscribe(response => {
temp = response.json()
})
for(let chat of temp.data.getSelf.chats) {
let memberID: number
let memberName: string
let memberLevel: number
for(let member of chat.members) {
if(member.id != this.ownID) {
memberID = member.id
memberName = member.name
memberLevel = member.level
temp = response.json();
});
for (const chat of temp.data.getSelf.chats) {
let memberID: number;
let memberName: string;
let memberLevel: number;
for (const member of chat.members) {
if (member.id != this.ownID) {
memberID = member.id;
memberName = member.name;
memberLevel = member.level;
}
}
chatPartners.push(new FriendInfo(memberID, memberName, memberLevel))
chatPartners.push(new FriendInfo(memberID, memberName, memberLevel));
}
return chatPartners
return chatPartners;
}
public sendMessage(pChatID: number, pContent: string): any {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent))
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent));
}
public getMessages(pChatID): Array<Chatmessage> {
let messages: Array<Chatmessage>
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response =>
{
console.log("Downloading messages ...")
messages = this.renderMessages(response.json())
})
return messages
let messages: Array<Chatmessage>;
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response => {
console.log('Downloading messages ...');
messages = this.renderMessages(response.json());
});
return messages;
}
public getMessagesRaw(pChatID): any {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID))
const url = 'https://greenvironment.net/graphql';
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID));
}
public renderMessages(pResponse: any): Array<Chatmessage> {
let messages = new Array<Chatmessage>()
for(let message of pResponse.data.getChat.messages) {
if(message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true))
const messages = new Array<Chatmessage>();
for (const message of pResponse.data.getChat.messages) {
if (message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true));
} else {
messages.push(new Chatmessage(message.content, message.createdAt, false))
messages.push(new Chatmessage(message.content, message.createdAt, false));
}
}
return messages
return messages;
}
public renderAllChats(pResponse: any): Array<Chat> {
let chats = Array<Chat>()
for(let chat of pResponse.data.getSelf.chats) {
let memberID: number
let memberName: string
for(let member of chat.members) {
if(member.id != this.ownID) {
memberID = member.id
memberName = member.name
const chats = Array<Chat>();
for (const chat of pResponse.data.getSelf.chats) {
let memberID: number;
let memberName: string;
for (const member of chat.members) {
if (member.id != this.ownID) {
memberID = member.id;
memberName = member.name;
}
}
let messages = new Array<Chatmessage>()
for(let message of chat.messages) {
if(message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true))
const messages = new Array<Chatmessage>();
for (const message of chat.messages) {
if (message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true));
} else {
messages.push(new Chatmessage(message.content, message.createdAt, false))
messages.push(new Chatmessage(message.content, message.createdAt, false));
}
}
chats.push(new Chat(chat.id, memberID, memberName, messages))
chats.push(new Chat(chat.id, memberID, memberName, messages));
}
return chats
return chats;
}
updateChat(pResponse: any) {
let id = pResponse.data.getChat.id
let memberId : number
let memberName: string
for(let member of pResponse.data.getChat.members) {
if(member.id != this.ownID) {
memberId = member.id
memberName = member.name
const id = pResponse.data.getChat.id;
let memberId: number;
let memberName: string;
for (const member of pResponse.data.getChat.members) {
if (member.id != this.ownID) {
memberId = member.id;
memberName = member.name;
}
}
let messages = new Array<Chatmessage>()
for(let message of pResponse.data.getChat.messages) {
if(message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true))
const messages = new Array<Chatmessage>();
for (const message of pResponse.data.getChat.messages) {
if (message.author.id == this.ownID) {
messages.push(new Chatmessage(message.content, message.createdAt, true));
} else {
messages.push(new Chatmessage(message.content, message.createdAt, false))
messages.push(new Chatmessage(message.content, message.createdAt, false));
}
}
this.chats.push(new Chat(id, memberId, memberName, messages))
this.chats.push(new Chat(id, memberId, memberName, messages));
}
getBodyForNewChat(pUserID: number) {
this.arr = [pUserID]
this.arr = [pUserID];
const body = {query: `mutation($userID: number[]) {
createChat(members: $userID) {id}
createChat(members: $userID) {id}
}`, variables: {
members: this.arr
}};
return body
return body;
}
getBodyForRequestOfAllChatPartners() {
@ -225,46 +224,46 @@ export class ChatService {
getSelf {
chats(first: 1000, offset: 0) {members{name, id, level}}
}}`
}
};
return body
return body;
}
getBodyForSendMessage(pchatID: number, pContent: string) {
const body = {query: `mutation($chatId: ID!, $content: String!) {
sendMessage(chatId: $chatId, content: $content) {id}
sendMessage(chatId: $chatId, content: $content) {id}
}`, variables: {
chatId: pchatID,
content: pContent
}};
return body
return body;
}
getBodyForGetAllChats() {
const body = {query: `query {
getSelf {
chats(first: 1000, offset: 0) {
id, members{name, id, level},
id, members{name, id, level},
messages(first: 1000, offset: 0) {
author {id}, createdAt, content
}
}
}
}`
}
return body
};
return body;
}
getBodyForGetChatsByID(pChatID: number) {
const body = {query: `query($chatID: ID!) {
getChat(chatId: $chatID) {id, members{name, id, level},
getChat(chatId: $chatID) {id, members{name, id, level},
messages(first: 1000, offset: 0) {author {id}, createdAt, content}}
}
}`, variables: {
chatId: pChatID
}}
return body
}};
return body;
}
getBodyForGetMessagesInChat(pChatID: number) {
@ -274,7 +273,7 @@ export class ChatService {
}
}`, variables: {
chatId: pChatID
}}
return body
}};
return body;
}
}

@ -7,18 +7,18 @@ import { User } from '../models/user';
})
export class DatasharingService {
private userInfoSource = new BehaviorSubject<User>(new User())
private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>())
currentUserInfo = this.userInfoSource.asObservable()
currentChatIDs = this.chatIDsSource.asObservable()
private userInfoSource = new BehaviorSubject<User>(new User());
private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>());
currentUserInfo = this.userInfoSource.asObservable();
currentChatIDs = this.chatIDsSource.asObservable();
constructor() { }
changeUserInfo(pUserInfo: User) {
this.userInfoSource.next(pUserInfo)
this.userInfoSource.next(pUserInfo);
}
changeChatIDs(pChatIDs: number[]) {
this.chatIDsSource.next(pChatIDs)
this.chatIDsSource.next(pChatIDs);
}
}

@ -9,117 +9,117 @@ import { environment } from 'src/environments/environment';
})
export class FeedService {
posts: Array<Post>
posts: Array<Post>;
constructor(private http: Http) { }
public createPost(pContent: String){
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
public createPost(pContent: String) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($content: String!) {
createPost(content: $content) {id}
}`, variables: {
content: pContent
}}
}};
this.http.post(url, body).subscribe(response => {
console.log(response.text())})
console.log(response.text()); });
}
public createPost2(pContent: String){
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
public createPost2(pContent: String) {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `query{
getSelf {name}
}`}
}`};
this.http.post(url, body).subscribe(response => {
console.log(response.text())})
console.log(response.text()); });
}
public upvote(pPostID: number): any {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) {
vote(postId: $postId, type: UPVOTE)
}`, variables: {
postId: pPostID
}}
return this.http.post(url, body)
}};
return this.http.post(url, body);
}
public downvote(pPostID: number): any {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) {
vote(postId: $postId, type: DOWNVOTE)
}`, variables: {
postId: pPostID
}}
return this.http.post(url, body)
}};
return this.http.post(url, body);
}
public getAllPosts(): Array<Post> {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
this.http.post(url, this.getBodyForGetAllPosts())
.subscribe(response => {
this.posts = this.renderAllPosts(response.json())
console.log(response)
this.posts = this.renderAllPosts(response.json());
console.log(response);
});
return this.posts
return this.posts;
}
public getAllPostsRaw(): any {
let url = environment.graphQLUrl
let headers = new Headers()
headers.set('Content-Type', 'application/json')
return this.http.post(url, this.getBodyForGetAllPosts())
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.getBodyForGetAllPosts());
}
getBodyForGetAllPosts() {
const body = {query: `query {
getPosts (first: 1000, offset: 0) {id, content, htmlContent, upvotes, downvotes, userVote, author{name, handle, id}, createdAt}
}`
}
};
return body
return body;
}
public renderAllPosts(pResponse: any): Array<Post> {
let posts = new Array<Post>()
//let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' }
for(let post of pResponse.data.getPosts) {
let id: number = post.id
let content: string = post.content
let htmlContent: string = post.htmlContent
let upvotes: number = post.upvotes
let downvotes: number = post.downvotes
let userVote: string = post.userVote
let author = new Author(post.author.id, post.author.name, post.author.handle)
let temp = new Date(Number(post.createdAt))
let date = temp.toLocaleString("en-GB")
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author))
const posts = new Array<Post>();
// let options = {year: 'numeric', month: 'short', day: 'numeric', hour: '' }
for (const post of pResponse.data.getPosts) {
const id: number = post.id;
const content: string = post.content;
const htmlContent: string = post.htmlContent;
const upvotes: number = post.upvotes;
const downvotes: number = post.downvotes;
const userVote: string = post.userVote;
const author = new Author(post.author.id, post.author.name, post.author.handle);
const temp = new Date(Number(post.createdAt));
const date = temp.toLocaleString('en-GB');
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, userVote, date, author));
}
return posts
return posts;
}
}

@ -1,66 +1,83 @@
import { Injectable, EventEmitter, Output } from '@angular/core';
import {Http, URLSearchParams, Headers} from '@angular/http';
import { Login } from '../../models/login';
import { User } from 'src/app/models/user';
import { DatasharingService } from '../datasharing.service';
import { userInfo } from 'os';
import {Injectable} from '@angular/core';
import {Headers, Http} from '@angular/http';
import {Login} from '../../models/login';
import {User} from 'src/app/models/user';
import {DatasharingService} from '../datasharing.service';
import {Router} from '@angular/router';
import { environment } from 'src/environments/environment';
import {environment} from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class LoginService {
constructor(private http: Http, private data: DatasharingService,private router: Router) { }
constructor(private http: Http, private data: DatasharingService, private router: Router) {
}
public login(login: Login, errorCb: any) {
public login(login : Login, errorCb: any) {
//let url = './graphql'
let url = environment.graphQLUrl
let headers = new Headers();
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson(login))
return this.http.post(environment.graphQLUrl, this.buildJson(login))
.subscribe(response => {
console.log(response.text());
this.loginSuccess();
this.updateUserInfo(response.json())
}, errorCb
console.log(response.text());
this.loginSuccess();
this.updateUserInfo(response.json());
}, errorCb
);
}
public loginSuccess(){
public loginSuccess() {
console.log('alles supi dupi');
//do routing
this.router.navigateByUrl('');
this.router.navigateByUrl('');
}
public updateUserInfo(response : any){
const user: User = new User();
user.loggedIn = true;
user.userID = response.data.login.id;
user.username = response.data.login.name;
user.handle = response.data.login.handle;
user.email = response.data.login.email;
user.points = response.data.login.points;
user.level = response.data.login.level;
user.friendIDs = response.data.login.friends;
user.groupIDs = response.data.login.groups;
user.chatIDs = response.data.login.chats;
user.requestIDs = response.data.login.requests;
public updateUserInfo(response: any) {
const loginData = response.data.login;
const user: User = new User(
loginData.login.id,
true,
loginData.name,
loginData.handle,
loginData.email,
loginData.points,
loginData.level,
loginData.friends,
loginData.groups,
loginData.chats,
loginData.requests,
);
this.data.changeUserInfo(user)
this.data.changeUserInfo(user);
}
public buildJson(login: Login): any {
const body = {query: `mutation($email: String, $pwHash: String) {
login(email: $email, passwordHash: $pwHash) {id, name,email, handle, points, level, friends{id}, groups{id},chats{id}}
}`, variables: {
const body = {
query: `mutation($email: String, $pwHash: String) {
login(email: $email, passwordHash: $pwHash) {
id,
name,
email,
handle,
points,
level,
friends {
id
},
groups {
id
},
chats{
id
}
}
}`
, variables: {
email: login.email,
pwHash: login.passwordHash,
}};
}
};
return body;
}
}//add ,receivedRequests{id} later
}

@ -11,32 +11,32 @@ import { environment } from 'src/environments/environment';
})
export class RegisterService {
constructor(private http: Http, private data: DatasharingService,private router: Router) { }
constructor(private http: Http, private data: DatasharingService, private router: Router) { }
public register(registration: Registration, errorCb: any) {
//let url = './graphql'
let url = environment.graphQLUrl
let headers = new Headers();
// let url = './graphql'
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson(registration))
.subscribe(response => {
console.log(response.text());
this.registerSuccess();
this.updateUserInfo(response.json())
this.updateUserInfo(response.json());
}, errorCb
);
}
public registerSuccess(){
public registerSuccess() {
console.log('alles supi dupi');
//do routing
// do routing
this.router.navigateByUrl('');
}
public updateUserInfo(response : any){
public updateUserInfo(response: any) {
const user: User = new User();
user.loggedIn = true;
user.userID = response.data.register.id;
@ -50,13 +50,13 @@ export class RegisterService {
user.chatIDs = response.data.register.chats;
user.requestIDs = response.data.register.requests;
this.data.changeUserInfo(user)
this.data.changeUserInfo(user);
}
public buildJson(registration: Registration): any {
const body = {query: `mutation($username: String, $email: String, $pwHash: String) {
register(username: $username, email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}}
register(username: $username, email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}}
}`, variables: {
email: registration.email,
pwHash: registration.passwordHash,

@ -12,36 +12,36 @@ import { environment } from 'src/environments/environment';
})
export class SelfService {
constructor(private http: Http, private data: DatasharingService,private router: Router) { }
constructor(private http: Http, private data: DatasharingService, private router: Router) { }
public checkIfLoggedIn() {
console.log('check if logged in...');
let url = environment.graphQLUrl;
let headers = new Headers();
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, this.buildJson())
.subscribe(response => {
console.log(response.text());
this.stillLoggedIn();
this.updateUserInfo(response.json())
this.updateUserInfo(response.json());
}, error => {
this.notLoggedIn()
console.log(error.text())
this.notLoggedIn();
console.log(error.text());
}
);
}
public stillLoggedIn(){
public stillLoggedIn() {
console.log('user was logged in');
}
public notLoggedIn(){
public notLoggedIn() {
console.log('user was not logged in');
}
public updateUserInfo(response : any){
public updateUserInfo(response: any) {
const user: User = new User();
user.loggedIn = true;
user.userID = response.data.getSelf.id;
@ -55,14 +55,14 @@ export class SelfService {
user.chatIDs = response.data.getSelf.chats;
user.requestIDs = response.data.getSelf.requests;
this.data.changeUserInfo(user)
this.data.changeUserInfo(user);
}
public buildJson(): any {
const body = {query: `{
getSelf{id, name,email, handle, points, level, friends{id}, groups{id},chats{id}}
getSelf{id, name,email, handle, points, level, friends{id}, groups{id},chats{id}}
}`, variables: {
}};
return body;
}
}//add ,receivedRequests{id} later
}// add ,receivedRequests{id} later

@ -12,6 +12,9 @@
"element",
"app",
"kebab-case"
]
],
"indent": {
"options": "spaces"
}
}
}

@ -4,6 +4,7 @@
],
"rules": {
"arrow-return-shorthand": true,
"brace-style": "1tbs",
"callable-types": true,
"class-name": true,
"comment-format": [
@ -11,6 +12,7 @@
"check-space"
],
"curly": true,
"cyclomatic-complexity": true,
"deprecation": {
"severity": "warn"
},
@ -23,13 +25,15 @@
"import-spacing": true,
"indent": [
true,
"spaces"
"spaces",
4
],
"interface-over-type-literal": true,
"label-position": true,
"max-classes-per-file": true,
"max-line-length": [
true,
140
120
],
"member-access": false,
"member-ordering": [
@ -43,6 +47,7 @@
]
}
],
"new-parens": true,
"no-arg": true,
"no-bitwise": true,
"no-console": [
@ -74,6 +79,7 @@
"no-unnecessary-initializer": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-requires": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
@ -89,10 +95,7 @@
"single"
],
"radix": true,
"semicolon": [
true,
"always"
],
"semicolon": true,
"triple-equals": [
true,
"allow-null-check"
@ -121,6 +124,7 @@
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-internal-module": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,

Loading…
Cancel
Save