Skip to content

Commit 86697b9

Browse files
committed
Removed duplicate CBBRs
1 parent 6063cea commit 86697b9

1 file changed

Lines changed: 42 additions & 42 deletions

File tree

src/community-board-budget-request/community-board-budget-request.repository.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,17 @@ export class CommunityBoardBudgetRequestRepository {
321321
buffer: number;
322322
}): Promise<FindManyRepo> {
323323
try {
324-
return await this.db
325-
.select({
326-
id: communityBoardBudgetRequest.id,
327-
cbbrPolicyAreaId: communityBoardBudgetRequest.policyArea,
328-
title: communityBoardBudgetRequest.title,
329-
communityBoardId: sql<string>`${borough.abbr} || ${communityBoardBudgetRequest.communityDistrictId}`,
330-
isMapped: sql<boolean>`${or(
331-
isNotNull(communityBoardBudgetRequest.liFtMPnt),
332-
isNotNull(communityBoardBudgetRequest.liFtMPoly),
333-
)}`,
334-
isContinuedSupport: communityBoardBudgetRequest.isContinuedSupport,
335-
})
324+
return await this.db[geom === null ? "selectDistinct" : "select"]({
325+
id: communityBoardBudgetRequest.id,
326+
cbbrPolicyAreaId: communityBoardBudgetRequest.policyArea,
327+
title: communityBoardBudgetRequest.title,
328+
communityBoardId: sql<string>`${borough.abbr} || ${communityBoardBudgetRequest.communityDistrictId}`,
329+
isMapped: sql<boolean>`${or(
330+
isNotNull(communityBoardBudgetRequest.liFtMPnt),
331+
isNotNull(communityBoardBudgetRequest.liFtMPoly),
332+
)}`,
333+
isContinuedSupport: communityBoardBudgetRequest.isContinuedSupport,
334+
})
336335
.from(communityBoardBudgetRequest)
337336
.leftJoin(
338337
borough,
@@ -419,11 +418,12 @@ export class CommunityBoardBudgetRequestRepository {
419418
.limit(limit)
420419
.offset(offset)
421420
.orderBy(
422-
sql`CASE
421+
geom !== null
422+
? sql`CASE
423423
WHEN ${geom !== null && isNotNull(communityBoardBudgetRequest.liFtMPnt)} THEN ${geom} <-> ${communityBoardBudgetRequest.liFtMPnt}
424424
WHEN ${geom !== null && isNotNull(communityBoardBudgetRequest.liFtMPoly)} THEN ${geom} <-> ${communityBoardBudgetRequest.liFtMPoly}
425-
END`,
426-
communityBoardBudgetRequest.id,
425+
END`
426+
: communityBoardBudgetRequest.id,
427427
);
428428
} catch {
429429
throw new DataRetrievalException(
@@ -632,30 +632,29 @@ export class CommunityBoardBudgetRequestRepository {
632632
buffer: number;
633633
}): Promise<FindCsvRepo> {
634634
try {
635-
return await this.db
636-
.select({
637-
id: communityBoardBudgetRequest.id,
638-
communityBoardId: sql<string>`${borough.abbr} || ${communityBoardBudgetRequest.communityDistrictId}`,
639-
address: communityBoardBudgetRequest.address,
640-
siteName: communityBoardBudgetRequest.siteName,
641-
segmentOnStreet: communityBoardBudgetRequest.segmentOnStreet,
642-
segmentCrossStreetOne:
643-
communityBoardBudgetRequest.segmentCrossStreetOne,
644-
segmentCrossStreetTwo:
645-
communityBoardBudgetRequest.segmentCrossStreetTwo,
646-
intersectionStreetOne:
647-
communityBoardBudgetRequest.intersectionStreetOne,
648-
intersectionStreetTwo:
649-
communityBoardBudgetRequest.intersectionStreetTwo,
650-
requestType: sql<string>`SUBSTRING(${communityBoardBudgetRequest.requestType}, 1, 1)`,
651-
isContinuedSupport: communityBoardBudgetRequest.isContinuedSupport,
652-
request: cbbrRequest.description,
653-
explanation: communityBoardBudgetRequest.explanation,
654-
agency: communityBoardBudgetRequest.agency,
655-
priority: communityBoardBudgetRequest.priority,
656-
agencyCategoryResponse: cbbrAgencyCategoryResponse.description,
657-
agencyResponse: communityBoardBudgetRequest.agencyResponse,
658-
})
635+
return await this.db[geom === null ? "selectDistinct" : "select"]({
636+
id: communityBoardBudgetRequest.id,
637+
communityBoardId: sql<string>`${borough.abbr} || ${communityBoardBudgetRequest.communityDistrictId}`,
638+
address: communityBoardBudgetRequest.address,
639+
siteName: communityBoardBudgetRequest.siteName,
640+
segmentOnStreet: communityBoardBudgetRequest.segmentOnStreet,
641+
segmentCrossStreetOne:
642+
communityBoardBudgetRequest.segmentCrossStreetOne,
643+
segmentCrossStreetTwo:
644+
communityBoardBudgetRequest.segmentCrossStreetTwo,
645+
intersectionStreetOne:
646+
communityBoardBudgetRequest.intersectionStreetOne,
647+
intersectionStreetTwo:
648+
communityBoardBudgetRequest.intersectionStreetTwo,
649+
requestType: sql<string>`SUBSTRING(${communityBoardBudgetRequest.requestType}, 1, 1)`,
650+
isContinuedSupport: communityBoardBudgetRequest.isContinuedSupport,
651+
request: cbbrRequest.description,
652+
explanation: communityBoardBudgetRequest.explanation,
653+
agency: communityBoardBudgetRequest.agency,
654+
priority: communityBoardBudgetRequest.priority,
655+
agencyCategoryResponse: cbbrAgencyCategoryResponse.description,
656+
agencyResponse: communityBoardBudgetRequest.agencyResponse,
657+
})
659658
.from(communityBoardBudgetRequest)
660659
.leftJoin(
661660
borough,
@@ -751,11 +750,12 @@ export class CommunityBoardBudgetRequestRepository {
751750
),
752751
)
753752
.orderBy(
754-
sql`CASE
753+
geom !== null
754+
? sql`CASE
755755
WHEN ${geom !== null && isNotNull(communityBoardBudgetRequest.liFtMPnt)} THEN ${geom} <-> ${communityBoardBudgetRequest.liFtMPnt}
756756
WHEN ${geom !== null && isNotNull(communityBoardBudgetRequest.liFtMPoly)} THEN ${geom} <-> ${communityBoardBudgetRequest.liFtMPoly}
757-
END`,
758-
communityBoardBudgetRequest.id,
757+
END`
758+
: communityBoardBudgetRequest.id,
759759
);
760760
} catch {
761761
throw new DataRetrievalException(

0 commit comments

Comments
 (0)