Skip to content
Snippets Groups Projects
Unverified Commit 9c4a789a authored by MeiMei's avatar MeiMei Committed by GitHub
Browse files

Use insert for creating Note (#6440)

parent 111eb43f
No related branches found
No related tags found
No related merge requests found
......@@ -433,30 +433,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)) {
......@@ -467,7 +466,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
console.error(e);
throw new Error('something happened');
throw e;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment