migrate publishTypedVote meteor call
This commit is contained in:
parent
573fa99bcd
commit
0ef2e8afea
@ -1,12 +1,10 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import publishTypedVote from './methods/publishTypedVote';
|
||||
import publishVote from './methods/publishVote';
|
||||
import startPoll from './methods/startPoll';
|
||||
import stopPoll from './methods/stopPoll';
|
||||
|
||||
Meteor.methods({
|
||||
publishVote,
|
||||
publishTypedVote,
|
||||
startPoll,
|
||||
stopPoll,
|
||||
});
|
||||
|
@ -1,79 +0,0 @@
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import { check } from 'meteor/check';
|
||||
import Polls from '/imports/api/polls';
|
||||
import { extractCredentials } from '/imports/api/common/server/helpers';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default async function publishTypedVote(id, pollAnswer) {
|
||||
const REDIS_CONFIG = Meteor.settings.private.redis;
|
||||
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
||||
const MAX_INPUT_CHARS = Meteor.settings.public.poll.maxTypedAnswerLength;
|
||||
let EVENT_NAME = 'RespondToTypedPollReqMsg';
|
||||
|
||||
try {
|
||||
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
||||
|
||||
check(meetingId, String);
|
||||
check(requesterUserId, String);
|
||||
check(pollAnswer, String);
|
||||
check(id, String);
|
||||
|
||||
const allowedToVote = await Polls.findOneAsync({
|
||||
id,
|
||||
users: { $in: [requesterUserId] },
|
||||
meetingId,
|
||||
}, {
|
||||
fields: {
|
||||
users: 1,
|
||||
},
|
||||
});
|
||||
|
||||
if (!allowedToVote) {
|
||||
Logger.info(`Poll User={${requesterUserId}} has already voted in PollId={${id}}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const activePoll = await Polls.findOneAsync({ meetingId, id }, {
|
||||
fields: {
|
||||
answers: 1,
|
||||
},
|
||||
});
|
||||
|
||||
let existingAnsId = null;
|
||||
activePoll.answers.forEach((a) => {
|
||||
if (a.key === pollAnswer) existingAnsId = a.id;
|
||||
});
|
||||
|
||||
if (existingAnsId !== null) {
|
||||
check(existingAnsId, Number);
|
||||
EVENT_NAME = 'RespondToPollReqMsg';
|
||||
|
||||
return RedisPubSub.publishUserMessage(
|
||||
CHANNEL,
|
||||
EVENT_NAME,
|
||||
meetingId,
|
||||
requesterUserId,
|
||||
{
|
||||
requesterId: requesterUserId,
|
||||
pollId: id,
|
||||
questionId: 0,
|
||||
answerIds: [existingAnsId],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const payload = {
|
||||
requesterId: requesterUserId,
|
||||
pollId: id,
|
||||
questionId: 0,
|
||||
answer: pollAnswer.substring(0, MAX_INPUT_CHARS),
|
||||
};
|
||||
|
||||
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
||||
} catch (err) {
|
||||
Logger.error(`Exception while invoking method publishTypedVote ${err.stack}`);
|
||||
}
|
||||
//In this case we return true because
|
||||
//lint asks for async functions to return some value.
|
||||
return true;
|
||||
}
|
@ -5,8 +5,19 @@ export const POLL_PUBLISH_RESULT = gql`
|
||||
pollPublishResult(
|
||||
pollId: $pollId,
|
||||
)
|
||||
}`;
|
||||
}
|
||||
`;
|
||||
|
||||
export const POLL_SUBMIT_TYPED_VOTE = gql`
|
||||
mutation PollSubmitTypedVote($pollId: String!, $answer: String!) {
|
||||
pollSubmitUserTypedVote(
|
||||
pollId: $pollId,
|
||||
answer: $answer,
|
||||
)
|
||||
}
|
||||
`;
|
||||
|
||||
export default {
|
||||
POLL_PUBLISH_RESULT,
|
||||
POLL_SUBMIT_TYPED_VOTE,
|
||||
};
|
||||
|
@ -1,11 +1,13 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withTracker } from 'meteor/react-meteor-data';
|
||||
import { useMutation } from '@apollo/client';
|
||||
import PollingService from './service';
|
||||
import PollService from '/imports/ui/components/poll/service';
|
||||
import PollingComponent from './component';
|
||||
import { isPollingEnabled } from '/imports/ui/services/features';
|
||||
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
||||
import { POLL_SUBMIT_TYPED_VOTE } from '/imports/ui/components/poll/mutations';
|
||||
|
||||
const propTypes = {
|
||||
pollExists: PropTypes.bool.isRequired,
|
||||
@ -17,9 +19,20 @@ const PollingContainer = ({ pollExists, ...props }) => {
|
||||
}));
|
||||
const showPolling = pollExists && !currentUserData?.presenter && isPollingEnabled();
|
||||
|
||||
const [pollSubmitUserTypedVote] = useMutation(POLL_SUBMIT_TYPED_VOTE);
|
||||
|
||||
const handleTypedVote = (pollId, answer) => {
|
||||
pollSubmitUserTypedVote({
|
||||
variables: {
|
||||
pollId,
|
||||
answer,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (showPolling) {
|
||||
return (
|
||||
<PollingComponent {...props} />
|
||||
<PollingComponent handleTypedVote={handleTypedVote} {...props} />
|
||||
);
|
||||
}
|
||||
return null;
|
||||
@ -29,7 +42,7 @@ PollingContainer.propTypes = propTypes;
|
||||
|
||||
export default withTracker(() => {
|
||||
const {
|
||||
pollExists, handleVote, poll, handleTypedVote,
|
||||
pollExists, handleVote, poll,
|
||||
} = PollingService.mapPolls();
|
||||
const { pollTypes } = PollService;
|
||||
|
||||
@ -41,7 +54,6 @@ export default withTracker(() => {
|
||||
return ({
|
||||
pollExists,
|
||||
handleVote,
|
||||
handleTypedVote,
|
||||
poll,
|
||||
pollAnswerIds: PollService.pollAnswerIds,
|
||||
pollTypes,
|
||||
|
@ -8,10 +8,6 @@ const handleVote = (pollId, answerIds) => {
|
||||
makeCall('publishVote', pollId, answerIds);
|
||||
};
|
||||
|
||||
const handleTypedVote = (pollId, answer) => {
|
||||
makeCall('publishTypedVote', pollId, answer);
|
||||
};
|
||||
|
||||
const mapPolls = () => {
|
||||
const poll = Polls.findOne({});
|
||||
if (!poll) {
|
||||
@ -44,7 +40,6 @@ const mapPolls = () => {
|
||||
pollExists: true,
|
||||
amIRequester,
|
||||
handleVote: debounce(handleVote, 500, { leading: true, trailing: false }),
|
||||
handleTypedVote: debounce(handleTypedVote, 500, { leading: true, trailing: false }),
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user