Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions backend/src/database/repositories/memberRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,42 @@ class MemberRepository {
parsed.sort = customSortFunction
}

if (filter.organizations && filter.organizations.length > 0) {
parsed.query.bool.must = parsed.query.bool.must.filter(
(d) => d.term['nested_organizations.uuid_id'] === undefined,
)

// add organizations filter manually for now

for (const organizationId of filter.organizations) {
parsed.query.bool.must.push({
nested: {
path: 'nested_organizations',
query: {
bool: {
must: [
{
term: {
'nested_organizations.uuid_id': organizationId,
},
},
{
bool: {
must_not: {
exists: {
field: 'nested_organizations.obj_memberOrganizations.date_dateEnd',
},
},
},
},
],
},
},
},
})
}
}

const countResponse = await options.opensearch.count({
index: OpenSearchIndex.MEMBERS,
body: { query: parsed.query },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
where "organizationId" in ($(ids:csv))),
member_data as (select os."segmentId",
os."organizationId",
count(distinct m.id) as "memberCount",
count(distinct m.id) filter ( where mo."dateEnd" is null ) as "memberCount",
count(distinct a.id) as "activityCount",
case
when array_agg(distinct a.platform) = array [null] then array []::text[]
Expand All @@ -30,16 +30,18 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
on a."organizationId" = os."organizationId" and
a."segmentId" = os."segmentId" and a."deletedAt" is null
left join members m on a."memberId" = m.id and m."deletedAt" is null
left join "memberOrganizations" mo
on m.id = mo."memberId" and a."organizationId" = mo."organizationId"
left join "memberIdentities" mi on m.id = mi."memberId"
group by os."segmentId", os."organizationId")
select o.id as "organizationId",
select o.id as "organizationId",
md."segmentId",
o."tenantId",
o.address,
o.attributes,
o."createdAt",
o.description,
COALESCE(o."displayName", o.name) as "displayName",
coalesce(o."displayName", o.name) as "displayName",
o.emails,
o."employeeCountByCountry",
o.employees,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export class MemberSyncService extends LoggerBase {
string_username: identity.username,
})
}
p.obj_arr_identities = p_identities
p.nested_identities = p_identities

const p_organizations = []
for (const organization of data.organizations) {
Expand All @@ -498,7 +498,7 @@ export class MemberSyncService extends LoggerBase {
},
})
}
p.obj_arr_organizations = p_organizations
p.nested_organizations = p_organizations

const p_tags = []
for (const tag of data.tags) {
Expand All @@ -508,7 +508,7 @@ export class MemberSyncService extends LoggerBase {
})
}

p.obj_arr_tags = p_tags
p.nested_tags = p_tags

p.uuid_arr_toMergeIds = data.toMergeIds
p.uuid_arr_noMergeIds = data.noMergeIds
Expand Down
10 changes: 5 additions & 5 deletions services/apps/search_sync_worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export enum OpenSearchIndex {
// Keeps track of version numbers for all OpenSearch indexes, aiding in managing documents.
// for eg: members_v1, activities_v1, etc.
export const IndexVersions = new Map<OpenSearchIndex, number>()
IndexVersions.set(OpenSearchIndex.MEMBERS, 1)
IndexVersions.set(OpenSearchIndex.ACTIVITIES, 1)
IndexVersions.set(OpenSearchIndex.ORGANIZATIONS, 1)
IndexVersions.set(OpenSearchIndex.MEMBERS, 2)
IndexVersions.set(OpenSearchIndex.ACTIVITIES, 2)
IndexVersions.set(OpenSearchIndex.ORGANIZATIONS, 2)

const prefixedMapping = {
dynamic_templates: [
Expand Down Expand Up @@ -299,7 +299,7 @@ const prefixedMapping = {
{
nested_objects: {
match_pattern: 'regex',
match: '^obj_arr_.*',
match: '^nested_.*',
path_match: '.*',
mapping: {
type: 'nested',
Expand All @@ -309,7 +309,7 @@ const prefixedMapping = {
{
nox_nested_objects: {
match_pattern: 'regex',
match: '^nox_obj_arr_.*',
match: '^nox_nested_.*',
path_match: '.*',
mapping: {
type: 'nested',
Expand Down
18 changes: 9 additions & 9 deletions services/libs/opensearch/src/models/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export class MembersOpensearch extends OpensearchModelBase {
type: OpensearchFieldType.FLOAT,
},
identities: {
type: OpensearchFieldType.OBJECT_ARR,
type: OpensearchFieldType.NESTED,
customTranslation: {
toOpensearch: 'obj_arr_identities.string_platform',
fromOpensearch: 'obj_arr_identities',
toOpensearch: 'nested_identities.string_platform',
fromOpensearch: 'nested_identities',
},
},
attributes: {
Expand All @@ -80,17 +80,17 @@ export class MembersOpensearch extends OpensearchModelBase {
type: OpensearchFieldType.UUID_ARR,
},
tags: {
type: OpensearchFieldType.OBJECT_ARR,
type: OpensearchFieldType.NESTED,
customTranslation: {
toOpensearch: 'obj_arr_tags.uuid_id',
fromOpensearch: 'obj_arr_tags',
toOpensearch: 'nested_tags.uuid_id',
fromOpensearch: 'nested_tags',
},
},
organizations: {
type: OpensearchFieldType.OBJECT_ARR,
type: OpensearchFieldType.NESTED,
customTranslation: {
toOpensearch: 'obj_arr_organizations.uuid_id',
fromOpensearch: 'obj_arr_organizations',
toOpensearch: 'nested_organizations.uuid_id',
fromOpensearch: 'nested_organizations',
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion services/libs/types/src/enums/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum OpensearchFieldType {
INT = 'int',
DATE = 'date',
OBJECT = 'obj',
OBJECT_ARR = 'obj_arr',
NESTED = 'nested',
FLOAT = 'float',
BOOL = 'bool',
}
Expand Down