diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-20 03:27:03 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-20 03:27:03 +0200 |
commit | 04dea8d788acfaf485f4aa9ad255e39f6aac2a08 (patch) | |
tree | 2a61e45ef6f313012a585a0a80c1fa5bfe3ddae8 /src/api/routes/users/@me/notes.ts | |
parent | Fix merge conflicts (diff) | |
download | server-04dea8d788acfaf485f4aa9ad255e39f6aac2a08.tar.xz |
prettier
Diffstat (limited to 'src/api/routes/users/@me/notes.ts')
-rw-r--r-- | src/api/routes/users/@me/notes.ts | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/api/routes/users/@me/notes.ts b/src/api/routes/users/@me/notes.ts index f938f088..fc207401 100644 --- a/src/api/routes/users/@me/notes.ts +++ b/src/api/routes/users/@me/notes.ts @@ -1,6 +1,6 @@ -import { Request, Response, Router } from "express"; import { route } from "@fosscord/api"; -import { User, Note, emitEvent, Snowflake } from "@fosscord/util"; +import { emitEvent, Note, Snowflake, User } from "@fosscord/util"; +import { Request, Response, Router } from "express"; const router: Router = Router(); @@ -10,38 +10,31 @@ router.get("/:id", route({}), async (req: Request, res: Response) => { const note = await Note.findOneOrFail({ where: { owner: { id: req.user_id }, - target: { id: id }, + target: { id: id } } }); return res.json({ note: note?.content, note_user_id: id, - user_id: req.user_id, + user_id: req.user_id }); }); router.put("/:id", route({}), async (req: Request, res: Response) => { const { id } = req.params; const owner = await User.findOneOrFail({ where: { id: req.user_id } }); - const target = await User.findOneOrFail({ where: { id: id } }); //if noted user does not exist throw + const target = await User.findOneOrFail({ where: { id: id } }); //if noted user does not exist throw const { note } = req.body; if (note && note.length) { // upsert a note if (await Note.findOne({ where: { owner: { id: owner.id }, target: { id: target.id } } })) { - Note.update( - { owner: { id: owner.id }, target: { id: target.id } }, - { owner, target, content: note } - ); + 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 } - ); - } - } - else { + } else { await Note.delete({ owner: { id: owner.id }, target: { id: target.id } }); } @@ -51,7 +44,7 @@ router.put("/:id", route({}), async (req: Request, res: Response) => { note: note, id: target.id }, - user_id: owner.id, + user_id: owner.id }); return res.status(204); |