Commit f5816b02 authored by Christopher Fullarton's avatar Christopher Fullarton

Fixes joining of quizzes

parent fb63dbd1
Pipeline #34378 passed with stages
in 15 minutes and 28 seconds
......@@ -58,7 +58,7 @@ export class NicknameInputComponent implements OnInit, OnDestroy {
sessionStorage.setItem(StorageKey.QuizToken, token);
this.putMember(this.nickname, sessionStorage.getItem(StorageKey.CurrentMemberGroupName)).then(() => {
this.putMember(this.nickname).then(() => {
this.attendeeService.ownNick = this.nickname;
this.router.navigate(['/quiz', 'flow', 'lobby']);
}, data => {
......@@ -98,20 +98,20 @@ export class NicknameInputComponent implements OnInit, OnDestroy {
this._messageSubscriptions.forEach(sub => this.messageQueue.unsubscribe(sub));
}
private putMember(name, groupName): Promise<void> {
private putMember(name: string): Promise<void> {
return new Promise((resolve, reject) => {
this._messageSubscriptions.push(this.messageQueue.subscribe(MessageProtocol.Added, payload => {
this.attendeeService.addMember(payload.member);
resolve();
}));
this.memberApiService.putMember(new MemberEntity({
currentQuizName: this.quizService.quiz.name,
name,
groupName,
groupName: sessionStorage.getItem(StorageKey.CurrentMemberGroupName),
ticket: this.userService.casTicket,
})).subscribe(data => {
if (data.status === StatusProtocol.Success && data.step === MessageProtocol.Added) {
this._messageSubscriptions.push(this.messageQueue.subscribe(MessageProtocol.Added, payload => {
this.attendeeService.addMember(payload.member);
resolve();
}));
} else {
if (data.status !== StatusProtocol.Success || data.step !== MessageProtocol.Added) {
reject(data);
}
}, (error) => {
......
......@@ -67,26 +67,7 @@ export class NicknameSelectComponent implements OnInit, OnDestroy {
sessionStorage.setItem(StorageKey.QuizToken, token);
const promise = new Promise(async (resolve, reject) => {
this.memberApiService.putMember(new MemberEntity({
currentQuizName: this.quizService.quiz.name,
name: nickname,
groupName: sessionStorage.getItem(StorageKey.CurrentMemberGroupName),
ticket: this.userService.casTicket,
})).subscribe((data: IMessage) => {
if (data.status === StatusProtocol.Success && data.step === MessageProtocol.Added) {
this._messageSubscriptions.push(this.messageQueue.subscribe(MessageProtocol.Added, payload => {
this.attendeeService.addMember(payload.member);
resolve();
}));
} else {
reject();
}
}, () => {
reject();
});
});
promise.then(() => {
this.putMember(nickname).then(() => {
this.attendeeService.ownNick = nickname;
this.router.navigate(['/quiz', 'flow', 'lobby']);
}, (err) => {
......@@ -120,4 +101,29 @@ export class NicknameSelectComponent implements OnInit, OnDestroy {
this.footerBarService.footerElemBack.restoreClickCallback();
this._messageSubscriptions.forEach(sub => this.messageQueue.unsubscribe(sub));
}
private putMember(name: string): Promise<any> {
return new Promise(async (resolve, reject) => {
this._messageSubscriptions.push(this.messageQueue.subscribe(MessageProtocol.Added, payload => {
this.attendeeService.addMember(payload.member);
resolve();
}));
this.memberApiService.putMember(new MemberEntity({
currentQuizName: this.quizService.quiz.name,
name,
groupName: sessionStorage.getItem(StorageKey.CurrentMemberGroupName),
ticket: this.userService.casTicket,
})).subscribe((data: IMessage) => {
if (data.status !== StatusProtocol.Success || data.step !== MessageProtocol.Added) {
reject(data);
}
}, error => {
reject({
status: StatusProtocol.Failed,
payload: error,
});
});
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment