Add validation for answers in Custom Polls
This commit is contained in:
parent
e304387206
commit
4726bdbc39
@ -1,4 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run this script as root ( or with sudo )" ;
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
for var in "$@"
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { RedisMessage } from '../types';
|
||||
import {throwErrorIfNotPresenter} from "../imports/validation";
|
||||
import {ValidationError} from "../types/ValidationError";
|
||||
|
||||
export default function buildRedisMessage(sessionVariables: Record<string, unknown>, input: Record<string, unknown>): RedisMessage {
|
||||
throwErrorIfNotPresenter(sessionVariables);
|
||||
@ -26,7 +27,13 @@ export default function buildRedisMessage(sessionVariables: Record<string, unkno
|
||||
};
|
||||
|
||||
if (input.pollType === 'CUSTOM') {
|
||||
//TODO Validate answers as it is required for custom and not required in Hasura
|
||||
if(!input.hasOwnProperty('answers')) {
|
||||
throw new ValidationError('Field `answers` is required for Custom polls.', 400);
|
||||
}
|
||||
|
||||
if(!Array.isArray(input.answers) || input.answers.length < 2) {
|
||||
throw new ValidationError('Field `answers` should contain at least two answers.', 400);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
body.answers = input.answers;
|
||||
|
Loading…
Reference in New Issue
Block a user