Skip to content

Commit

Permalink
Retrieve org attributes when finding org by id
Browse files Browse the repository at this point in the history
  • Loading branch information
sausage-todd committed Jun 18, 2024
1 parent 9b3b368 commit e12aa06
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
22 changes: 21 additions & 1 deletion backend/src/database/repositories/organizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
fetchManyOrgIdentities,
updateOrgIdentity,
} from '@crowd/data-access-layer/src/org_identities'
import { findOrgAttributes } from '@crowd/data-access-layer/src/org_attributes'
import { FieldTranslatorFactory, OpensearchQueryParser } from '@crowd/opensearch'
import {
FeatureFlag,
Expand Down Expand Up @@ -1250,7 +1251,26 @@ class OrganizationRepository {
throw new Error404()
}

return rows[0]
const organization = rows[0]

const qx = SequelizeRepository.getQueryExecutor(options)
const attributes = await findOrgAttributes(qx, id)
organization.attributes = attributes.reduce((acc, a) => {
if (!acc[a.name]) {
acc[a.name] = {}
}
if (!acc[a.name][a.source]) {
acc[a.name][a.source] = []
}

acc[a.name][a.source].push(a.value)
if (a.default) {
acc[a.name].default = a.value
}
return acc
}, {})

return organization
}

static async filterIdsInTenant(ids, options: IRepositoryOptions) {
Expand Down
27 changes: 27 additions & 0 deletions services/libs/data-access-layer/src/org_attributes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { QueryExecutor } from '../queryExecutor'

export interface IOrgAttribute {
id?: string
createdAt: string
updatedAt: string
organizationId: string
type: string
name: string
source: string
default: boolean
value?: string
}

export async function findOrgAttributes(qx: QueryExecutor, organizationId: string) {
return qx.select(
`
SELECT
*
FROM "orgAttributes"
WHERE "organizationId" = $(organizationId)
`,
{
organizationId,
},
)
}

0 comments on commit e12aa06

Please sign in to comment.