Skip to content

Commit

Permalink
update types name for secrets v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Jan 2, 2023
1 parent ac4b67d commit a07d4e6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/src/routes/v2/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ router.delete(
}
})

const [bulkModificationInfoError, bulkModificationInfo] = await to(Secret.bulkWrite(deleteOperationsToPerform).then())
if (bulkModificationInfoError) {
throw InternalServerError({ message: "Unable to apply modifications, please try again" })
const [bulkDeleteError, bulkDelete] = await to(Secret.bulkWrite(deleteOperationsToPerform).then())
if (bulkDeleteError) {
if (bulkDeleteError instanceof ValidationError) {
throw RouteValidationError({ message: "Unable to apply modifications, please try again", stack: bulkDeleteError.stack })
}
throw InternalServerError()
}

res.status(200).send()
Expand All @@ -135,7 +138,7 @@ router.delete(
router.patch(
'/batch-modify/workspace/:workspaceId/environment/:environmentName',
requireAuth,
body('secrets').exists().isArray().custom((value) => value.every((item: ISecret) => typeof item === 'object')),
body('secrets').exists().isArray().custom((secrets: ModifySecretRequestBody[]) => secrets.length > 0),
param('workspaceId').exists().isMongoId().trim(),
param('environmentName').exists().trim(),
requireWorkspaceAuth({
Expand All @@ -145,7 +148,6 @@ router.patch(
validateRequest, async (req: Request, res: Response) => {
const { workspaceId, environmentName } = req.params
const secretsModificationsRequested: ModifySecretRequestBody[] = req.body.secrets;

const [secretIdsUserCanModifyError, secretIdsUserCanModify] = await to(Secret.find({ workspace: workspaceId, environment: environmentName }, { _id: 1 }).then())
if (secretIdsUserCanModifyError) {
throw InternalServerError({ message: "Unable to fetch secrets you own" })
Expand All @@ -154,6 +156,7 @@ router.patch(
const secretsUserCanModifySet: Set<string> = new Set(secretIdsUserCanModify.map(objectId => objectId._id.toString()));
const updateOperationsToPerform: any = []


secretsModificationsRequested.forEach(userModifiedSecret => {
if (secretsUserCanModifySet.has(userModifiedSecret._id.toString())) {
const sanitizedSecret: SanitizedSecretModify = {
Expand All @@ -180,7 +183,11 @@ router.patch(

const [bulkModificationInfoError, bulkModificationInfo] = await to(Secret.bulkWrite(updateOperationsToPerform).then())
if (bulkModificationInfoError) {
throw InternalServerError({ message: "Unable to apply modifications, please try again" })
if (bulkModificationInfoError instanceof ValidationError) {
throw RouteValidationError({ message: "Unable to apply modifications, please try again", stack: bulkModificationInfoError.stack })
}

throw InternalServerError()
}

return res.status(200).send()
Expand Down

0 comments on commit a07d4e6

Please sign in to comment.