( noteId: RemoteNoteId, text: string, authorId: UserId, )
| 751 | } |
| 752 | |
| 753 | export async function insertNoteComment( |
| 754 | noteId: RemoteNoteId, |
| 755 | text: string, |
| 756 | authorId: UserId, |
| 757 | ) { |
| 758 | const noteDbId = fromBase64Url(noteId) |
| 759 | await db.transaction().execute( |
| 760 | async (tx) => |
| 761 | await Promise.all([ |
| 762 | db |
| 763 | .selectFrom('note') |
| 764 | .select(['id']) |
| 765 | .where('note.id', '=', noteDbId) |
| 766 | .executeTakeFirst() |
| 767 | .then((r) => { |
| 768 | if (r == null) throwExp(`Note ${noteId} not found.`) |
| 769 | }), |
| 770 | tx |
| 771 | .updateTable('note') |
| 772 | .set({ |
| 773 | commentsCount: (x) => sql`${x.ref('commentsCount')} + 1`, |
| 774 | }) |
| 775 | .where('note.id', '=', noteDbId) |
| 776 | .execute(), |
| 777 | tx |
| 778 | .insertInto('noteComment') |
| 779 | .values({ |
| 780 | id: unhex(hexId()), |
| 781 | authorId, |
| 782 | level: 0, |
| 783 | noteId: noteDbId, |
| 784 | votes: '', |
| 785 | text, |
| 786 | }) |
| 787 | .execute(), |
| 788 | ]), |
| 789 | ) |
| 790 | } |
| 791 | |
| 792 | export async function insertNoteChildComment( |
| 793 | parentCommentId: CommentId, |
no test coverage detected