diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-23 21:06:53 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-23 21:06:53 +1000 |
commit | f7ce1780f47f40d97975ee7a8ea6f1923564c258 (patch) | |
tree | cd0772cf05acf5281eb157c3cb39c6f09a9e486b /api/src | |
parent | Merge branch 'slowcord' of github.com:MaddyUnderStars/fosscord-server into sl... (diff) | |
parent | Delete Note if no content (diff) | |
download | server-f7ce1780f47f40d97975ee7a8ea6f1923564c258.tar.xz |
Merge branch 'feat/notesTable' into slowcord
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/routes/users/@me/notes.ts | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/api/src/routes/users/@me/notes.ts b/api/src/routes/users/@me/notes.ts index e3406d18..3c503942 100644 --- a/api/src/routes/users/@me/notes.ts +++ b/api/src/routes/users/@me/notes.ts @@ -27,18 +27,22 @@ router.put("/:id", route({}), async (req: Request, res: Response) => { const target = await User.findOneOrFail({ where: { id: id } }); //if noted user does not exist throw const { note } = req.body; - // await User.update({ id: req.user_id }, { notes: { ...user.notes, [noteUser.id]: note } }); - - if (await Note.findOne({ owner: { id: owner.id }, target: { id: target.id } })) { - Note.update( - { owner: { id: owner.id }, target: { id: target.id } }, - { owner, target, content: note } - ); + if (note && note.length) { + // upsert a note + if (await Note.findOne({ owner: { id: owner.id }, target: { id: target.id } })) { + Note.update( + { owner: { id: owner.id }, target: { id: target.id } }, + { owner, target, content: note } + ); + } + else { + Note.insert( + { id: Snowflake.generate(), owner, target, content: note } + ); + } } else { - Note.insert( - { id: Snowflake.generate(), owner, target, content: note } - ); + await Note.delete({ owner: { id: owner.id }, target: { id: target.id } }); } await emitEvent({ |