Skip to content

Commit fe15e3e

Browse files
authored
Merge branch 'main' into fix/CM-1999
2 parents 927bc33 + 90965c5 commit fe15e3e

File tree

25 files changed

+314
-277
lines changed

25 files changed

+314
-277
lines changed

backend/src/api/index.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,38 @@ setImmediate(async () => {
168168
next()
169169
})
170170

171+
app.use('/health', async (req: any, res) => {
172+
try {
173+
const seq = SequelizeRepository.getSequelize(req)
174+
175+
const [osPingRes, redisPingRes, dbPingRes, temporalPingRes] = await Promise.all([
176+
// ping opensearch
177+
opensearch.ping().then((res) => res.body),
178+
// ping redis,
179+
redis.ping().then((res) => res === 'PONG'),
180+
// ping database
181+
seq.query('select 1', { type: QueryTypes.SELECT }).then((rows) => rows.length === 1),
182+
// ping temporal
183+
req.temporal
184+
? (req.temporal as TemporalClient).workflowService.getSystemInfo({}).then(() => true)
185+
: Promise.resolve(true),
186+
])
187+
188+
if (osPingRes && redisPingRes && dbPingRes && temporalPingRes) {
189+
res.sendStatus(200)
190+
} else {
191+
res.status(500).json({
192+
opensearch: osPingRes,
193+
redis: redisPingRes,
194+
database: dbPingRes,
195+
temporal: temporalPingRes,
196+
})
197+
}
198+
} catch (err) {
199+
res.status(500).json({ error: err.message, stack: err.stack })
200+
}
201+
})
202+
171203
// Configure the Entity routes
172204
const routes = express.Router()
173205

@@ -207,38 +239,6 @@ setImmediate(async () => {
207239

208240
app.use('/', routes)
209241

210-
app.use('/health', async (req: any, res) => {
211-
try {
212-
const seq = SequelizeRepository.getSequelize(req)
213-
214-
const [osPingRes, redisPingRes, dbPingRes, temporalPingRes] = await Promise.all([
215-
// ping opensearch
216-
opensearch.ping().then((res) => res.body),
217-
// ping redis,
218-
redis.ping().then((res) => res === 'PONG'),
219-
// ping database
220-
seq.query('select 1', { type: QueryTypes.SELECT }).then((rows) => rows.length === 1),
221-
// ping temporal
222-
req.temporal
223-
? (req.temporal as TemporalClient).workflowService.getSystemInfo({}).then(() => true)
224-
: Promise.resolve(true),
225-
])
226-
227-
if (osPingRes && redisPingRes && dbPingRes && temporalPingRes) {
228-
res.sendStatus(200)
229-
} else {
230-
res.status(500).json({
231-
opensearch: osPingRes,
232-
redis: redisPingRes,
233-
database: dbPingRes,
234-
temporal: temporalPingRes,
235-
})
236-
}
237-
} catch (err) {
238-
res.status(500).json({ error: err.message, stack: err.stack })
239-
}
240-
})
241-
242242
app.use(errorMiddleware)
243243
})
244244

backend/src/database/repositories/integrationRepository.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,6 @@ class IntegrationRepository {
137137

138138
// also mark integration runs as deleted
139139
const seq = SequelizeRepository.getSequelize(options)
140-
await seq.query(
141-
`update "integrationRuns" set state = :newState
142-
where "integrationId" = :integrationId and state in (:delayed, :pending, :processing)
143-
`,
144-
{
145-
replacements: {
146-
newState: IntegrationRunState.INTEGRATION_DELETED,
147-
delayed: IntegrationRunState.DELAYED,
148-
pending: IntegrationRunState.PENDING,
149-
processing: IntegrationRunState.PROCESSING,
150-
integrationId: id,
151-
},
152-
transaction,
153-
},
154-
)
155140

156141
await seq.query(
157142
`update integration.runs set state = :newState

backend/src/database/repositories/member/memberOrganizationsRepository.ts

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,68 +19,56 @@ class MemberOrganizationsRepository {
1919
memberId: string,
2020
options: IRepositoryOptions,
2121
): Promise<IRenderFriendlyMemberOrganization[]> {
22-
const transaction = await SequelizeRepository.createTransaction(options)
23-
try {
24-
const txOptions = { ...options, transaction }
25-
const qx = SequelizeRepository.getQueryExecutor(txOptions, transaction)
26-
27-
// Fetch member organizations
28-
const memberOrganizations: IMemberOrganization[] = await fetchMemberOrganizations(
29-
qx,
30-
memberId,
31-
)
32-
33-
// Parse unique organization ids
34-
const orgIds: string[] = [...new Set(memberOrganizations.map((mo) => mo.organizationId))]
35-
36-
// Fetch organizations
37-
let organizations: IOrganizationSummary[] = []
38-
if (orgIds.length) {
39-
organizations = await queryOrgs(qx, {
40-
filter: {
41-
[OrganizationField.ID]: {
42-
in: orgIds,
43-
},
44-
},
45-
fields: [OrganizationField.ID, OrganizationField.DISPLAY_NAME, OrganizationField.LOGO],
46-
})
47-
}
48-
49-
// Fetch affiliation overrides
50-
const affiliationOverrides = await findMemberOrganizationAffiliationOverrides(
51-
qx,
52-
memberId,
53-
memberOrganizations.map((mo) => mo.id),
54-
)
55-
56-
// Create mapping by id to speed up the processing
57-
const orgByid: Record<string, IOrganizationSummary> = organizations.reduce(
58-
(obj: Record<string, IOrganizationSummary>, org) => ({
59-
...obj,
60-
[org.id]: org,
61-
}),
62-
{},
63-
)
64-
65-
// Format the results
66-
const result: IRenderFriendlyMemberOrganization[] = memberOrganizations.map((mo) => ({
67-
...(orgByid[mo.organizationId] || {}),
68-
id: mo.organizationId,
69-
memberOrganizations: {
70-
...mo,
71-
affiliationOverride: affiliationOverrides.find((ao) => ao.memberOrganizationId === mo.id),
72-
},
73-
}))
22+
const qx = SequelizeRepository.getQueryExecutor(options)
7423

75-
await SequelizeRepository.commitTransaction(transaction)
24+
// Fetch member organizations
25+
const memberOrganizations: IMemberOrganization[] = await fetchMemberOrganizations(qx, memberId)
7626

77-
return result
78-
} catch (err) {
79-
if (transaction) {
80-
await SequelizeRepository.rollbackTransaction(transaction)
81-
}
82-
throw err
27+
if (memberOrganizations.length === 0) {
28+
return []
8329
}
30+
31+
// Parse unique organization ids
32+
const orgIds: string[] = [...new Set(memberOrganizations.map((mo) => mo.organizationId))]
33+
34+
// Fetch organizations
35+
let organizations: IOrganizationSummary[] = []
36+
if (orgIds.length) {
37+
organizations = await queryOrgs(qx, {
38+
filter: {
39+
[OrganizationField.ID]: {
40+
in: orgIds,
41+
},
42+
},
43+
fields: [OrganizationField.ID, OrganizationField.DISPLAY_NAME, OrganizationField.LOGO],
44+
})
45+
}
46+
47+
// Fetch affiliation overrides
48+
const affiliationOverrides = await findMemberOrganizationAffiliationOverrides(
49+
qx,
50+
memberId,
51+
memberOrganizations.map((mo) => mo.id),
52+
)
53+
54+
// Create mapping by id to speed up the processing
55+
const orgByid: Record<string, IOrganizationSummary> = organizations.reduce(
56+
(obj: Record<string, IOrganizationSummary>, org) => ({
57+
...obj,
58+
[org.id]: org,
59+
}),
60+
{},
61+
)
62+
63+
// Format the results
64+
return memberOrganizations.map((mo) => ({
65+
...(orgByid[mo.organizationId] || {}),
66+
id: mo.organizationId,
67+
memberOrganizations: {
68+
...mo,
69+
affiliationOverride: affiliationOverrides.find((ao) => ao.memberOrganizationId === mo.id),
70+
},
71+
}))
8472
}
8573

8674
static async create(

backend/src/database/repositories/memberRepository.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,19 +543,14 @@ class MemberRepository {
543543
const tenant = SequelizeRepository.getCurrentTenant(options)
544544

545545
for (const i of identitiesToMove) {
546-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
547-
const { rowCount } = await moveToNewMember(qx, {
546+
await moveToNewMember(qx, {
548547
tenantId: tenant.id,
549548
oldMemberId: fromMemberId,
550549
newMemberId: toMemberId,
551550
platform: i.platform,
552551
value: i.value,
553552
type: i.type,
554553
})
555-
556-
if (rowCount !== 1) {
557-
throw new Error('One row should be updated!')
558-
}
559554
}
560555

561556
if (identitiesToUpdate.length > 0) {

backend/src/database/repositories/organizationRepository.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,6 @@ class OrganizationRepository {
316316
}
317317
}
318318

319-
static findLfxMembershipInFilters(filter: any): any {
320-
if (!filter) return null
321-
322-
if (filter.lfxMembership) {
323-
return filter.lfxMembership
324-
}
325-
326-
if (Array.isArray(filter.and)) {
327-
for (const subFilter of filter.and) {
328-
const result = OrganizationRepository.findLfxMembershipInFilters(subFilter)
329-
if (result) {
330-
return result
331-
}
332-
}
333-
}
334-
335-
return null
336-
}
337-
338319
static convertOrgAttributesForDisplay(attributes: IDbOrgAttribute[]) {
339320
return attributes.reduce((acc, a) => {
340321
if (!acc[a.name]) {
@@ -1615,7 +1596,7 @@ class OrganizationRepository {
16151596
const withAggregates = include.aggregates
16161597

16171598
// look for lfxMembership filter
1618-
const lfxMembershipFilter = OrganizationRepository.findLfxMembershipInFilters(filter)
1599+
const lfxMembershipFilter = filter.and?.find((f) => f.lfxMembership)?.lfxMembership
16191600
let lfxMembershipFilterWhereClause = ''
16201601

16211602
if (lfxMembershipFilter) {
@@ -1627,8 +1608,14 @@ class OrganizationRepository {
16271608
}
16281609

16291610
// remove lfxMembership filter from obj since filterParser doesn't support it
1630-
filter.and = filter.and.filter((f) => !f.and?.some((subF) => subF.lfxMembership))
1611+
filter.and = filter.and.filter((f) => !f.lfxMembership)
1612+
1613+
// handle edge case where filter.and is empty
1614+
if (filter.and.length === 0) {
1615+
delete filter.and
1616+
}
16311617
}
1618+
16321619
if (segmentId) {
16331620
const segment = (await findSegmentById(optionsQx(options), segmentId)) as any
16341621

backend/src/services/memberOrganizationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default class MemberOrganizationService extends LoggerBase {
101101
(m) => mergeStrat.entityId(m) === secondaryId,
102102
)
103103

104-
this.mergeRoles(primaryRoles, secondaryRoles, mergeStrat)
104+
await this.mergeRoles(primaryRoles, secondaryRoles, mergeStrat)
105105

106106
// update rest of the o2 members
107107
const remainingRoles = await MemberOrganizationRepository.findNonIntersectingRoles(

backend/src/services/memberService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,20 +1272,20 @@ export default class MemberService extends LoggerBase {
12721272
},
12731273
}
12741274

1275+
const repoOptions: IRepositoryOptions =
1276+
await SequelizeRepository.createTransactionalRepositoryOptions(this.options)
1277+
tx = repoOptions.transaction
1278+
12751279
await MergeActionsRepository.add(
12761280
MergeActionType.MEMBER,
12771281
originalId,
12781282
toMergeId,
1279-
this.options,
1283+
repoOptions,
12801284
MergeActionStep.MERGE_STARTED,
12811285
MergeActionState.IN_PROGRESS,
12821286
backup,
12831287
)
12841288

1285-
const repoOptions: IRepositoryOptions =
1286-
await SequelizeRepository.createTransactionalRepositoryOptions(this.options)
1287-
tx = repoOptions.transaction
1288-
12891289
const identitiesToUpdate = []
12901290
const identitiesToMove = []
12911291
for (const identity of toMergeIdentities) {

backend/src/services/searchSyncService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class SearchSyncService extends LoggerBase {
4848
return process()
4949
}
5050

51-
async triggerMemberSync(tenantId: string, memberId: string, opts: { withAggs?: boolean } = {}) {
51+
async triggerMemberSync(tenantId: string, memberId: string, opts?: { withAggs?: boolean }) {
5252
const client = await this.getSearchSyncClient()
5353

5454
if (client instanceof SearchSyncApiClient) {

frontend/src/modules/contributor/components/shared/contributor-work-position.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { storeToRefs } from 'pinia';
4141
import LfAvatar from '@/ui-kit/avatar/Avatar.vue';
4242
import LfIcon from '@/ui-kit/icon/Icon.vue';
4343
import { Contributor } from '@/modules/contributor/types/Contributor';
44+
import useContributorHelpers from '@/modules/contributor/helpers/contributor.helpers';
4445
4546
const props = defineProps<{
4647
contributor: Contributor,
@@ -49,7 +50,9 @@ const props = defineProps<{
4950
const lsSegmentsStore = useLfSegmentsStore();
5051
const { selectedProjectGroup } = storeToRefs(lsSegmentsStore);
5152
52-
const organization = computed(() => props.contributor.organizations?.[0]);
53+
const { activeOrganization } = useContributorHelpers();
54+
55+
const organization = computed(() => activeOrganization(props.contributor));
5356
const jobTitle = computed(() => organization.value?.memberOrganizations?.title
5457
|| props.contributor.attributes?.jobTitle?.default);
5558
</script>

frontend/src/modules/contributor/helpers/contributor.helpers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ const useContributorHelpers = () => {
6666
}));
6767
};
6868

69-
const activeOrganization = (contributor: Contributor) => contributor.organizations?.[0];
69+
const activeOrganization = (contributor: Contributor) => {
70+
const { organizations } = contributor;
71+
console.log(organizations);
72+
return organizations.find((org) => org.memberOrganizations.affiliationOverride?.isPrimaryWorkExperience
73+
&& !!org.memberOrganizations.dateStart
74+
&& !org.memberOrganizations.dateEnd)
75+
|| organizations.find((org) => !!org.memberOrganizations.dateStart && !org.memberOrganizations.dateEnd)
76+
|| organizations.find((org) => !org.memberOrganizations.dateStart && !org.memberOrganizations.dateEnd) || null;
77+
};
7078

7179
return {
7280
avatar,

0 commit comments

Comments
 (0)