diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-22 01:42:43 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-22 01:43:27 +0300 |
commit | 4909dda29566710793b8445ab4426102ca4a0324 (patch) | |
tree | d3bc9a565647c160b7464251f2688bd5455dd674 /services/votes/votes.class.ts | |
parent | e99b51895afd532a529744396ecae87d47c68503 (diff) | |
download | which-api-4909dda29566710793b8445ab4426102ca4a0324.tar.gz |
feat: create Votes service
Diffstat (limited to 'services/votes/votes.class.ts')
-rw-r--r-- | services/votes/votes.class.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/services/votes/votes.class.ts b/services/votes/votes.class.ts new file mode 100644 index 0000000..d95c148 --- /dev/null +++ b/services/votes/votes.class.ts @@ -0,0 +1,14 @@ +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> { + return PollModel.findById(params.route.id) + .then(poll => poll?.vote(params.user._id, data.which)) + .catch(e => { + console.error(e); + return null; + }); + } +} + |