diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts index 0f121e7c9..8736e80c6 100644 --- a/backend/src/lib/api-docs/constants.ts +++ b/backend/src/lib/api-docs/constants.ts @@ -201,7 +201,7 @@ export const SECRETS = { type: "The type of the secret to attach tags to. (shared/personal)", environment: "The slug of the environment where the secret is located", projectSlug: "The slug of the project where the secret is located", - tagSlugs: "An array of tag slugs to attach to the secret." + tagSlugs: "An array of existing tag slugs to attach to the secret." }, DETACH_TAGS: { secretName: "The name of the secret to detach tags from.", @@ -209,7 +209,7 @@ export const SECRETS = { type: "The type of the secret to attach tags to. (shared/personal)", environment: "The slug of the environment where the secret is located", projectSlug: "The slug of the project where the secret is located", - tagSlugs: "An array of tag slugs to detach from the secret." + tagSlugs: "An array of existing tag slugs to detach from the secret." } } as const; diff --git a/backend/src/services/secret/secret-service.ts b/backend/src/services/secret/secret-service.ts index e3b57802f..f8fed95bb 100644 --- a/backend/src/services/secret/secret-service.ts +++ b/backend/src/services/secret/secret-service.ts @@ -1058,13 +1058,13 @@ export const secretServiceFactory = ({ throw new BadRequestError({ message: "One or more tags not found." }); } - const secretTags = await secretDAL.getSecretTags(secret.id); + const existingSecretTags = await secretDAL.getSecretTags(secret.id); - if (secretTags.some((tag) => tagSlugs.includes(tag.slug))) { + if (existingSecretTags.some((tag) => tagSlugs.includes(tag.slug))) { throw new BadRequestError({ message: "One or more tags already exist on the secret" }); } - const combinedTags = new Set([...secretTags.map((tag) => tag.id), ...tags.map((el) => el.id)]); + const combinedTags = new Set([...existingSecretTags.map((tag) => tag.id), ...tags.map((el) => el.id)]); const updatedSecret = await secretDAL.transaction(async (tx) => fnSecretBulkUpdate({ @@ -1091,7 +1091,7 @@ export const secretServiceFactory = ({ return { ...updatedSecret[0], - tags: [...secretTags, ...tags].map((t) => ({ id: t.id, slug: t.slug, name: t.name, color: t.color })) + tags: [...existingSecretTags, ...tags].map((t) => ({ id: t.id, slug: t.slug, name: t.name, color: t.color })) }; }; @@ -1156,17 +1156,17 @@ export const secretServiceFactory = ({ throw new BadRequestError({ message: "One or more tags not found." }); } - const secretTags = await secretDAL.getSecretTags(secret.id); + const existingSecretTags = await secretDAL.getSecretTags(secret.id); // Make sure all the tags exist on the secret const tagIdsToRemove = tags.map((tag) => tag.id); - const secretTagIds = secretTags.map((tag) => tag.id); + const secretTagIds = existingSecretTags.map((tag) => tag.id); if (!tagIdsToRemove.every((el) => secretTagIds.includes(el))) { throw new BadRequestError({ message: "One or more tags not found on the secret" }); } - const newTags = secretTags.filter((tag) => !tagIdsToRemove.includes(tag.id)); + const newTags = existingSecretTags.filter((tag) => !tagIdsToRemove.includes(tag.id)); const updatedSecret = await secretDAL.transaction(async (tx) => fnSecretBulkUpdate({