aboutsummaryrefslogtreecommitdiff
path: root/services/votes/votes.class.ts
blob: 6b9181b711f5f5fdfd656e4b40d8936c0e4274ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 which: 'left' | 'right' = data.which;
      const { user } = params;
      poll.contents[which].votes.push(user._id);
      poll.save();
      return poll.toObject();
    }
    return null;
  }
}