Skip to content

Commit a18fa84

Browse files
fix: remove duplicate handleOpportunityKeywordsUpdate function
- Export handleOpportunityKeywordsUpdate from parse.ts - Remove duplicate implementation from opportunity.ts - Add best practices section to AGENTS.md about avoiding duplication Co-authored-by: Ido Shamun <idoshamun@users.noreply.github.com>
1 parent f21012d commit a18fa84

3 files changed

Lines changed: 10 additions & 26 deletions

File tree

AGENTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ This file provides guidance to coding agents when working with code in this repo
105105
- `.infra/common.ts` - Worker subscription definitions
106106
- `.infra/index.ts` - Main Pulumi deployment configuration
107107

108+
## Best Practices & Lessons Learned
109+
110+
**Avoiding Code Duplication:**
111+
- **Always check for existing implementations** before creating new helper functions. Use Grep or Glob tools to search for similar function names or logic patterns across the codebase.
112+
- **Prefer extracting to common utilities** when logic needs to be shared. Place shared helpers in appropriate `src/common/` subdirectories (e.g., `src/common/opportunity/` for opportunity-related helpers).
113+
- **Export and import, don't duplicate**: When you need the same logic in multiple places, export the function from its original location and import it where needed. This ensures a single source of truth and prevents maintenance issues.
114+
- **Example lesson**: When implementing `handleOpportunityKeywordsUpdate`, the function was duplicated in both `src/common/opportunity/parse.ts` and `src/schema/opportunity.ts`. This caused lint failures and maintenance burden. The correct approach was to export it from `parse.ts` and import it in `opportunity.ts`.
115+
108116
## Pull Requests
109117

110118
Keep PR descriptions concise and to the point. Reviewers should not be exhausted by lengthy explanations.

src/common/opportunity/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export interface UpdateOpportunityContext {
368368
* Handles opportunity keywords updates
369369
* Replaces all existing keywords with the new set
370370
*/
371-
async function handleOpportunityKeywordsUpdate(
371+
export async function handleOpportunityKeywordsUpdate(
372372
entityManager: EntityManager,
373373
opportunityId: string,
374374
keywords: Array<{ keyword: string }> | undefined,

src/schema/opportunity.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import {
103103
parseOpportunityWithBrokkr,
104104
createOpportunityFromParsedData,
105105
updateOpportunityFromParsedData,
106+
handleOpportunityKeywordsUpdate,
106107
} from '../common/opportunity/parse';
107108
import {
108109
isMockEnabled,
@@ -1115,31 +1116,6 @@ async function handleOpportunityLocationUpdate(
11151116
}
11161117
}
11171118

1118-
/**
1119-
* Handles opportunity keywords updates
1120-
* Replaces all existing keywords with the new set
1121-
*/
1122-
async function handleOpportunityKeywordsUpdate(
1123-
entityManager: EntityManager,
1124-
opportunityId: string,
1125-
keywords: Array<{ keyword: string }> | undefined,
1126-
): Promise<void> {
1127-
if (!Array.isArray(keywords)) {
1128-
return;
1129-
}
1130-
1131-
await entityManager.getRepository(OpportunityKeyword).delete({
1132-
opportunityId,
1133-
});
1134-
1135-
await entityManager.getRepository(OpportunityKeyword).insert(
1136-
keywords.map((keyword) => ({
1137-
opportunityId,
1138-
keyword: keyword.keyword,
1139-
})),
1140-
);
1141-
}
1142-
11431119
/**
11441120
* Handles opportunity screening questions updates
11451121
* Validates questions ownership and upserts them with proper ordering

0 commit comments

Comments
 (0)