import { Injectable } from '@angular/core'; import { UserRole } from '../enums/user-role.enum'; import { Poll } from '../models/poll.model'; import { User } from '../models/user.model'; import { PollService } from './poll.service'; import { UserService } from './user.service'; @Injectable({ providedIn: 'root', }) export class MockingService { public pollsDatabase: Poll[]; private user: User = new User(UserRole.ANONYMOUS, false, 'toto', 'toto@gafam.com', []); private poll1: Poll = new Poll(false, 'mon super sondage', 'super description 1', 'super_slug_1', 'id1'); private poll2: Poll = new Poll(false, 'mon autre sondage', 'super description 2', 'super_slug_2', 'id2'); constructor(private userService: UserService, private pollService: PollService) { this.pollsDatabase = [this.poll1, this.poll2]; this.user.polls = this.pollsDatabase; } public loadUser(role: UserRole): void { this.user.role = role; console.info('MOCKING user', { user: this.user }); this.userService.updateUser(this.user); } public loadPoll(slug: string): void { const poll: Poll | undefined = this.pollsDatabase.find((poll: Poll) => poll.slug === slug); if (poll) { console.info('MOCKING poll', { poll }); this.pollService.updateCurrentPoll(poll); } } }