aboutsummaryrefslogtreecommitdiff
path: root/services/PollService.ts
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-09 13:49:51 +0300
committereug-vs <eug-vs@keemail.me>2020-06-09 13:49:51 +0300
commit24f0d8709fc5e90a92d9c3940e693f76cd653bf4 (patch)
treebefd2d1309eb46584c47842a5866ad0c74b2c73b /services/PollService.ts
parent53c7ec8572d80c75828702b2a103269136785b4a (diff)
downloadwhich-api-24f0d8709fc5e90a92d9c3940e693f76cd653bf4.tar.gz
refactor: move services to separate folder
Diffstat (limited to 'services/PollService.ts')
-rw-r--r--services/PollService.ts38
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;
+ }
+}
+