• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 14655113082

25 Apr 2025 01:39AM UTC coverage: 45.41% (-0.5%) from 45.902%
14655113082

Pull #11922

github

web-flow
Merge 5cbbe9b61 into 8f728a23c
Pull Request #11922: Thread Rankings

1645 of 4008 branches covered (41.04%)

Branch coverage included in aggregate %.

15 of 81 new or added lines in 15 files covered. (18.52%)

21 existing lines in 4 files now uncovered.

3020 of 6265 relevant lines covered (48.2%)

39.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.0
/libs/model/src/aggregates/poll/createPollVote.command.ts
1
import { Command, InvalidState } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import moment from 'moment/moment';
4
import { models } from '../../database';
5
import { authPoll } from '../../middleware';
6
import { mustBeAuthorizedPoll } from '../../middleware/guards';
7

8
export const CreateVotePollErrors = {
33✔
9
  InvalidOption: 'Invalid response option',
10
  PollingClosed: 'Polling already finished',
11
};
12

13
export function CreatePollVote(): Command<typeof schemas.CreatePollVote> {
14
  return {
×
15
    ...schemas.CreatePollVote,
16
    auth: [
17
      authPoll({
18
        action: 'UPDATE_POLL',
19
      }),
20
    ],
21
    body: async ({ actor, payload, context }) => {
22
      const { poll, address } = mustBeAuthorizedPoll(actor, context);
×
23
      if (
×
24
        !poll.ends_at &&
×
25
        moment(poll.ends_at).utc().isBefore(moment().utc())
26
      ) {
27
        throw new InvalidState(CreateVotePollErrors.PollingClosed);
×
28
      }
29

30
      // TODO: migrate this to be JSONB array of strings in the DB
31
      const options = JSON.parse(poll.options);
×
32
      if (!options.includes(payload.option)) {
×
33
        throw new InvalidState(CreateVotePollErrors.InvalidOption);
×
34
      }
35

36
      // findOrCreate doesn't work because `poll_id` and `option` not
37
      // optional in the Vote schema
UNCOV
38
      let vote = await models.Vote.findOne({
×
39
        where: {
40
          poll_id: payload.poll_id,
41
          address: address.address,
42
        },
43
      });
UNCOV
44
      if (!vote) {
×
UNCOV
45
        vote = await models.Vote.create({
×
46
          poll_id: payload.poll_id,
47
          address: address.address,
48
          author_community_id: address.community_id,
49
          community_id: poll.community_id,
50
          option: payload.option,
51
        });
52
      }
53

UNCOV
54
      return vote.toJSON();
×
55
    },
56
  };
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc