Skip to content

Commit b054bd6

Browse files
committed
fix: check user correctly
1 parent dbfb0d3 commit b054bd6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

models/polls/poll.model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Model, model } from 'mongoose';
22
import { PollSchema, pollSchema } from './poll.schema';
3+
import { Types } from 'mongoose';
34

45
pollSchema.methods.vote = function(userId: string, which: 'left' | 'right'): PollSchema {
5-
const participants = ['left', 'right'].reduce((acc, option) => {
6+
const participants: Types.ObjectId[] = ['left', 'right'].reduce((acc, option) => {
67
const { votes } = this.contents[option];
78
return acc.concat(votes);
89
}, []);
910

10-
if (!participants.indexOf(userId) === -1) {
11+
if (!participants.some(user => user.equals(userId))) {
1112
this.contents[which].votes.push(userId);
1213
}
1314

0 commit comments

Comments
 (0)