(
auth: AuthContext | null,
secretId: string,
input: UpdateSecretInput,
)
| 144 | } |
| 145 | |
| 146 | async updateSecret( |
| 147 | auth: AuthContext | null, |
| 148 | secretId: string, |
| 149 | input: UpdateSecretInput, |
| 150 | ): Promise<SecretSummary> { |
| 151 | const organizationId = this.assertOrganizationId(auth); |
| 152 | const updates: SecretUpdateData = {}; |
| 153 | |
| 154 | if (input.name !== undefined) { |
| 155 | const trimmedName = input.name.trim(); |
| 156 | if (trimmedName.length === 0) { |
| 157 | throw new BadRequestException('Secret name cannot be empty'); |
| 158 | } |
| 159 | updates.name = trimmedName; |
| 160 | } |
| 161 | if (input.description !== undefined) { |
| 162 | if (input.description === null) { |
| 163 | updates.description = null; |
| 164 | } else { |
| 165 | const trimmedDescription = input.description.trim(); |
| 166 | updates.description = trimmedDescription.length > 0 ? trimmedDescription : null; |
| 167 | } |
| 168 | } |
| 169 | if (input.tags !== undefined) { |
| 170 | if (input.tags === null) { |
| 171 | updates.tags = null; |
| 172 | } else { |
| 173 | const normalizedTags = input.tags.map((tag) => tag.trim()).filter((tag) => tag.length > 0); |
| 174 | updates.tags = normalizedTags.length > 0 ? normalizedTags : null; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | if (Object.keys(updates).length === 0) { |
| 179 | return this.repository.findById(secretId, { organizationId }); |
| 180 | } |
| 181 | |
| 182 | return this.repository.updateSecret(secretId, updates, { organizationId }); |
| 183 | } |
| 184 | |
| 185 | async deleteSecret(auth: AuthContext | null, secretId: string): Promise<void> { |
| 186 | const organizationId = this.assertOrganizationId(auth); |
no test coverage detected