From c28f4ffb3f5d67125abe3da9af60f05233f663a7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 Apr 2019 20:07:36 +0900 Subject: [PATCH] Clean up --- src/models/entities/poll.ts | 4 ---- src/models/entities/user-keypair.ts | 3 +-- src/models/entities/user-profile.ts | 1 - src/models/entities/user-publickey.ts | 1 - src/remote/activitypub/models/question.ts | 2 +- src/server/api/endpoints/notes/polls/vote.ts | 2 +- src/services/note/create.ts | 1 - src/services/note/polls/vote.ts | 2 +- 8 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/models/entities/poll.ts b/src/models/entities/poll.ts index 204f102f5..894f07e68 100644 --- a/src/models/entities/poll.ts +++ b/src/models/entities/poll.ts @@ -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, { diff --git a/src/models/entities/user-keypair.ts b/src/models/entities/user-keypair.ts index 9181abf8c..808985f47 100644 --- a/src/models/entities/user-keypair.ts +++ b/src/models/entities/user-keypair.ts @@ -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']; diff --git a/src/models/entities/user-profile.ts b/src/models/entities/user-profile.ts index 24b92231f..421d17c59 100644 --- a/src/models/entities/user-profile.ts +++ b/src/models/entities/user-profile.ts @@ -4,7 +4,6 @@ import { User } from './user'; @Entity() export class UserProfile { - @Index({ unique: true }) @PrimaryColumn(id()) public userId: User['id']; diff --git a/src/models/entities/user-publickey.ts b/src/models/entities/user-publickey.ts index 81c42404f..26b694407 100644 --- a/src/models/entities/user-publickey.ts +++ b/src/models/entities/user-publickey.ts @@ -4,7 +4,6 @@ import { id } from '../id'; @Entity() export class UserPublickey { - @Index({ unique: true }) @PrimaryColumn(id()) public userId: User['id']; diff --git a/src/remote/activitypub/models/question.ts b/src/remote/activitypub/models/question.ts index a5091a6d9..68f0cb359 100644 --- a/src/remote/activitypub/models/question.ts +++ b/src/remote/activitypub/models/question.ts @@ -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 }); diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts index d868234dc..dd4d93c7a 100644 --- a/src/server/api/endpoints/notes/polls/vote.ts +++ b/src/server/api/endpoints/notes/polls/vote.ts @@ -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, diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 6058fada1..bc1225cd4 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -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, diff --git a/src/services/note/polls/vote.ts b/src/services/note/polls/vote.ts index 95e5b3ef3..3051ff42d 100644 --- a/src/services/note/polls/vote.ts +++ b/src/services/note/polls/vote.ts @@ -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,