This commit is contained in:
syuilo
2021-12-09 23:58:30 +09:00
parent 0abe2dfee0
commit c69b72e199
573 changed files with 3318 additions and 3318 deletions

View File

@@ -11,13 +11,13 @@ export const meta = {
params: {
limit: {
validator: $.optional.num.range(1, 100),
default: 10
default: 10,
},
offset: {
validator: $.optional.num.min(0),
default: 0
}
default: 0,
},
},
res: {
@@ -26,9 +26,9 @@ export const meta = {
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'Note'
}
}
ref: 'Note',
},
},
};
export default define(meta, async (ps, user) => {
@@ -68,10 +68,10 @@ export default define(meta, async (ps, user) => {
if (polls.length === 0) return [];
const notes = await Notes.find({
id: In(polls.map(poll => poll.noteId))
id: In(polls.map(poll => poll.noteId)),
});
return await Notes.packMany(notes, user, {
detail: true
detail: true,
});
});

View File

@@ -27,7 +27,7 @@ export const meta = {
},
choice: {
validator: $.num
validator: $.num,
},
},
@@ -35,39 +35,39 @@ export const meta = {
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'ecafbd2e-c283-4d6d-aecb-1a0a33b75396'
id: 'ecafbd2e-c283-4d6d-aecb-1a0a33b75396',
},
noPoll: {
message: 'The note does not attach a poll.',
code: 'NO_POLL',
id: '5f979967-52d9-4314-a911-1c673727f92f'
id: '5f979967-52d9-4314-a911-1c673727f92f',
},
invalidChoice: {
message: 'Choice ID is invalid.',
code: 'INVALID_CHOICE',
id: 'e0cc9a04-f2e8-41e4-a5f1-4127293260cc'
id: 'e0cc9a04-f2e8-41e4-a5f1-4127293260cc',
},
alreadyVoted: {
message: 'You have already voted.',
code: 'ALREADY_VOTED',
id: '0963fc77-efac-419b-9424-b391608dc6d8'
id: '0963fc77-efac-419b-9424-b391608dc6d8',
},
alreadyExpired: {
message: 'The poll is already expired.',
code: 'ALREADY_EXPIRED',
id: '1022a357-b085-4054-9083-8f8de358337e'
id: '1022a357-b085-4054-9083-8f8de358337e',
},
youHaveBeenBlocked: {
message: 'You cannot vote this poll because you have been blocked by this user.',
code: 'YOU_HAVE_BEEN_BLOCKED',
id: '85a5377e-b1e9-4617-b0b9-5bea73331e49'
id: '85a5377e-b1e9-4617-b0b9-5bea73331e49',
},
}
},
};
export default define(meta, async (ps, user) => {
@@ -107,7 +107,7 @@ export default define(meta, async (ps, user) => {
// if already voted
const exist = await PollVotes.find({
noteId: note.id,
userId: user.id
userId: user.id,
});
if (exist.length) {
@@ -126,7 +126,7 @@ export default define(meta, async (ps, user) => {
createdAt,
noteId: note.id,
userId: user.id,
choice: ps.choice
choice: ps.choice,
}).then(x => PollVotes.findOneOrFail(x.identifiers[0]));
// Increment votes count
@@ -135,14 +135,14 @@ export default define(meta, async (ps, user) => {
publishNoteStream(note.id, 'pollVoted', {
choice: ps.choice,
userId: user.id
userId: user.id,
});
// Notify
createNotification(note.userId, 'pollVote', {
notifierId: user.id,
noteId: note.id,
choice: ps.choice
choice: ps.choice,
});
// Fetch watchers
@@ -154,7 +154,7 @@ export default define(meta, async (ps, user) => {
createNotification(watcher.userId, 'pollVote', {
notifierId: user.id,
noteId: note.id,
choice: ps.choice
choice: ps.choice,
});
}
});