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 dbfb0d3 commit b054bd6Copy full SHA for b054bd6
models/polls/poll.model.ts
@@ -1,13 +1,14 @@
1
import { Model, model } from 'mongoose';
2
import { PollSchema, pollSchema } from './poll.schema';
3
+import { Types } from 'mongoose';
4
5
pollSchema.methods.vote = function(userId: string, which: 'left' | 'right'): PollSchema {
- const participants = ['left', 'right'].reduce((acc, option) => {
6
+ const participants: Types.ObjectId[] = ['left', 'right'].reduce((acc, option) => {
7
const { votes } = this.contents[option];
8
return acc.concat(votes);
9
}, []);
10
- if (!participants.indexOf(userId) === -1) {
11
+ if (!participants.some(user => user.equals(userId))) {
12
this.contents[which].votes.push(userId);
13
}
14
0 commit comments