From e9d0438f6c02664c652a593c686564361fa0de6b Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 9 Jun 2020 14:16:15 +0300 Subject: refactor: structurize feathers app --- services/polls/polls.class.ts | 38 ++++++++++++++++++++++++++++++++++++++ services/polls/polls.service.ts | 7 +++++++ 2 files changed, 45 insertions(+) create mode 100644 services/polls/polls.class.ts create mode 100644 services/polls/polls.service.ts (limited to 'services/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) { + 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()); +}; + -- cgit v1.2.3