42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
|
|
import { Choice } from '../models/choice.model';
|
|
import { Poll } from '../models/poll.model';
|
|
import { User } from '../models/user.model';
|
|
import { PollService } from './poll.service';
|
|
import { UserService } from './user.service';
|
|
import { UuidService } from './uuid.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class MockingService {
|
|
private user: User;
|
|
public pollsDatabase: Poll[] = [];
|
|
|
|
private poll1: Poll = new Poll(this.user, undefined, 'Quand le picnic ?', 'Pour faire la teuf');
|
|
private poll2: Poll = new Poll(this.user, undefined, 'On fait quoi à la soirée ?', 'Balancez vos idées');
|
|
|
|
constructor(private userService: UserService, private pollService: PollService, private uuidService: UuidService) {
|
|
this.poll1.slug = this.uuidService.getUUID();
|
|
this.poll2.slug = this.uuidService.getUUID();
|
|
this.poll1.choices = [new Choice('mardi prochain'), new Choice('mercredi')];
|
|
this.poll2.choices = [new Choice('jeux'), new Choice('danser'), new Choice('discuter en picolant')];
|
|
|
|
this.pollsDatabase = [this.poll1, this.poll2];
|
|
}
|
|
|
|
public loadUser(user: User): void {
|
|
this.user = user;
|
|
this.user.polls = this.pollsDatabase;
|
|
console.info('MOCKING user', { user: this.user });
|
|
this.userService.updateUser(this.user);
|
|
}
|
|
|
|
public loadPoll(slug: string): void {
|
|
this.poll1.slug = slug;
|
|
console.info('MOCKING poll', { poll: this.poll1 });
|
|
this.pollService.updateCurrentPoll(this.poll1);
|
|
}
|
|
}
|