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

hicommonwealth / commonwealth / 22329524614

23 Feb 2026 11:33PM UTC coverage: 38.204% (+0.03%) from 38.173%
22329524614

Pull #13194

github

web-flow
Merge 19ef2c5a5 into 6658c85df
Pull Request #13194: AI Completion Fixes

2110 of 6026 branches covered (35.01%)

Branch coverage included in aggregate %.

9 of 80 new or added lines in 3 files covered. (11.25%)

30 existing lines in 14 files now uncovered.

3752 of 9318 relevant lines covered (40.27%)

52.52 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
      let vote = await models.Vote.findOne({
×
48
        where: {
49
          poll_id: payload.poll_id,
50
          address: address.address,
51
        },
52
      });
53

54
      if (!vote) {
×
55
        vote = await models.Vote.create({
×
56
          poll_id: payload.poll_id,
57
          address: address.address,
58
          user_id: actor.user.id!,
59
          author_community_id: address.community_id,
60
          community_id: poll.community_id,
61
          calculated_voting_weight: calculated_voting_weight?.toString(),
62
          option: payload.option,
63
        });
64
      } else if (poll.allow_revotes) {
×
65
        vote.option = payload.option;
×
66
        vote.calculated_voting_weight = calculated_voting_weight?.toString();
×
67
        await vote.save();
×
68
      } else {
69
        throw new InvalidState('User has already voted in this poll');
×
70
      }
71

72
      return vote.toJSON();
×
73
    },
74
  };
75
}
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