diff options
author | Puyodead1 <puyodead@proton.me> | 2023-03-25 18:01:56 -0400 |
---|---|---|
committer | Puyodead1 <puyodead@proton.me> | 2023-04-13 15:39:31 -0400 |
commit | 860b9d583e720ba5e3d003e1eaca81faf22e360f (patch) | |
tree | d5c8301f756fe4e4a3b85dc7f58f6003f5f62c65 /src/api | |
parent | oapi: users progress (diff) | |
download | server-860b9d583e720ba5e3d003e1eaca81faf22e360f.tar.xz |
oapi: finish users
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/routes/applications/#id/bot/index.ts | 4 | ||||
-rw-r--r-- | src/api/routes/auth/register.ts | 2 | ||||
-rw-r--r-- | src/api/routes/auth/reset.ts | 2 | ||||
-rw-r--r-- | src/api/routes/users/@me/guilds/#guild_id/settings.ts | 36 | ||||
-rw-r--r-- | src/api/routes/users/@me/mfa/totp/disable.ts | 12 | ||||
-rw-r--r-- | src/api/routes/users/@me/mfa/totp/enable.ts | 15 | ||||
-rw-r--r-- | src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts | 34 | ||||
-rw-r--r-- | src/api/routes/users/@me/mfa/webauthn/credentials/index.ts | 12 |
8 files changed, 90 insertions, 27 deletions
diff --git a/src/api/routes/applications/#id/bot/index.ts b/src/api/routes/applications/#id/bot/index.ts index 5eea27e9..0a6e6fd4 100644 --- a/src/api/routes/applications/#id/bot/index.ts +++ b/src/api/routes/applications/#id/bot/index.ts @@ -35,8 +35,8 @@ router.post( "/", route({ responses: { - 200: { - body: "TokenResponse", + 204: { + body: "TokenOnlyResponse", }, 400: { body: "APIErrorResponse", diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts index 73a28fed..321b4a65 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts @@ -45,7 +45,7 @@ router.post( route({ requestBody: "RegisterSchema", responses: { - 200: { body: "TokenResponse" }, + 200: { body: "TokenOnlyResponse" }, 400: { body: "APIErrorOrCaptchaResponse" }, }, }), diff --git a/src/api/routes/auth/reset.ts b/src/api/routes/auth/reset.ts index cbfa4935..f97045a6 100644 --- a/src/api/routes/auth/reset.ts +++ b/src/api/routes/auth/reset.ts @@ -38,7 +38,7 @@ router.post( requestBody: "PasswordResetSchema", responses: { 200: { - body: "TokenResponse", + body: "TokenOnlyResponse", }, 400: { body: "APIErrorOrCaptchaResponse", diff --git a/src/api/routes/users/@me/guilds/#guild_id/settings.ts b/src/api/routes/users/@me/guilds/#guild_id/settings.ts index 2ae82423..ac6586ce 100644 --- a/src/api/routes/users/@me/guilds/#guild_id/settings.ts +++ b/src/api/routes/users/@me/guilds/#guild_id/settings.ts @@ -28,17 +28,37 @@ import { Request, Response, Router } from "express"; const router = Router(); // GET doesn't exist on discord.com -router.get("/", route({}), async (req: Request, res: Response) => { - const user = await Member.findOneOrFail({ - where: { id: req.user_id, guild_id: req.params.guild_id }, - select: ["settings"], - }); - return res.json(user.settings); -}); +router.get( + "/", + route({ + responses: { + 200: {}, + 404: {}, + }, + }), + async (req: Request, res: Response) => { + const user = await Member.findOneOrFail({ + where: { id: req.user_id, guild_id: req.params.guild_id }, + select: ["settings"], + }); + return res.json(user.settings); + }, +); router.patch( "/", - route({ requestBody: "UserGuildSettingsSchema" }), + route({ + requestBody: "UserGuildSettingsSchema", + responses: { + 200: {}, + 400: { + body: "APIErrorResponse", + }, + 404: { + body: "APIErrorResponse", + }, + }, + }), async (req: Request, res: Response) => { const body = req.body as UserGuildSettingsSchema; diff --git a/src/api/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts index bade76c3..362152d7 100644 --- a/src/api/routes/users/@me/mfa/totp/disable.ts +++ b/src/api/routes/users/@me/mfa/totp/disable.ts @@ -31,7 +31,17 @@ const router = Router(); router.post( "/", - route({ requestBody: "TotpDisableSchema" }), + route({ + requestBody: "TotpDisableSchema", + responses: { + 200: { + body: "TokenOnlyResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), async (req: Request, res: Response) => { const body = req.body as TotpDisableSchema; diff --git a/src/api/routes/users/@me/mfa/totp/enable.ts b/src/api/routes/users/@me/mfa/totp/enable.ts index 87bbaec9..19836e4d 100644 --- a/src/api/routes/users/@me/mfa/totp/enable.ts +++ b/src/api/routes/users/@me/mfa/totp/enable.ts @@ -32,7 +32,20 @@ const router = Router(); router.post( "/", - route({ requestBody: "TotpEnableSchema" }), + route({ + requestBody: "TotpEnableSchema", + responses: { + 200: { + body: "TokenWithBackupCodesResponse", + }, + 400: { + body: "APIErrorResponse", + }, + 404: { + body: "APIErrorResponse", + }, + }, + }), async (req: Request, res: Response) => { const body = req.body as TotpEnableSchema; diff --git a/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts b/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts index 04aca7e4..9cf42def 100644 --- a/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts +++ b/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts @@ -21,21 +21,31 @@ import { SecurityKey, User } from "@spacebar/util"; import { Request, Response, Router } from "express"; const router = Router(); -router.delete("/", route({}), async (req: Request, res: Response) => { - const { key_id } = req.params; +router.delete( + "/", + route({ + responses: { + 204: {}, + }, + }), + async (req: Request, res: Response) => { + const { key_id } = req.params; - await SecurityKey.delete({ - id: key_id, - user_id: req.user_id, - }); + await SecurityKey.delete({ + id: key_id, + user_id: req.user_id, + }); - const keys = await SecurityKey.count({ where: { user_id: req.user_id } }); + const keys = await SecurityKey.count({ + where: { user_id: req.user_id }, + }); - // disable webauthn if there are no keys left - if (keys === 0) - await User.update({ id: req.user_id }, { webauthn_enabled: false }); + // disable webauthn if there are no keys left + if (keys === 0) + await User.update({ id: req.user_id }, { webauthn_enabled: false }); - res.sendStatus(204); -}); + res.sendStatus(204); + }, +); export default router; diff --git a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts index 46bdfdd0..f383ffb7 100644 --- a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts +++ b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts @@ -73,7 +73,17 @@ router.get("/", route({}), async (req: Request, res: Response) => { router.post( "/", - route({ requestBody: "WebAuthnPostSchema" }), + route({ + requestBody: "WebAuthnPostSchema", + responses: { + 200: { + body: "WebAuthnCreateResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), async (req: Request, res: Response) => { if (!WebAuthn.fido2) { // TODO: I did this for typescript and I can't use ! |