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">
</mat-form-field>
</div>
<mat-error *ngIf="errorOccurred">{{getErrorMessage()}}</mat-error>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">Cancel</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 {NavigationEnd, Router} from '@angular/router';
import {Data, NavigationEnd, Router} from '@angular/router';
import {User} from 'src/app/models/user';
import {MatSort} from '@angular/material/sort';
import {RequestService} from 'src/app/services/request/request.service';
@ -17,11 +17,14 @@ import {DialogGroupFileUploadComponent} from './fileUpload/fileUpload.component'
})
export class DialogCreateEventComponent {
groupId: string;
private errorMessage: string;
errorOccurred: boolean;
constructor(
public dialogRef: MatDialogRef<DialogCreateEventComponent>,
private group: GroupService,
private router: Router) {
private router: Router,
private datasharingService: DatasharingService) {
this.groupId = this.router.url.substr(this.router.url.lastIndexOf('/') + 1);
}
@ -29,15 +32,36 @@ export class DialogCreateEventComponent {
this.dialogRef.close();
}
/**
* Creates a new event
* @param name
* @param date
* @param time
*/
createEvent(name: string, date: string, time: string) {
name = name.trim();
this.errorOccurred = false;
if (name && 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();
}, (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
@ -132,14 +156,14 @@ export class GroupComponent implements OnInit {
public joinEvent(event: Event) {
this.groupService.joinEvent(event.id).subscribe(response => {
const pEvent = response.json().data.joinEvent;
const pEvent = response.data.joinEvent;
event.joined = pEvent.joined;
});
}
public leaveEvent(event: Event) {
this.groupService.leaveEvent(event.id).subscribe(response => {
const pEvent = response.json().data.leaveEvent;
const pEvent = response.data.leaveEvent;
event.joined = pEvent.joined;
});
}

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

Loading…
Cancel
Save