Skip to content

Commit f561903

Browse files
committed
fix: resolve location for opportunity only by country for now
1 parent 680ca59 commit f561903

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/entity/dataset/utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ export const createLocationFromMapbox = async (
2626
*/
2727
export const findDatasetLocation = async (
2828
con: DataSource,
29-
locationData: {
30-
iso2?: string | null;
31-
},
29+
locationData: Partial<Pick<DatasetLocation, 'iso2' | 'city' | 'subdivision'>>,
3230
): Promise<DatasetLocation | null> => {
3331
const { iso2 } = locationData;
3432

3533
if (!iso2) {
3634
return null;
3735
}
3836

39-
const repo = con.manager.getRepository(DatasetLocation);
37+
const locationQuery = con.manager
38+
.getRepository(DatasetLocation)
39+
.createQueryBuilder()
40+
.where('iso2 = :iso2Only', { iso2Only: iso2 })
41+
.andWhere('city IS NULL')
42+
.andWhere('subdivision IS NULL');
4043

41-
// Find location by iso2 country code
42-
const location = await repo.findOne({
43-
where: { iso2: iso2.toUpperCase() },
44-
});
44+
const location = await locationQuery.getOne();
4545

4646
return location;
4747
};

src/schema/opportunity.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,10 +2756,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
27562756
const opportunityContent = new OpportunityContent(renderedContent);
27572757

27582758
// Extract and process locations
2759-
const locationData = (parsedOpportunity.location || []) as Array<{
2760-
iso2?: string;
2761-
type?: number;
2762-
}>;
2759+
const locationData = parsedOpportunity.location || [];
27632760

27642761
const opportunityResult = await ctx.con.transaction(
27652762
async (entityManager) => {
@@ -2788,9 +2785,7 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
27882785

27892786
// Create OpportunityLocation entries for each location
27902787
for (const loc of locationData) {
2791-
const datasetLocation = await findDatasetLocation(ctx.con, {
2792-
iso2: loc.iso2,
2793-
});
2788+
const datasetLocation = await findDatasetLocation(ctx.con, loc);
27942789

27952790
if (datasetLocation) {
27962791
await entityManager.getRepository(OpportunityLocation).save({

0 commit comments

Comments
 (0)