Skip to content

Commit

Permalink
Endpoint to serve organizations across all segments (#2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
skwowet authored Aug 12, 2024
1 parent 02da1aa commit 1a1010c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 3 additions & 1 deletion backend/src/api/organization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default (app) => {
`/tenant/:tenantId/organization/autocomplete`,
safeWrap(require('./organizationAutocomplete').default),
)
app.get(`/tenant/:tenantId/organization`, safeWrap(require('./organizationList').default))
app.get(
`/tenant/:tenantId/organization/active`,
safeWrap(require('./organizationActiveList').default),
Expand Down Expand Up @@ -49,4 +48,7 @@ export default (app) => {
)

app.post(`/tenant/:tenantId/organization/id`, safeWrap(require('./organizationByIds').default))

// list organizations across all segments
app.post(`/tenant/:tenantId/organization/list`, safeWrap(require('./organizationList').default))
}
22 changes: 19 additions & 3 deletions backend/src/api/organization/organizationList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import Permissions from '../../security/permissions'
import OrganizationService from '../../services/organizationService'
import PermissionChecker from '../../services/user/permissionChecker'
import Permissions from '../../security/permissions'
import OrganizationService from '@/services/organizationService'

/**
* POST /tenant/{tenantId}/organization/list
* @summary List organizations across all segments
* @tag Organizations
* @security Bearer
* @description List organizations across all segments. It accepts filters, sorting options and pagination.
* @pathParam {string} tenantId - Your workspace/tenant ID
* @bodyContent {OrganizationQuery} application/json
* @response 200 - Ok
* @responseContent {OrganizationList} 200.application/json
* @responseExample {OrganizationList} 200.application/json.Organization
* @response 401 - Unauthorized
* @response 404 - Not found
* @response 429 - Too many requests
*/
export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.organizationRead)

const payload = await new OrganizationService(req).findAndCountAll(req.query)
const orgService = new OrganizationService(req)
const payload = await orgService.listOrganizationsAcrossAllSegments(req.body)

await req.responseHandler.success(req, res, payload)
}
16 changes: 16 additions & 0 deletions backend/src/services/organizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,22 @@ export default class OrganizationService extends LoggerBase {
)
}

async listOrganizationsAcrossAllSegments(args) {
const { filter, orderBy, limit, offset } = args
return OrganizationRepository.findAndCountAll(
{
filter,
orderBy,
limit,
offset,
segmentId: undefined,
fields: ['id', 'displayName', 'isTeamOrganization'],
include: { identities: true, segments: true, lfxMemberships: true },
},
this.options,
)
}

async destroyBulk(ids) {
const transaction = await SequelizeRepository.createTransaction(this.options)

Expand Down

0 comments on commit 1a1010c

Please sign in to comment.