diff options
-rw-r--r-- | models/polls/poll.schema.ts | 7 | ||||
-rw-r--r-- | services/votes/votes.class.ts | 14 | ||||
-rw-r--r-- | services/votes/votes.service.ts | 9 |
3 files changed, 6 insertions, 24 deletions
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts index 2f39aa1..4d1d762 100644 --- a/models/polls/poll.schema.ts +++ b/models/polls/poll.schema.ts @@ -2,7 +2,6 @@ import { Document, Schema, Types } from 'mongoose'; export interface ImageDataSchema { url: string; - votes: string[]; } export interface PollSchema extends Document { @@ -17,12 +16,6 @@ export interface PollSchema extends Document { export const imageDataSchema = { url: String, - votes: [ - { - type: Types.ObjectId, - ref: 'vote' - } - ] }; export const pollSchema = new Schema({ diff --git a/services/votes/votes.class.ts b/services/votes/votes.class.ts deleted file mode 100644 index 3220ee7..0000000 --- a/services/votes/votes.class.ts +++ /dev/null @@ -1,14 +0,0 @@ -import PollModel from '../../models/polls/poll.model'; -import { PollSchema } from '../../models/polls/poll.schema'; - -export default class Votes { - async create(data: any, params: any): Promise<PollSchema | null> { - const poll = await PollModel.findById(params.route.id); - if (poll) { - const updatedPoll = await poll.vote(params.user._id, data.which); - return updatedPoll.toObject(); - } - return null; - } -} - diff --git a/services/votes/votes.service.ts b/services/votes/votes.service.ts index 3947d9b..81f767c 100644 --- a/services/votes/votes.service.ts +++ b/services/votes/votes.service.ts @@ -1,10 +1,13 @@ import { Application } from '@feathersjs/express'; -import Votes from './votes.class'; +import service from 'feathers-mongoose'; +import Model from '../../models/votes/vote.model'; import hooks from './votes.hooks'; +const VoteService = service({ Model }); + export default (app: Application): void => { - app.use('/polls/:id/votes/', new Votes()); - app.service('/polls/:id/votes/').hooks(hooks); + app.use('/votes/', VoteService); + app.service('votes').hooks(hooks); }; |