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

hicommonwealth / commonwealth / 16226169862

11 Jul 2025 05:37PM UTC coverage: 39.752% (-0.2%) from 39.977%
16226169862

push

github

web-flow
Merge pull request #12611 from hicommonwealth/rotorsoft/12610-clean-self-imports

Clean self imports

1857 of 5042 branches covered (36.83%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

27 existing lines in 12 files now uncovered.

3269 of 7853 relevant lines covered (41.63%)

36.23 hits per line

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

0.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 dayjs from 'dayjs';
4
import utc from 'dayjs/plugin/utc';
5
import { models } from '../../database';
6
import { authPoll } from '../../middleware';
7
import { mustBeAuthorizedPoll } from '../../middleware/guards';
8
import { getVotingWeight } from '../../services/stakeHelper';
9

UNCOV
10
dayjs.extend(utc);
×
11

UNCOV
12
export const CreateVotePollErrors = {
×
13
  InvalidOption: 'Invalid response option',
14
  PollingClosed: 'Polling already finished',
15
};
16

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

31
      if (thread.archived_at) {
×
32
        throw new InvalidState('Cannot vote on an archived thread');
×
33
      }
34
      if (thread.locked_at) {
×
35
        throw new InvalidState('Cannot vote on a locked thread');
×
36
      }
37

38
      if (!poll.options.includes(payload.option)) {
×
39
        throw new InvalidState(CreateVotePollErrors.InvalidOption);
×
40
      }
41

42
      const calculated_voting_weight = await getVotingWeight(
×
43
        thread.topic_id,
44
        address.address,
45
      );
46

47
      // findOrCreate doesn't work because `poll_id` and `option` not
48
      // optional in the Vote schema
49
      let vote = await models.Vote.findOne({
×
50
        where: {
51
          poll_id: payload.poll_id,
52
          address: address.address,
53
        },
54
      });
55
      if (!vote) {
×
56
        vote = await models.Vote.create({
×
57
          poll_id: payload.poll_id,
58
          address: address.address,
59
          user_id: actor.user.id!,
60
          author_community_id: address.community_id,
61
          community_id: poll.community_id,
62
          calculated_voting_weight: calculated_voting_weight?.toString(),
63
          option: payload.option,
64
        });
65
      }
66

67
      return vote.toJSON();
×
68
    },
69
  };
70
}
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