-
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 pull request #10013 from hicommonwealth/release/v1.7.4-x
Release/v1.7.4-4
- Loading branch information
Showing
24 changed files
with
260 additions
and
344 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { PollContext } from '@hicommonwealth/schemas'; | ||
import { z } from 'zod'; | ||
import { Vote } from '../entities/poll.schemas'; | ||
import { PG_INT } from '../utils'; | ||
|
||
export const CreatePollVote = { | ||
input: z.object({ | ||
thread_id: PG_INT, | ||
poll_id: z.number(), | ||
option: z.string(), | ||
}), | ||
output: Vote, | ||
context: PollContext, | ||
}; |
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,36 @@ | ||
import { z } from 'zod'; | ||
import { Community } from '../entities/community.schemas'; | ||
import { Thread } from '../entities/thread.schemas'; | ||
import { PG_INT } from '../utils'; | ||
|
||
const _vote = z.object({ | ||
id: PG_INT.optional(), | ||
poll_id: z.number(), | ||
option: z.string(), | ||
address: z.string(), | ||
author_community_id: z.string(), | ||
community_id: z.string(), | ||
created_at: z.coerce.date().optional(), | ||
updated_at: z.coerce.date().optional(), | ||
}); | ||
|
||
export const Poll = z.object({ | ||
id: PG_INT.optional(), | ||
community_id: z.string(), | ||
thread_id: z.number(), | ||
prompt: z.string(), | ||
options: z.string(), | ||
ends_at: z.coerce.date(), | ||
created_at: z.coerce.date().optional(), | ||
updated_at: z.coerce.date().optional(), | ||
|
||
// associations | ||
Thread: Thread.optional(), | ||
Community: Community.optional(), | ||
votes: _vote.optional(), | ||
}); | ||
|
||
export const Vote = _vote.extend({ | ||
// associations | ||
poll: Poll.optional(), | ||
}); |
Oops, something went wrong.