From 58d3f3945ab5c2475e760793fb7062faac385f3e Mon Sep 17 00:00:00 2001 From: akhilmhdh Date: Sun, 4 Jun 2023 13:12:44 +0530 Subject: [PATCH] feat(folders): removed old comments --- .../controllers/v1/secretsFolderController.ts | 3 +- backend/src/ee/helpers/secret.ts | 1 - backend/src/middleware/requestErrorHandler.ts | 69 +++++++++++-------- backend/src/models/secret.ts | 1 - 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/backend/src/controllers/v1/secretsFolderController.ts b/backend/src/controllers/v1/secretsFolderController.ts index a750af53e..06d68a41d 100644 --- a/backend/src/controllers/v1/secretsFolderController.ts +++ b/backend/src/controllers/v1/secretsFolderController.ts @@ -65,8 +65,7 @@ export const createFolder = async (req: Request, res: Response) => { const folderVersion = new FolderVersion({ workspace: workspaceId, environment, - // root condition - nodes: parentFolder || folders.nodes, + nodes: parentFolder, }); await folderVersion.save(); diff --git a/backend/src/ee/helpers/secret.ts b/backend/src/ee/helpers/secret.ts index f7edab06e..b315310cb 100644 --- a/backend/src/ee/helpers/secret.ts +++ b/backend/src/ee/helpers/secret.ts @@ -31,7 +31,6 @@ const takeSecretSnapshotHelper = async ({ workspace: workspaceId, environment, folder: folderId, - // undefined means root thus collect all secrets }, "_id" ).lean() diff --git a/backend/src/middleware/requestErrorHandler.ts b/backend/src/middleware/requestErrorHandler.ts index 1f1e9f9b2..08aa0d5fd 100644 --- a/backend/src/middleware/requestErrorHandler.ts +++ b/backend/src/middleware/requestErrorHandler.ts @@ -1,34 +1,45 @@ import * as Sentry from '@sentry/node'; -import { ErrorRequestHandler } from "express"; -import { InternalServerError } from "../utils/errors"; -import { getLogger } from "../utils/logger"; -import RequestError, { LogLevel } from "../utils/requestError"; -import { getNodeEnv } from '../config'; +import { ErrorRequestHandler } from 'express'; +import { InternalServerError } from '../utils/errors'; +import { getLogger } from '../utils/logger'; +import RequestError, { LogLevel } from '../utils/requestError'; -export const requestErrorHandler: ErrorRequestHandler = async (error: RequestError | Error, req, res, next) => { - if (res.headersSent) return next(); - if ((await getNodeEnv()) !== "production") { - /* eslint-disable no-console */ - console.log(error) - /* eslint-enable no-console */ - } +export const requestErrorHandler: ErrorRequestHandler = async ( + error: RequestError | Error, + req, + res, + next +) => { + if (res.headersSent) return next(); - //TODO: Find better way to type check for error. In current setting you need to cast type to get the functions and variables from RequestError - if (!(error instanceof RequestError)) { - error = InternalServerError({ context: { exception: error.message }, stack: error.stack }); - (await getLogger('backend-main')).log((error).levelName.toLowerCase(), (error).message) - } + //TODO: Find better way to type check for error. In current setting you need to cast type to get the functions and variables from RequestError + if (!(error instanceof RequestError)) { + error = InternalServerError({ + context: { exception: error.message }, + stack: error.stack, + }); + (await getLogger('backend-main')).log( + (error).levelName.toLowerCase(), + (error).message + ); + } - //* Set Sentry user identification if req.user is populated - if (req.user !== undefined && req.user !== null) { - Sentry.setUser({ email: (req.user as any).email }) - } - //* Only sent error to Sentry if LogLevel is one of the following level 'ERROR', 'EMERGENCY' or 'CRITICAL' - //* with this we will eliminate false-positive errors like 'BadRequestError', 'UnauthorizedRequestError' and so on - if ([LogLevel.ERROR, LogLevel.EMERGENCY, LogLevel.CRITICAL].includes((error).level)) { - Sentry.captureException(error) - } + //* Set Sentry user identification if req.user is populated + if (req.user !== undefined && req.user !== null) { + Sentry.setUser({ email: (req.user as any).email }); + } + //* Only sent error to Sentry if LogLevel is one of the following level 'ERROR', 'EMERGENCY' or 'CRITICAL' + //* with this we will eliminate false-positive errors like 'BadRequestError', 'UnauthorizedRequestError' and so on + if ( + [LogLevel.ERROR, LogLevel.EMERGENCY, LogLevel.CRITICAL].includes( + (error).level + ) + ) { + Sentry.captureException(error); + } - res.status((error).statusCode).json((error).format(req)) - next() -} \ No newline at end of file + res + .status((error).statusCode) + .json((error).format(req)); + next(); +}; diff --git a/backend/src/models/secret.ts b/backend/src/models/secret.ts index 75163ccd1..ff34d99b1 100644 --- a/backend/src/models/secret.ts +++ b/backend/src/models/secret.ts @@ -127,7 +127,6 @@ const secretSchema = new Schema( required: true, default: ENCODING_SCHEME_UTF8, }, - // the full path to the secret in relation to folders folder: { type: String, default: "root",