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

hicommonwealth / commonwealth / 14799879024

02 May 2025 05:10PM UTC coverage: 44.434% (-0.7%) from 45.12%
14799879024

push

github

web-flow
Merge pull request #12024 from hicommonwealth/rotorsoft/9823-replace-moment-libs

Replace moment in libs, fixex tests

1663 of 4120 branches covered (40.36%)

Branch coverage included in aggregate %.

6 of 9 new or added lines in 4 files covered. (66.67%)

49 existing lines in 6 files now uncovered.

3027 of 6435 relevant lines covered (47.04%)

39.03 hits per line

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

9.52
/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

9
dayjs.extend(utc);
33✔
10

11
export const CreateVotePollErrors = {
33✔
12
  InvalidOption: 'Invalid response option',
13
  PollingClosed: 'Polling already finished',
14
};
15

16
export function CreatePollVote(): Command<typeof schemas.CreatePollVote> {
17
  return {
×
18
    ...schemas.CreatePollVote,
19
    auth: [
20
      authPoll({
21
        action: 'UPDATE_POLL',
22
      }),
23
    ],
24
    body: async ({ actor, payload, context }) => {
25
      const { poll, address } = mustBeAuthorizedPoll(actor, context);
×
NEW
26
      if (!poll.ends_at && dayjs(poll.ends_at).utc().isBefore(dayjs().utc())) {
×
UNCOV
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
38
      let vote = await models.Vote.findOne({
×
39
        where: {
40
          poll_id: payload.poll_id,
41
          address: address.address,
42
        },
43
      });
44
      if (!vote) {
×
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

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