(secretId: string, options: SecretQueryOptions = {})
| 124 | } |
| 125 | |
| 126 | async findById(secretId: string, options: SecretQueryOptions = {}): Promise<SecretSummary> { |
| 127 | const conditions: SQL[] = [eq(secrets.id, secretId)]; |
| 128 | if (options.organizationId) { |
| 129 | conditions.push(eq(secrets.organizationId, options.organizationId)); |
| 130 | } |
| 131 | |
| 132 | const whereClause = conditions.length === 1 ? conditions[0] : and(...conditions); |
| 133 | |
| 134 | const rows = await this.db |
| 135 | .select({ |
| 136 | id: secrets.id, |
| 137 | name: secrets.name, |
| 138 | description: secrets.description, |
| 139 | tags: secrets.tags, |
| 140 | createdAt: secrets.createdAt, |
| 141 | updatedAt: secrets.updatedAt, |
| 142 | versionId: secretVersions.id, |
| 143 | version: secretVersions.version, |
| 144 | versionCreatedAt: secretVersions.createdAt, |
| 145 | versionCreatedBy: secretVersions.createdBy, |
| 146 | }) |
| 147 | .from(secrets) |
| 148 | .leftJoin( |
| 149 | secretVersions, |
| 150 | and(eq(secretVersions.secretId, secrets.id), eq(secretVersions.isActive, true)), |
| 151 | ) |
| 152 | .where(whereClause) |
| 153 | .limit(1); |
| 154 | |
| 155 | const row = rows[0]; |
| 156 | if (!row) { |
| 157 | throw new NotFoundException(`Secret ${secretId} not found`); |
| 158 | } |
| 159 | |
| 160 | return this.mapSummary(row); |
| 161 | } |
| 162 | |
| 163 | async findValueBySecretId( |
| 164 | secretId: string, |
no test coverage detected