aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/index.ts1
-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, 11 insertions, 62 deletions
diff --git a/services/index.ts b/services/index.ts
index eeaf485..441f9ad 100644
--- a/services/index.ts
+++ b/services/index.ts
@@ -1,3 +1,4 @@
+import { Application } from '@feathersjs/express';
import Users from './users/users.service';
import Polls from './polls/polls.service';
diff --git a/services/polls/polls.class.ts b/services/polls/polls.class.ts
deleted file mode 100644
index 82ef155..0000000
--- a/services/polls/polls.class.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-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
index a4bd816..ca75d5a 100644
--- a/services/polls/polls.service.ts
+++ b/services/polls/polls.service.ts
@@ -1,7 +1,10 @@
import { Application } from '@feathersjs/express';
-import Polls from './polls.class';
+import Model from '../../models/polls/poll.model';
+import service from 'feathers-mongoose';
+
+const PollService = service({ Model });
export default (app: Application): void => {
- app.use('/polls', new Polls());
+ app.use('/polls', PollService);
};
diff --git a/services/users/users.class.ts b/services/users/users.class.ts
deleted file mode 100644
index db6b5a9..0000000
--- a/services/users/users.class.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-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
index bf608fe..47dac3d 100644
--- a/services/users/users.service.ts
+++ b/services/users/users.service.ts
@@ -1,7 +1,10 @@
import { Application } from '@feathersjs/express';
-import Users from './users.class';
+import Model from '../../models/users/user.model';
+import service from 'feathers-mongoose';
+
+const UserService = service({ Model });
export default (app: Application): void => {
- app.use('/users', new Users());
+ app.use('/users', UserService);
};