aboutsummaryrefslogtreecommitdiff
path: root/services/PollService.ts
blob: 2944af3a9514e758bd3456bc407fa3816aa76ae3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
interface ImageData {
  url: string;
  votes: number;
}

interface User {
  name: string;
  avatarUrl: string;
}

export interface Poll {
  author: User;
  contents: {
    left: ImageData;
    right: ImageData;
  };
}

const defaultUser: User = {
  name: 'John Doe',
  avatarUrl: 'https://github.com/eug-vs.png'
};


export class PollService {
  polls: Poll[] = [];

  async find () {
    return this.polls;
  }

  async create (data: Pick<Poll, 'contents'>) {
    const poll: Poll = { ...data, author: defaultUser };
    this.polls.push(poll);
    return poll;
  }
}