summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/create.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 08:56:07 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 08:56:07 +0900
commitdc45055f2ffcea2369f12d104999746220b22c90 (patch)
treed3ec8f4a03076fe804c906cd60656e197f3010f2 /src/api/endpoints/posts/create.ts
parentwip (diff)
downloadsharkey-dc45055f2ffcea2369f12d104999746220b22c90.tar.gz
sharkey-dc45055f2ffcea2369f12d104999746220b22c90.tar.bz2
sharkey-dc45055f2ffcea2369f12d104999746220b22c90.zip
wip
Diffstat (limited to 'src/api/endpoints/posts/create.ts')
-rw-r--r--src/api/endpoints/posts/create.ts19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 686c3a67d0..3dc121305c 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -131,21 +131,18 @@ module.exports = (params, user, app) =>
let poll = null;
if (_poll !== null) {
- const [pollChoices, pollChoicesErr] = it(params.poll, 'set', false, [
- choices => {
- const shouldReject = choices.some(choice => {
+ const [pollChoices, pollChoicesErr] =
+ it(params.poll).expect.array()
+ .unique()
+ .allString()
+ .range(1, 10)
+ .validate(choices => !choices.some(choice => {
if (typeof choice != 'string') return true;
if (choice.trim().length == 0) return true;
if (choice.trim().length > 50) return true;
return false;
- });
- return shouldReject ? new Error('invalid poll choices') : true;
- },
- // 選択肢がひとつならエラー
- choices => choices.length == 1 ? new Error('poll choices must be ひとつ以上') : true,
- // 選択肢が多すぎてもエラー
- choices => choices.length > 10 ? new Error('many poll choices') : true,
- ]);
+ }))
+ .qed();
if (pollChoicesErr) return rej('invalid poll choices');
_poll.choices = pollChoices.map((choice, i) => ({