-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ka.testcontainers
- Loading branch information
Showing
80 changed files
with
1,447 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Command, InvalidState } from '@hicommonwealth/core'; | ||
import * as schemas from '@hicommonwealth/schemas'; | ||
import moment from 'moment/moment'; | ||
import { models } from '../database'; | ||
import { authPoll } from '../middleware'; | ||
import { mustBeAuthorizedPoll } from '../middleware/guards'; | ||
|
||
export const CreateVotePollErrors = { | ||
InvalidOption: 'Invalid response option', | ||
PollingClosed: 'Polling already finished', | ||
}; | ||
|
||
export function CreatePollVote(): Command<typeof schemas.CreatePollVote> { | ||
return { | ||
...schemas.CreatePollVote, | ||
auth: [ | ||
authPoll({ | ||
action: 'UPDATE_POLL', | ||
}), | ||
], | ||
body: async ({ actor, payload, context }) => { | ||
const { poll, address } = mustBeAuthorizedPoll(actor, context); | ||
if ( | ||
!poll.ends_at && | ||
moment(poll.ends_at).utc().isBefore(moment().utc()) | ||
) { | ||
throw new InvalidState(CreateVotePollErrors.PollingClosed); | ||
} | ||
|
||
// TODO: migrate this to be JSONB array of strings in the DB | ||
const options = JSON.parse(poll.options); | ||
if (!options.includes(payload.option)) { | ||
throw new InvalidState(CreateVotePollErrors.InvalidOption); | ||
} | ||
|
||
return models.Vote.create({ | ||
poll_id: payload.poll_id, | ||
address: address.address, | ||
author_community_id: address.community_id, | ||
community_id: poll.community_id, | ||
option: payload.option, | ||
}); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './createPollVote.command'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.