aboutsummaryrefslogtreecommitdiff
path: root/services/polls/polls.class.ts
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-09 14:16:15 +0300
committereug-vs <eug-vs@keemail.me>2020-06-09 14:16:15 +0300
commite9d0438f6c02664c652a593c686564361fa0de6b (patch)
tree5bc0a1e78cf72c6e1ae48f5ee3954511748c81b1 /services/polls/polls.class.ts
parent24f0d8709fc5e90a92d9c3940e693f76cd653bf4 (diff)
downloadwhich-api-e9d0438f6c02664c652a593c686564361fa0de6b.tar.gz
refactor: structurize feathers app
Diffstat (limited to 'services/polls/polls.class.ts')
-rw-r--r--services/polls/polls.class.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/services/polls/polls.class.ts b/services/polls/polls.class.ts
new file mode 100644
index 0000000..82ef155
--- /dev/null
+++ b/services/polls/polls.class.ts
@@ -0,0 +1,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;
+ }
+}
+