diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/PollService.ts | 38 | ||||
-rw-r--r-- | services/UserService.ts | 20 |
2 files changed, 58 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; + } +} + diff --git a/services/UserService.ts b/services/UserService.ts new file mode 100644 index 0000000..57a883c --- /dev/null +++ b/services/UserService.ts @@ -0,0 +1,20 @@ +interface User { + name: string; + avatarUrl?: string; + age?: number; +} + +export class UserService { + users: User[] = []; + + async find (){ + return this.users; + } + + async create(data: Pick<User, 'name' | 'avatarUrl' | 'age'>){ + const user: User = { ...data }; + this.users.push(user); + return user; + } +} + |