Skip to content
This repository has been archived by the owner on Aug 3, 2018. It is now read-only.

Commit

Permalink
fix(appointment): disallows booking of multiple appointments
Browse files Browse the repository at this point in the history
Fixes: #53
  • Loading branch information
Martin committed Aug 6, 2016
1 parent e8aca2d commit 47a2e63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/app/appointment/appointment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AppointmentComponent {
appointmentSocket;
rightBeforeAppointment: boolean = false;
loadedInitially: boolean = false;
userHasAppointment: boolean = false;

constructor(
public appointmentService: AppointmentService,
Expand All @@ -43,6 +44,7 @@ export class AppointmentComponent {
* Method for querying appointments
*/
loadAppointments(): void {
this.userHasAppointment = false;
this.appointmentService
.getAll()
.map(res => res.json())
Expand All @@ -53,7 +55,9 @@ export class AppointmentComponent {
// find current user and check if appointment is now
for (const appointment of res.appointments) {
if (!appointment.user) continue;
if (appointment.user._id !== this.getUserId()) continue;

this.userHasAppointment = true;
const format: string = appointment.hour < 1000 ? 'Hmm' : 'HHmm';

// show Hangouts Button 5 minutes before and after appointment time
Expand All @@ -62,10 +66,7 @@ export class AppointmentComponent {
const hourEnd = moment.utc('' + appointment.hour, format)
.add(5, 'minutes');

if (appointment.user._id === this.getUserId()
&& moment.utc() >= hourStart
&& moment.utc() <= hourEnd
) {
if (moment.utc() >= hourStart && moment.utc() <= hourEnd) {
this.activateHangoutsButton();
break;
}
Expand Down
10 changes: 8 additions & 2 deletions src/app/appointment/appointment.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h3>You can start the meeting via this button:</h3>
<span *ngIf="app.hour == hour && app.weekDay == day">
<a *ngIf="app.user && app.user._id !== getUserId()" class="taken-appointment">
<span class="appointment-username">{{ app.user.name }}</span>
<span class="appointment-taken">my</span>
<span class="appointment-taken">taken</span>
</a>
<a href="#"
*ngIf="app.user && app.user._id === getUserId()"
Expand All @@ -41,12 +41,18 @@ <h3>You can start the meeting via this button:</h3>
<span class="appointment-taken">my</span>
</a>
<a href="#"
*ngIf="!app.user"
*ngIf="!app.user && !userHasAppointment"
class="free-appointment"
(click)="toggleRegistration($event, app)"
>
free
</a>
<a
*ngIf="!app.user && userHasAppointment"
class="free-appointment"
>
free
</a>
</span>
</span>
</td>
Expand Down

0 comments on commit 47a2e63

Please sign in to comment.