From 66776ce05c97d293e76900a840b753342e4198f3 Mon Sep 17 00:00:00 2001 From: mei23 Date: Thu, 4 Jun 2020 07:13:51 +0900 Subject: [PATCH] Use insert for creating Note --- src/services/note/create.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 71f070307e..6b703c4807 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -405,30 +405,29 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri // 投稿を作成 try { - let note: Note; if (insert.hasPoll) { // Start transaction await getConnection().transaction(async transactionalEntityManager => { - note = await transactionalEntityManager.save(insert); + await transactionalEntityManager.insert(Note, insert); const poll = new Poll({ - noteId: note.id, + noteId: insert.id, choices: data.poll!.choices, expiresAt: data.poll!.expiresAt, multiple: data.poll!.multiple, votes: new Array(data.poll!.choices.length).fill(0), - noteVisibility: note.visibility, + noteVisibility: insert.visibility, userId: user.id, userHost: user.host }); - await transactionalEntityManager.save(poll); + await transactionalEntityManager.insert(Poll, poll); }); } else { - note = await Notes.save(insert); + await Notes.insert(insert); } - return note!; + return await Notes.findOneOrFail(insert.id); } catch (e) { // duplicate key error if (isDuplicateKeyValueError(e)) { @@ -439,7 +438,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri console.error(e); - throw new Error('something happened'); + throw e; } }