aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-06-09 14:26:22 +0300
committerGitHub <noreply@github.com>2020-06-09 14:26:22 +0300
commitbd36aeb53d04a13167925ecd4d5d73ed2ad09914 (patch)
tree5bc0a1e78cf72c6e1ae48f5ee3954511748c81b1 /services
parentabe7c3220c40031b9adecf9b27ab7141b7d3f736 (diff)
parente9d0438f6c02664c652a593c686564361fa0de6b (diff)
downloadwhich-api-bd36aeb53d04a13167925ecd4d5d73ed2ad09914.tar.gz
Merge pull request #2 from eug-vs/refactor
Structurize feathers app
Diffstat (limited to 'services')
-rw-r--r--services/index.ts8
-rw-r--r--services/polls/polls.class.ts38
-rw-r--r--services/polls/polls.service.ts7
-rw-r--r--services/users/users.class.ts20
-rw-r--r--services/users/users.service.ts7
5 files changed, 80 insertions, 0 deletions
diff --git a/services/index.ts b/services/index.ts
new file mode 100644
index 0000000..eeaf485
--- /dev/null
+++ b/services/index.ts
@@ -0,0 +1,8 @@
+import Users from './users/users.service';
+import Polls from './polls/polls.service';
+
+export default (app: Application): void => {
+ app.configure(Users);
+ app.configure(Polls);
+};
+
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;
+ }
+}
+
diff --git a/services/polls/polls.service.ts b/services/polls/polls.service.ts
new file mode 100644
index 0000000..a4bd816
--- /dev/null
+++ b/services/polls/polls.service.ts
@@ -0,0 +1,7 @@
+import { Application } from '@feathersjs/express';
+import Polls from './polls.class';
+
+export default (app: Application): void => {
+ app.use('/polls', new Polls());
+};
+
diff --git a/services/users/users.class.ts b/services/users/users.class.ts
new file mode 100644
index 0000000..db6b5a9
--- /dev/null
+++ b/services/users/users.class.ts
@@ -0,0 +1,20 @@
+interface User {
+ name: string;
+ avatarUrl?: string;
+ age?: number;
+}
+
+export default class Users {
+ 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;
+ }
+}
+
diff --git a/services/users/users.service.ts b/services/users/users.service.ts
new file mode 100644
index 0000000..bf608fe
--- /dev/null
+++ b/services/users/users.service.ts
@@ -0,0 +1,7 @@
+import { Application } from '@feathersjs/express';
+import Users from './users.class';
+
+export default (app: Application): void => {
+ app.use('/users', new Users());
+};
+