From 3dadf22ff6e51cf01965a3d1adf2744712174d6c Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Mon, 3 Aug 2020 00:24:03 +0530 Subject: [PATCH] :recycle: Change snake to camel case --- src/_staart/helpers/authorization.ts | 22 +++++++-------- src/_staart/helpers/jwt.ts | 12 ++++----- src/_staart/rest/oauth.ts | 6 ++--- src/_staart/rest/organization.ts | 28 ++++++++++---------- src/_staart/rest/user.ts | 28 ++++++++++---------- src/_staart/services/organization.service.ts | 14 +++++----- src/_staart/services/user.service.ts | 18 ++++++------- 7 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/_staart/helpers/authorization.ts b/src/_staart/helpers/authorization.ts index 20386fe46..3df32ea6b 100644 --- a/src/_staart/helpers/authorization.ts +++ b/src/_staart/helpers/authorization.ts @@ -9,8 +9,8 @@ import { users, organizations, memberships, - access_tokens, - api_keys, + accessTokens, + apiKeys, } from "@prisma/client"; import { prisma } from "./prisma"; import { getUserById } from "../services/user.service"; @@ -56,7 +56,7 @@ const canUserUser = async (user: users, action: UserScopes, target: users) => { * Whether an access token can perform an action for an organization */ const canAccessTokenUser = ( - accessToken: access_tokens, + accessToken: accessTokens, action: UserScopes, target: users ) => { @@ -163,7 +163,7 @@ const canUserSudo = async (user: users, action: SudoScopes) => { * Whether an API key can perform an action for an organization */ const canApiKeyOrganization = ( - apiKey: api_keys, + apiKey: apiKeys, action: OrgScopes, target: organizations ) => { @@ -187,7 +187,7 @@ export const can = async ( targetType: "user" | "organization" | "membership" | "sudo", target?: string | users | organizations | memberships ) => { - let requestFromType: "users" | "api_keys" | "access_tokens" = "users"; + let requestFromType: "users" | "apiKeys" | "accessTokens" = "users"; /** * First, we figure out what the first parameter is @@ -195,9 +195,9 @@ export const can = async ( */ if (typeof user === "object") { if ((user as ApiKeyResponse).sub === Tokens.API_KEY) { - requestFromType = "api_keys"; + requestFromType = "apiKeys"; } else if ((user as AccessTokenResponse).sub === Tokens.ACCESS_TOKEN) { - requestFromType = "access_tokens"; + requestFromType = "accessTokens"; } } else { const result = await getUserById(user); @@ -232,8 +232,8 @@ export const can = async ( } } - if (requestFromType === "api_keys") { - const apiKeyDetails = await prisma.api_keys.findOne({ + if (requestFromType === "apiKeys") { + const apiKeyDetails = await prisma.apiKeys.findOne({ where: { id: parseInt((user as ApiKeyResponse).id) }, }); if (!apiKeyDetails || !target) throw new Error(INVALID_TOKEN); @@ -242,8 +242,8 @@ export const can = async ( action as OrgScopes, target as organizations ); - } else if (requestFromType === "access_tokens") { - const accessTokenDetails = await prisma.access_tokens.findOne({ + } else if (requestFromType === "accessTokens") { + const accessTokenDetails = await prisma.accessTokens.findOne({ where: { id: parseInt((user as ApiKeyResponse).id) }, }); if (!accessTokenDetails || !target) throw new Error(INVALID_TOKEN); diff --git a/src/_staart/helpers/jwt.ts b/src/_staart/helpers/jwt.ts index 6815c0d50..88ad0deea 100644 --- a/src/_staart/helpers/jwt.ts +++ b/src/_staart/helpers/jwt.ts @@ -29,11 +29,11 @@ import { removeFalsyValues, } from "./utils"; import { - access_tokensCreateInput, - access_tokensUpdateInput, + accessTokensCreateInput, + accessTokensUpdateInput, users, - api_keysCreateInput, - api_keysUpdateInput, + apiKeysCreateInput, + apiKeysUpdateInput, } from "@prisma/client"; import { prisma } from "./prisma"; import { @@ -153,7 +153,7 @@ export const twoFactorToken = (user: users) => * Generate an API key JWT */ export const apiKeyToken = ( - apiKey: api_keysCreateInput | api_keysUpdateInput + apiKey: apiKeysCreateInput | apiKeysUpdateInput ) => { const createApiKey = { ...removeFalsyValues(apiKey) }; delete createApiKey.createdAt; @@ -174,7 +174,7 @@ export const apiKeyToken = ( * Generate an access token */ export const accessToken = ( - accessToken: access_tokensCreateInput | access_tokensUpdateInput + accessToken: accessTokensCreateInput | accessTokensUpdateInput ) => { const createAccessToken = { ...removeFalsyValues(accessToken) }; delete createAccessToken.createdAt; diff --git a/src/_staart/rest/oauth.ts b/src/_staart/rest/oauth.ts index 57656d543..ea32a019e 100644 --- a/src/_staart/rest/oauth.ts +++ b/src/_staart/rest/oauth.ts @@ -88,7 +88,7 @@ export const github = { clientSecret: GITHUB_CLIENT_SECRET, redirectUri: getRedirectUri("github"), authorizationUri: "https://github.com/login/oauth/authorize", - accessTokenUri: "https://github.com/login/oauth/access_token", + accessTokenUri: "https://github.com/login/oauth/accessToken", scopes: ["read:user", "user:email"], }), callback: async (url: string, locals: Locals) => { @@ -109,14 +109,14 @@ export const facebook = { clientSecret: FACEBOOK_CLIENT_SECRET, redirectUri: getRedirectUri("facebook"), authorizationUri: "https://www.facebook.com/v3.3/dialog/oauth", - accessTokenUri: "https://graph.facebook.com/v3.3/oauth/access_token", + accessTokenUri: "https://graph.facebook.com/v3.3/oauth/accessToken", scopes: ["email"], }), callback: async (url: string, locals: Locals) => { const token = (await facebook.client.code.getToken(url)).accessToken; const data = ( await axios.get( - `https://graph.facebook.com/v3.3/me?fields=name,email&access_token=${token}` + `https://graph.facebook.com/v3.3/me?fields=name,email&accessToken=${token}` ) ).data; return loginWithOAuth2Service("facebook", data.name, data.email, locals); diff --git a/src/_staart/rest/organization.ts b/src/_staart/rest/organization.ts index 37c7193ee..39f5a4fb5 100644 --- a/src/_staart/rest/organization.ts +++ b/src/_staart/rest/organization.ts @@ -66,12 +66,12 @@ import { membershipsUpdateInput, users, MembershipRole, - api_keysSelect, - api_keysInclude, - api_keysOrderByInput, - api_keysWhereUniqueInput, - api_keysUpdateInput, - api_keysCreateInput, + apiKeysSelect, + apiKeysInclude, + apiKeysOrderByInput, + apiKeysWhereUniqueInput, + apiKeysUpdateInput, + apiKeysCreateInput, webhooksCreateInput, domainsSelect, domainsInclude, @@ -564,7 +564,7 @@ export const getAllOrganizationDataForUser = async ( id: parseInt(organizationId), }, include: { - api_keys: true, + apiKeys: true, domains: true, memberships: true, webhooks: true, @@ -798,7 +798,7 @@ export const getOrganizationApiKeysForUser = async ( ) ) return paginatedResult( - await prisma.api_keys.findMany({ + await prisma.apiKeys.findMany({ where: { organizationId: parseInt(organizationId) }, ...queryParamsToSelect(queryParams), }), @@ -820,7 +820,7 @@ export const getOrganizationApiKeyForUser = async ( organizationId ) ) - return prisma.api_keys.findOne({ where: { id: parseInt(apiKeyId) } }); + return prisma.apiKeys.findOne({ where: { id: parseInt(apiKeyId) } }); throw new Error(INSUFFICIENT_PERMISSION); }; @@ -849,7 +849,7 @@ export const updateApiKeyForUser = async ( userId: string | ApiKeyResponse, organizationId: string, apiKeyId: string, - data: api_keysUpdateInput, + data: apiKeysUpdateInput, locals: Locals ) => { if ( @@ -860,7 +860,7 @@ export const updateApiKeyForUser = async ( organizationId ) ) { - const result = await prisma.api_keys.update({ + const result = await prisma.apiKeys.update({ where: { id: parseInt(apiKeyId) }, data, }); @@ -874,7 +874,7 @@ export const updateApiKeyForUser = async ( export const createApiKeyForUser = async ( userId: string | ApiKeyResponse, organizationId: string, - apiKey: api_keysCreateInput, + apiKey: apiKeysCreateInput, locals: Locals ) => { if ( @@ -887,7 +887,7 @@ export const createApiKeyForUser = async ( ) { apiKey.jwtApiKey = randomString({ length: 20 }); apiKey.expiresAt = apiKey.expiresAt || new Date(TOKEN_EXPIRY_API_KEY_MAX); - const result = await prisma.api_keys.create({ + const result = await prisma.apiKeys.create({ data: { ...apiKey, organization: { @@ -918,7 +918,7 @@ export const deleteApiKeyForUser = async ( organizationId ) ) { - const result = await prisma.api_keys.delete({ + const result = await prisma.apiKeys.delete({ where: { id: parseInt(apiKeyId) }, }); queueWebhook(organizationId, Webhooks.DELETE_API_KEY, apiKeyId); diff --git a/src/_staart/rest/user.ts b/src/_staart/rest/user.ts index 1a8958b2b..943644387 100644 --- a/src/_staart/rest/user.ts +++ b/src/_staart/rest/user.ts @@ -44,12 +44,12 @@ import { membershipsInclude, membershipsOrderByInput, membershipsWhereUniqueInput, - access_tokensSelect, - access_tokensInclude, - access_tokensOrderByInput, - access_tokensWhereUniqueInput, - access_tokensUpdateInput, - access_tokensCreateInput, + accessTokensSelect, + accessTokensInclude, + accessTokensOrderByInput, + accessTokensWhereUniqueInput, + accessTokensUpdateInput, + accessTokensCreateInput, sessionsSelect, sessionsInclude, sessionsOrderByInput, @@ -229,7 +229,7 @@ export const getAllDataForUser = async ( where: { id: parseInt(userId) }, include: { emails: true, - access_tokens: true, + accessTokens: true, approved_locations: true, backup_codes: true, identities: true, @@ -322,7 +322,7 @@ export const getUserAccessTokensForUser = async ( await can(tokenUserId, UserScopes.READ_USER_ACCESS_TOKENS, "user", userId) ) return paginatedResult( - await prisma.access_tokens.findMany({ + await prisma.accessTokens.findMany({ where: { userId: parseInt(userId) }, ...queryParamsToSelect(queryParams), }), @@ -339,7 +339,7 @@ export const getUserAccessTokenForUser = async ( if ( await can(tokenUserId, UserScopes.READ_USER_ACCESS_TOKENS, "user", userId) ) - return prisma.access_tokens.findOne({ + return prisma.accessTokens.findOne({ where: { id: parseInt(accessTokenId) }, }); throw new Error(INSUFFICIENT_PERMISSION); @@ -349,13 +349,13 @@ export const updateAccessTokenForUser = async ( tokenUserId: string, userId: string, accessTokenId: string, - data: access_tokensUpdateInput, + data: accessTokensUpdateInput, locals: Locals ) => { if ( await can(tokenUserId, UserScopes.UPDATE_USER_ACCESS_TOKENS, "user", userId) ) - return prisma.access_tokens.update({ + return prisma.accessTokens.update({ where: { id: parseInt(accessTokenId) }, data, }); @@ -365,7 +365,7 @@ export const updateAccessTokenForUser = async ( export const createAccessTokenForUser = async ( tokenUserId: string, userId: string, - accessToken: access_tokensCreateInput, + accessToken: accessTokensCreateInput, locals: Locals ) => { if ( @@ -374,7 +374,7 @@ export const createAccessTokenForUser = async ( accessToken.jwtAccessToken = randomString({ length: 20 }); accessToken.expiresAt = accessToken.expiresAt || new Date(TOKEN_EXPIRY_API_KEY_MAX); - return prisma.access_tokens.create({ + return prisma.accessTokens.create({ data: { ...accessToken, user: { connect: { id: parseInt(userId) } } }, }); } @@ -390,7 +390,7 @@ export const deleteAccessTokenForUser = async ( if ( await can(tokenUserId, UserScopes.DELETE_USER_ACCESS_TOKENS, "user", userId) ) - return prisma.access_tokens.delete({ + return prisma.accessTokens.delete({ where: { id: parseInt(accessTokenId) }, }); throw new Error(INSUFFICIENT_PERMISSION); diff --git a/src/_staart/services/organization.service.ts b/src/_staart/services/organization.service.ts index 38013b75f..2b215dd49 100644 --- a/src/_staart/services/organization.service.ts +++ b/src/_staart/services/organization.service.ts @@ -28,8 +28,8 @@ import { prisma } from "../helpers/prisma"; import { organizationsCreateInput, organizationsUpdateInput, - api_keysCreateInput, - api_keysUpdateInput, + apiKeysCreateInput, + apiKeysUpdateInput, domainsCreateInput, organizations, } from "@prisma/client"; @@ -177,10 +177,10 @@ export const getApiKeyLogs = async (apiKeyId: string, query: KeyValue) => { /** * Create an API key */ -export const createApiKey = async (apiKey: api_keysCreateInput) => { +export const createApiKey = async (apiKey: apiKeysCreateInput) => { apiKey.expiresAt = apiKey.expiresAt || new Date(TOKEN_EXPIRY_API_KEY_MAX); apiKey.jwtApiKey = await apiKeyToken(apiKey); - return prisma.api_keys.create({ data: apiKey }); + return prisma.apiKeys.create({ data: apiKey }); }; /** @@ -188,15 +188,15 @@ export const createApiKey = async (apiKey: api_keysCreateInput) => { */ export const updateApiKey = async ( apiKeyId: string, - data: api_keysUpdateInput + data: apiKeysUpdateInput ) => { - const apiKey = await prisma.api_keys.findOne({ + const apiKey = await prisma.apiKeys.findOne({ where: { id: parseInt(apiKeyId) }, }); if (!apiKey) throw new Error(RESOURCE_NOT_FOUND); if (apiKey.jwtApiKey) await invalidateToken(apiKey.jwtApiKey); data.jwtApiKey = await apiKeyToken({ ...apiKey, ...data }); - return prisma.api_keys.update({ data, where: { id: parseInt(apiKeyId) } }); + return prisma.apiKeys.update({ data, where: { id: parseInt(apiKeyId) } }); }; /** diff --git a/src/_staart/services/user.service.ts b/src/_staart/services/user.service.ts index c15b07046..67ba01d1c 100644 --- a/src/_staart/services/user.service.ts +++ b/src/_staart/services/user.service.ts @@ -20,8 +20,8 @@ import { KeyValue } from "../interfaces/general"; import { prisma } from "../helpers/prisma"; import { users, - access_tokens, - access_tokensCreateInput, + accessTokens, + accessTokensCreateInput, sessionsUpdateInput, usersCreateInput, } from "@prisma/client"; @@ -234,10 +234,10 @@ export const createBackupCodes = async (userId: string | number, count = 1) => { /** * Create an API key */ -export const createAccessToken = async (data: access_tokensCreateInput) => { +export const createAccessToken = async (data: accessTokensCreateInput) => { data.expiresAt = data.expiresAt || new Date(TOKEN_EXPIRY_API_KEY_MAX); data.jwtAccessToken = await accessToken(data); - return prisma.access_tokens.create({ data }); + return prisma.accessTokens.create({ data }); }; /** @@ -245,16 +245,16 @@ export const createAccessToken = async (data: access_tokensCreateInput) => { */ export const updateAccessToken = async ( accessTokenId: string, - data: access_tokens + data: accessTokens ) => { - const newAccessToken = await prisma.access_tokens.findOne({ + const newAccessToken = await prisma.accessTokens.findOne({ where: { id: parseInt(accessTokenId) }, }); if (!newAccessToken) throw new Error(RESOURCE_NOT_FOUND); if (newAccessToken.jwtAccessToken) await invalidateToken(newAccessToken.jwtAccessToken); data.jwtAccessToken = await accessToken({ ...newAccessToken, ...data }); - return prisma.access_tokens.update({ + return prisma.accessTokens.update({ data, where: { id: parseInt(accessTokenId) }, }); @@ -264,13 +264,13 @@ export const updateAccessToken = async ( * Delete an API key */ export const deleteAccessToken = async (accessTokenId: string) => { - const currentAccessToken = await prisma.access_tokens.findOne({ + const currentAccessToken = await prisma.accessTokens.findOne({ where: { id: parseInt(accessTokenId) }, }); if (!currentAccessToken) throw new Error(RESOURCE_NOT_FOUND); if (currentAccessToken.jwtAccessToken) await invalidateToken(currentAccessToken.jwtAccessToken); - return prisma.access_tokens.delete({ + return prisma.accessTokens.delete({ where: { id: parseInt(accessTokenId) }, }); };