This commit is contained in:
syuilo 2019-04-10 20:07:36 +09:00
parent a12bdf3684
commit df280d8e19
8 changed files with 4 additions and 12 deletions

View file

@ -6,10 +6,6 @@ import { User } from './user';
@Entity()
export class Poll {
@PrimaryColumn(id())
public id: string;
@Index({ unique: true })
@Column(id())
public noteId: Note['id'];
@OneToOne(type => Note, {

View file

@ -1,10 +1,9 @@
import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'typeorm';
import { PrimaryColumn, Entity, JoinColumn, Column, OneToOne } from 'typeorm';
import { User } from './user';
import { id } from '../id';
@Entity()
export class UserKeypair {
@Index({ unique: true })
@PrimaryColumn(id())
public userId: User['id'];

View file

@ -4,7 +4,6 @@ import { User } from './user';
@Entity()
export class UserProfile {
@Index({ unique: true })
@PrimaryColumn(id())
public userId: User['id'];

View file

@ -4,7 +4,6 @@ import { id } from '../id';
@Entity()
export class UserPublickey {
@Index({ unique: true })
@PrimaryColumn(id())
public userId: User['id'];

View file

@ -72,7 +72,7 @@ export async function updateQuestion(value: any) {
updatedAt: new Date(),
});
await Polls.update(poll.id, {
await Polls.update({ noteId: note.id }, {
votes: poll.votes
});

View file

@ -123,7 +123,7 @@ export default define(meta, async (ps, user) => {
// Increment votes count
const index = ps.choice + 1; // In SQL, array index is 1 based
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE id = '${poll.id}'`);
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
publishNoteStream(note.id, 'pollVoted', {
choice: ps.choice,

View file

@ -398,7 +398,6 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
if (note.hasPoll) {
await Polls.save({
id: genId(),
noteId: note.id,
choices: data.poll.choices,
expiresAt: data.poll.expiresAt,

View file

@ -40,7 +40,7 @@ export default (user: User, note: Note, choice: number) => new Promise(async (re
// Increment votes count
const index = choice + 1; // In SQL, array index is 1 based
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE id = '${poll.id}'`);
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
publishNoteStream(note.id, 'pollVoted', {
choice: choice,