Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
syuilo | 647faa3c03 |
|
@ -1,5 +1,6 @@
|
|||
<template>
|
||||
<div class="mk-poll-editor">
|
||||
<ui-input type="date"></ui-input>
|
||||
<p class="caution" v-if="choices.length < 2">
|
||||
<fa icon="exclamation-triangle"/>{{ $t('no-only-one-choice') }}
|
||||
</p>
|
||||
|
@ -72,6 +73,8 @@ export default Vue.extend({
|
|||
<style lang="stylus" scoped>
|
||||
.mk-poll-editor
|
||||
padding 8px
|
||||
max-height 300px
|
||||
overflow auto
|
||||
|
||||
> .caution
|
||||
margin 0 0 8px 0
|
||||
|
|
|
@ -39,6 +39,7 @@ export type INote = {
|
|||
replyId: mongo.ObjectID;
|
||||
renoteId: mongo.ObjectID;
|
||||
poll: {
|
||||
period: Date;
|
||||
choices: Array<{
|
||||
id: number;
|
||||
}>
|
||||
|
|
|
@ -133,10 +133,10 @@ export const meta = {
|
|||
|
||||
poll: {
|
||||
validator: $.obj({
|
||||
choices: $.arr($.str)
|
||||
period: $.num.optional.nullable,
|
||||
choices: $.arr($.str.range(0, 50))
|
||||
.unique()
|
||||
.range(2, 10)
|
||||
.each(c => c.length > 0 && c.length < 50)
|
||||
}).optional.strict(),
|
||||
desc: {
|
||||
'ja-JP': 'アンケート'
|
||||
|
@ -210,16 +210,26 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
}
|
||||
|
||||
let poll: INote['poll'];
|
||||
|
||||
if (ps.poll) {
|
||||
(ps.poll as any).choices = (ps.poll as any).choices.map((choice: string, i: number) => ({
|
||||
id: i, // IDを付与
|
||||
text: choice.trim(),
|
||||
votes: 0
|
||||
}));
|
||||
const now = new Date();
|
||||
if (ps.poll.period && (ps.poll.period <= now.getTime())) {
|
||||
return rej('invalid poll period range');
|
||||
}
|
||||
|
||||
poll = {
|
||||
period: ps.poll.period ? new Date(ps.poll.period) : null,
|
||||
choices: ps.poll.choices.map((choice: string, i: number) => ({
|
||||
id: i, // IDを付与
|
||||
text: choice.trim(),
|
||||
votes: 0
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
|
||||
if (!(ps.text || files.length || renote || ps.poll)) {
|
||||
if (!(ps.text || files.length || renote || poll)) {
|
||||
return rej('text, fileIds, renoteId or poll is required');
|
||||
}
|
||||
|
||||
|
@ -227,7 +237,7 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
|||
create(user, {
|
||||
createdAt: new Date(),
|
||||
files: files,
|
||||
poll: ps.poll,
|
||||
poll: poll,
|
||||
text: ps.text,
|
||||
reply,
|
||||
renote,
|
||||
|
|
|
@ -59,6 +59,10 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||
return rej('already voted');
|
||||
}
|
||||
|
||||
if (note.poll.period && (note.poll.period.getTime() - Date.now() < 0)) {
|
||||
return rej('poll period expired');
|
||||
}
|
||||
|
||||
// Create vote
|
||||
await Vote.insert({
|
||||
createdAt: new Date(),
|
||||
|
|
Loading…
Reference in New Issue