mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 07:53:08 +02:00
Use insert for creating Note (#6440)
This commit is contained in:
parent
111eb43fd9
commit
9c4a789a4e
1 changed files with 7 additions and 8 deletions
|
@ -433,30 +433,29 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
|
||||||
|
|
||||||
// 投稿を作成
|
// 投稿を作成
|
||||||
try {
|
try {
|
||||||
let note: Note;
|
|
||||||
if (insert.hasPoll) {
|
if (insert.hasPoll) {
|
||||||
// Start transaction
|
// Start transaction
|
||||||
await getConnection().transaction(async transactionalEntityManager => {
|
await getConnection().transaction(async transactionalEntityManager => {
|
||||||
note = await transactionalEntityManager.save(insert);
|
await transactionalEntityManager.insert(Note, insert);
|
||||||
|
|
||||||
const poll = new Poll({
|
const poll = new Poll({
|
||||||
noteId: note.id,
|
noteId: insert.id,
|
||||||
choices: data.poll!.choices,
|
choices: data.poll!.choices,
|
||||||
expiresAt: data.poll!.expiresAt,
|
expiresAt: data.poll!.expiresAt,
|
||||||
multiple: data.poll!.multiple,
|
multiple: data.poll!.multiple,
|
||||||
votes: new Array(data.poll!.choices.length).fill(0),
|
votes: new Array(data.poll!.choices.length).fill(0),
|
||||||
noteVisibility: note.visibility,
|
noteVisibility: insert.visibility,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
userHost: user.host
|
userHost: user.host
|
||||||
});
|
});
|
||||||
|
|
||||||
await transactionalEntityManager.save(poll);
|
await transactionalEntityManager.insert(Poll, poll);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
note = await Notes.save(insert);
|
await Notes.insert(insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
return note!;
|
return await Notes.findOneOrFail(insert.id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// duplicate key error
|
// duplicate key error
|
||||||
if (isDuplicateKeyValueError(e)) {
|
if (isDuplicateKeyValueError(e)) {
|
||||||
|
@ -467,7 +466,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
|
||||||
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
||||||
throw new Error('something happened');
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue