We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ef94c64 commit 967ee22Copy full SHA for 967ee22
services/votes/votes.class.ts
@@ -3,12 +3,14 @@ import { PollSchema } from '../../models/polls/poll.schema';
3
4
export default class Votes {
5
async create(data: any, params: any): Promise<PollSchema | null> {
6
- return PollModel.findById(params.route.id)
7
- .then(poll => poll?.vote(params.user._id, data.which))
8
- .catch(e => {
9
- console.error(e);
10
- return null;
11
- });
+ const poll = await PollModel.findById(params.route.id);
+ if (poll) {
+ const which: 'left' | 'right' = data.which;
+ const { user } = params;
+ poll.contents[which].votes.push(user._id);
+ return poll.save();
12
+ }
13
+ return null;
14
}
15
16
0 commit comments