aboutsummaryrefslogtreecommitdiff
path: root/services/polls/polls.class.ts
blob: 82ef15537652ffda93d03f126d108e312074dcd7 (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;
}

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

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


export default class Polls {
  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;
  }
}