diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-09 13:49:51 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-09 13:49:51 +0300 |
commit | 24f0d8709fc5e90a92d9c3940e693f76cd653bf4 (patch) | |
tree | befd2d1309eb46584c47842a5866ad0c74b2c73b /services/PollService.ts | |
parent | 53c7ec8572d80c75828702b2a103269136785b4a (diff) | |
download | which-api-24f0d8709fc5e90a92d9c3940e693f76cd653bf4.tar.gz |
refactor: move services to separate folder
Diffstat (limited to 'services/PollService.ts')
-rw-r--r-- | services/PollService.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/services/PollService.ts b/services/PollService.ts new file mode 100644 index 0000000..2944af3 --- /dev/null +++ b/services/PollService.ts @@ -0,0 +1,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; + } +} + |