Fix Group creation, event join etc.

master
Trivernis 5 years ago
parent 510ec83e34
commit 161c3f2afd

@ -12,6 +12,7 @@
<input matInput #time type="time" placeholder="choose a time"> <input matInput #time type="time" placeholder="choose a time">
</mat-form-field> </mat-form-field>
</div> </div>
<mat-error *ngIf="errorOccurred">{{getErrorMessage()}}</mat-error>
<div mat-dialog-actions> <div mat-dialog-actions>
<button mat-button (click)="onNoClick()">Cancel</button> <button mat-button (click)="onNoClick()">Cancel</button>
<button mat-button cdkFocusInitial (click)="createEvent(name.value, date.value, time.value)">Create Event</button> <button mat-button cdkFocusInitial (click)="createEvent(name.value, date.value, time.value)">Create Event</button>

@ -1,5 +1,5 @@
import {Component, OnInit, ViewChild} from '@angular/core'; import {Component, OnInit, ViewChild} from '@angular/core';
import {NavigationEnd, Router} from '@angular/router'; import {Data, NavigationEnd, Router} from '@angular/router';
import {User} from 'src/app/models/user'; import {User} from 'src/app/models/user';
import {MatSort} from '@angular/material/sort'; import {MatSort} from '@angular/material/sort';
import {RequestService} from 'src/app/services/request/request.service'; import {RequestService} from 'src/app/services/request/request.service';
@ -17,11 +17,14 @@ import {DialogGroupFileUploadComponent} from './fileUpload/fileUpload.component'
}) })
export class DialogCreateEventComponent { export class DialogCreateEventComponent {
groupId: string; groupId: string;
private errorMessage: string;
errorOccurred: boolean;
constructor( constructor(
public dialogRef: MatDialogRef<DialogCreateEventComponent>, public dialogRef: MatDialogRef<DialogCreateEventComponent>,
private group: GroupService, private group: GroupService,
private router: Router) { private router: Router,
private datasharingService: DatasharingService) {
this.groupId = this.router.url.substr(this.router.url.lastIndexOf('/') + 1); this.groupId = this.router.url.substr(this.router.url.lastIndexOf('/') + 1);
} }
@ -29,15 +32,36 @@ export class DialogCreateEventComponent {
this.dialogRef.close(); this.dialogRef.close();
} }
/**
* Creates a new event
* @param name
* @param date
* @param time
*/
createEvent(name: string, date: string, time: string) { createEvent(name: string, date: string, time: string) {
name = name.trim(); name = name.trim();
this.errorOccurred = false;
if (name && date && time) { if (name && date && time) {
date = date + ' ' + time; date = date + ' ' + time;
this.group.createEvent(name, (new Date(date)).getTime().toString(), this.groupId); this.group.createEvent(name, (new Date(date)).getTime().toString(), this.groupId)
.subscribe(() => {
this.dialogRef.close(); this.dialogRef.close();
}, (error) => {
if (error.error) {
this.errorMessage = error.error.errors[0].message;
this.errorOccurred = true;
}
});
} }
} }
/**
* Returns the error message
*/
getErrorMessage(): string {
return this.errorMessage;
}
} }
// GROUP COMPONENT // GROUP COMPONENT
@ -132,14 +156,14 @@ export class GroupComponent implements OnInit {
public joinEvent(event: Event) { public joinEvent(event: Event) {
this.groupService.joinEvent(event.id).subscribe(response => { this.groupService.joinEvent(event.id).subscribe(response => {
const pEvent = response.json().data.joinEvent; const pEvent = response.data.joinEvent;
event.joined = pEvent.joined; event.joined = pEvent.joined;
}); });
} }
public leaveEvent(event: Event) { public leaveEvent(event: Event) {
this.groupService.leaveEvent(event.id).subscribe(response => { this.groupService.leaveEvent(event.id).subscribe(response => {
const pEvent = response.json().data.leaveEvent; const pEvent = response.data.leaveEvent;
event.joined = pEvent.joined; event.joined = pEvent.joined;
}); });
} }

@ -29,8 +29,8 @@ export class GroupService extends BaseService {
public group: BehaviorSubject<Group> = new BehaviorSubject(new Group()); public group: BehaviorSubject<Group> = new BehaviorSubject(new Group());
constructor(private http: HttpClient) { constructor(http: HttpClient) {
super(); super(http);
} }
/** /**
@ -70,8 +70,7 @@ export class GroupService extends BaseService {
} }
}; };
this.http.post(environment.graphQLUrl, body, {headers: this.headers}) return this.postGraphql(body, null, 0)
.pipe(this.retryRated())
.pipe(tap(response => { .pipe(tap(response => {
const event = new Event(); const event = new Event();
event.assignFromResponse(response.data.createEvent); event.assignFromResponse(response.data.createEvent);
@ -82,8 +81,6 @@ export class GroupService extends BaseService {
} }
public joinEvent(eventId: string) { public joinEvent(eventId: string) {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = { const body = {
query: `mutation($eventId: ID!) { query: `mutation($eventId: ID!) {
joinEvent(eventId: $eventId) { joinEvent(eventId: $eventId) {
@ -93,7 +90,7 @@ export class GroupService extends BaseService {
eventId: eventId eventId: eventId
} }
}; };
return this.http.post(environment.graphQLUrl, body, {headers: this.headers}) return this.postGraphql(body)
.pipe(this.retryRated()); .pipe(this.retryRated());
} }
@ -109,15 +106,13 @@ export class GroupService extends BaseService {
eventId: eventId eventId: eventId
} }
}; };
return this.http.post(environment.graphQLUrl, body, {headers: this.headers}) return this.postGraphql(body);
.pipe(this.retryRated());
} }
public changeProfilePicture(file: any, id: number) { public changeProfilePicture(file: any, id: number) {
const formData: any = new FormData(); const formData: any = new FormData();
formData.append('groupPicture', file); formData.append('groupPicture', file);
formData.append('groupId', id); formData.append('groupId', id);
return this.http.post<IFileUploadResult>(environment.greenvironmentUrl + '/upload', formData) return this.post<IFileUploadResult>(environment.greenvironmentUrl + '/upload', formData);
.pipe(this.retryRated());
} }
} }

Loading…
Cancel
Save