@@ -10,7 +10,7 @@ export interface IAffiliationPeriod {
1010 endDate : string | null
1111}
1212
13- interface IWorkExperience {
13+ interface IWorkExperienceResolution {
1414 id : string
1515 memberId : string
1616 organizationId : string
@@ -31,8 +31,8 @@ interface IWorkExperience {
3131export async function findWorkExperiencesBulk (
3232 qx : QueryExecutor ,
3333 memberIds : string [ ] ,
34- ) : Promise < IWorkExperience [ ] > {
35- const rows : IWorkExperience [ ] = await qx . select (
34+ ) : Promise < IWorkExperienceResolution [ ] > {
35+ const rows : IWorkExperienceResolution [ ] = await qx . select (
3636 `
3737 WITH relevant_orgs AS (
3838 SELECT DISTINCT "organizationId"
@@ -78,7 +78,7 @@ export async function findWorkExperiencesBulk(
7878export async function findManualAffiliationsBulk (
7979 qx : QueryExecutor ,
8080 memberIds : string [ ] ,
81- ) : Promise < IWorkExperience [ ] > {
81+ ) : Promise < IWorkExperienceResolution [ ] > {
8282 return qx . select (
8383 `
8484 SELECT
@@ -101,7 +101,7 @@ export async function findManualAffiliationsBulk(
101101 )
102102}
103103
104- function selectPrimaryWorkExperience ( orgs : IWorkExperience [ ] ) {
104+ function selectPrimaryWorkExperience ( orgs : IWorkExperienceResolution [ ] ) {
105105 if ( orgs . length === 1 ) return orgs [ 0 ]
106106
107107 // 1. Manual affiliations (segmentId non-null) always win
@@ -110,7 +110,7 @@ function selectPrimaryWorkExperience(orgs: IWorkExperience[]) {
110110 if ( manual . length === 1 ) return manual [ 0 ]
111111 return getLongestDateRange (
112112 manual as unknown as IMemberOrganization [ ] ,
113- ) as unknown as IWorkExperience
113+ ) as unknown as IWorkExperienceResolution
114114 }
115115
116116 // 2. isPrimaryWorkExperience = true — prefer those with a dateStart
@@ -128,11 +128,13 @@ function selectPrimaryWorkExperience(orgs: IWorkExperience[]) {
128128 }
129129
130130 // 5. Longest date range as final tiebreaker
131- return getLongestDateRange ( orgs as unknown as IMemberOrganization [ ] ) as unknown as IWorkExperience
131+ return getLongestDateRange (
132+ orgs as unknown as IMemberOrganization [ ] ,
133+ ) as unknown as IWorkExperienceResolution
132134}
133135
134136/** Returns the org used to fill gaps — primary undated wins, then earliest-created undated. */
135- function findFallbackOrg ( rows : IWorkExperience [ ] ) : IWorkExperience | null {
137+ function findFallbackOrg ( rows : IWorkExperienceResolution [ ] ) : IWorkExperienceResolution | null {
136138 const primaryUndated = rows . find ( ( r ) => r . isPrimaryWorkExperience && ! r . dateStart && ! r . dateEnd )
137139 if ( primaryUndated ) return primaryUndated
138140
@@ -148,7 +150,7 @@ function findFallbackOrg(rows: IWorkExperience[]): IWorkExperience | null {
148150 * Collects all date boundaries from the dated rows, capped at today.
149151 * Each dateStart and (dateEnd + 1 day) marks a point where active orgs can change.
150152 */
151- function collectBoundaries ( datedRows : IWorkExperience [ ] ) : Date [ ] {
153+ function collectBoundaries ( datedRows : IWorkExperienceResolution [ ] ) : Date [ ] {
152154 const today = startOfDay ( new Date ( ) )
153155
154156 const ms = new Set < number > ( [ today . getTime ( ) ] )
@@ -169,7 +171,10 @@ function collectBoundaries(datedRows: IWorkExperience[]): Date[] {
169171 . map ( ( t ) => new Date ( t ) )
170172}
171173
172- function orgsActiveAt ( rows : IWorkExperience [ ] , boundaryDate : Date ) : IWorkExperience [ ] {
174+ function orgsActiveAt (
175+ rows : IWorkExperienceResolution [ ] ,
176+ boundaryDate : Date ,
177+ ) : IWorkExperienceResolution [ ] {
173178 return rows . filter ( ( role ) => {
174179 if ( ! role . dateStart && ! role . dateEnd ) return true // truly undated: active at every boundary
175180
@@ -195,12 +200,12 @@ function dayBefore(date: Date): Date {
195200
196201/** Iterates boundary intervals and builds non-overlapping affiliation windows. */
197202function buildTimeline (
198- allRows : IWorkExperience [ ] ,
199- fallbackOrg : IWorkExperience | null ,
203+ allRows : IWorkExperienceResolution [ ] ,
204+ fallbackOrg : IWorkExperienceResolution | null ,
200205 boundaries : Date [ ] ,
201206) : IAffiliationPeriod [ ] {
202207 const affiliations : IAffiliationPeriod [ ] = [ ]
203- let currentOrg : IWorkExperience = null
208+ let currentOrg : IWorkExperienceResolution = null
204209 let currentWindowStart : Date = null
205210 let uncoveredPeriodStart : Date = null
206211
@@ -281,7 +286,7 @@ function buildTimeline(
281286 return affiliations
282287}
283288
284- function resolveAffiliationsForMember ( rows : IWorkExperience [ ] ) : IAffiliationPeriod [ ] {
289+ function resolveAffiliationsForMember ( rows : IWorkExperienceResolution [ ] ) : IAffiliationPeriod [ ] {
285290 // If one undated work-experience org is marked primary, drop other undated work-experience orgs
286291 // to avoid infinite conflicts. Manual affiliations (segmentId !== null) are never dropped.
287292 const primaryUndated = rows . find ( ( r ) => r . isPrimaryWorkExperience && ! r . dateStart && ! r . dateEnd )
@@ -320,7 +325,7 @@ export async function resolveAffiliationsByMemberIds(
320325 findManualAffiliationsBulk ( qx , memberIds ) ,
321326 ] )
322327
323- const byMember = new Map < string , IWorkExperience [ ] > ( )
328+ const byMember = new Map < string , IWorkExperienceResolution [ ] > ( )
324329 for ( const row of [ ...workExperiences , ...manualAffiliations ] ) {
325330 const list = byMember . get ( row . memberId ) ?? [ ]
326331 list . push ( row )
0 commit comments