mirror of
https://github.com/Wolvan/poll.horse.git
synced 2024-11-22 04:58:00 +01:00
Deduplicate entries
Duplicate entries were deduplicated during saving but not checked for when verifying for at least 2 options set. This lead to being able to have polls with only a single vote. Now deduplication is run at the start of the creation function.
This commit is contained in:
parent
cb0ec9dfa1
commit
39d14aff1c
1 changed files with 5 additions and 2 deletions
|
@ -70,8 +70,11 @@ export default async function init(router: Router, polls: Storage): Promise<void
|
||||||
multiSelect: boolean,
|
multiSelect: boolean,
|
||||||
captcha: boolean
|
captcha: boolean
|
||||||
}): Promise<Poll | string> {
|
}): Promise<Poll | string> {
|
||||||
if (!Array.isArray(pollData.options) || pollData.options.filter(i => i).length < 2)
|
if (!Array.isArray(pollData.options) || pollData.options
|
||||||
return "Options must be an array and have at least 2 entries";
|
.reduce((prev: string[], curr: string) => prev.concat(prev.includes(curr) ? "" : curr), [])
|
||||||
|
.filter(i => i).length < 2
|
||||||
|
)
|
||||||
|
return "Options must be an array and have at least 2 different entries";
|
||||||
if (pollData.options.filter(i => i).length > MAX_POLL_OPTIONS)
|
if (pollData.options.filter(i => i).length > MAX_POLL_OPTIONS)
|
||||||
return "Only " + MAX_POLL_OPTIONS + " options are allowed";
|
return "Only " + MAX_POLL_OPTIONS + " options are allowed";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue