funky-framadate-front/src/app/core/services/mocking.service.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-05-01 19:10:17 +02:00
import { Injectable } from '@angular/core';
2020-05-05 18:17:12 +02:00
import { Choice } from '../models/choice.model';
2020-05-01 19:10:17 +02:00
import { Poll } from '../models/poll.model';
2020-05-05 18:17:12 +02:00
import { Question } from '../models/question.model';
2020-05-01 19:10:17 +02:00
import { User } from '../models/user.model';
import { PollService } from './poll.service';
import { UserService } from './user.service';
@Injectable({
providedIn: 'root',
})
export class MockingService {
2020-05-05 18:17:12 +02:00
private user: User;
public pollsDatabase: Poll[] = [];
2020-05-01 19:10:17 +02:00
2020-05-12 19:16:23 +02:00
private poll1: Poll = new Poll(this.user, 'Quand le picnic ?', 'Pour faire la teuf');
private poll2: Poll = new Poll(this.user, 'On fait quoi à la soirée ?', 'Balancez vos idées');
2020-05-01 19:10:17 +02:00
constructor(private userService: UserService, private pollService: PollService) {
2020-05-12 19:16:23 +02:00
this.poll1.choices = [new Choice('mardi prochain'), new Choice('mercredi')];
this.poll2.choices = [new Choice('jeux'), new Choice('danser'), new Choice('discuter en picolant')];
2020-05-01 19:10:17 +02:00
this.pollsDatabase = [this.poll1, this.poll2];
}
2020-05-05 18:17:12 +02:00
public loadUser(user: User): void {
this.user = user;
this.user.polls = this.pollsDatabase;
2020-05-01 19:10:17 +02:00
console.info('MOCKING user', { user: this.user });
this.userService.updateUser(this.user);
}
public loadPoll(slug: string): void {
2020-05-12 19:16:23 +02:00
this.poll1.slug = slug;
2020-05-05 18:17:12 +02:00
console.info('MOCKING poll', { poll: this.poll1 });
this.pollService.updateCurrentPoll(this.poll1);
2020-05-01 19:10:17 +02:00
}
}