(secretName: string, options: SecretQueryOptions = {})
| 87 | } |
| 88 | |
| 89 | async findByName(secretName: string, options: SecretQueryOptions = {}): Promise<SecretSummary> { |
| 90 | const conditions: SQL[] = [eq(secrets.name, secretName)]; |
| 91 | if (options.organizationId) { |
| 92 | conditions.push(eq(secrets.organizationId, options.organizationId)); |
| 93 | } |
| 94 | |
| 95 | const whereClause = conditions.length === 1 ? conditions[0] : and(...conditions); |
| 96 | |
| 97 | const rows = await this.db |
| 98 | .select({ |
| 99 | id: secrets.id, |
| 100 | name: secrets.name, |
| 101 | description: secrets.description, |
| 102 | tags: secrets.tags, |
| 103 | createdAt: secrets.createdAt, |
| 104 | updatedAt: secrets.updatedAt, |
| 105 | versionId: secretVersions.id, |
| 106 | version: secretVersions.version, |
| 107 | versionCreatedAt: secretVersions.createdAt, |
| 108 | versionCreatedBy: secretVersions.createdBy, |
| 109 | }) |
| 110 | .from(secrets) |
| 111 | .leftJoin( |
| 112 | secretVersions, |
| 113 | and(eq(secretVersions.secretId, secrets.id), eq(secretVersions.isActive, true)), |
| 114 | ) |
| 115 | .where(whereClause) |
| 116 | .limit(1); |
| 117 | |
| 118 | const row = rows[0]; |
| 119 | if (!row) { |
| 120 | throw new NotFoundException(`Secret with name '${secretName}' not found`); |
| 121 | } |
| 122 | |
| 123 | return this.mapSummary(row); |
| 124 | } |
| 125 | |
| 126 | async findById(secretId: string, options: SecretQueryOptions = {}): Promise<SecretSummary> { |
| 127 | const conditions: SQL[] = [eq(secrets.id, secretId)]; |
no test coverage detected