(
secretId: string,
updates: SecretUpdateData,
options: SecretQueryOptions = {},
)
| 319 | } |
| 320 | |
| 321 | async updateSecret( |
| 322 | secretId: string, |
| 323 | updates: SecretUpdateData, |
| 324 | options: SecretQueryOptions = {}, |
| 325 | ): Promise<SecretSummary> { |
| 326 | await this.ensureSecretExists(secretId, options); |
| 327 | |
| 328 | const updatePayload: Partial<Omit<NewSecret, 'id' | 'createdAt' | 'updatedAt'>> = {}; |
| 329 | |
| 330 | if (updates.name !== undefined) { |
| 331 | updatePayload.name = updates.name; |
| 332 | } |
| 333 | |
| 334 | if (updates.description !== undefined) { |
| 335 | updatePayload.description = updates.description; |
| 336 | } |
| 337 | |
| 338 | if (updates.tags !== undefined) { |
| 339 | updatePayload.tags = updates.tags; |
| 340 | } |
| 341 | |
| 342 | if (Object.keys(updatePayload).length === 0) { |
| 343 | return this.findById(secretId, options); |
| 344 | } |
| 345 | |
| 346 | try { |
| 347 | const conditions: SQL[] = [eq(secrets.id, secretId)]; |
| 348 | if (options.organizationId) { |
| 349 | conditions.push(eq(secrets.organizationId, options.organizationId)); |
| 350 | } |
| 351 | |
| 352 | await this.db |
| 353 | .update(secrets) |
| 354 | .set({ |
| 355 | ...updatePayload, |
| 356 | updatedAt: sql`now()`, |
| 357 | }) |
| 358 | .where(and(...conditions)); |
| 359 | } catch (error: any) { |
| 360 | if (error?.code === '23505' && updates.name) { |
| 361 | throw new ConflictException(`Secret name '${updates.name}' already exists`); |
| 362 | } |
| 363 | throw error; |
| 364 | } |
| 365 | |
| 366 | return this.findById(secretId, options); |
| 367 | } |
| 368 | |
| 369 | async deleteSecret(secretId: string, options: SecretQueryOptions = {}): Promise<void> { |
| 370 | const conditions: SQL[] = [eq(secrets.id, secretId)]; |
nothing calls this directly
no test coverage detected