Skip to content

Commit 29cabbb

Browse files
committed
fix: resolve pr review comments
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent c75f20a commit 29cabbb

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

backend/src/middlewares/segmentMiddleware.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ export async function segmentMiddleware(req: Request, _res: Response, next: Next
99
const options = req as unknown as IRepositoryOptions
1010
const segmentRepository = new SegmentRepository(options)
1111

12-
// Query parameters take precedence; request body acts as the fallback.
13-
const rawSegments = req.query.segments ?? (req.body as Record<string, unknown>)?.segments
12+
const querySegments = toStringArray(req.query.segments)
13+
const bodySegments = toStringArray((req.body as Record<string, unknown>)?.segments)
1414

15-
// Express can parse segments as a single string or an array (?segments=a vs ?segments=a&segments=b).
16-
// Normalize into a clean, flat array of non-empty strings.
17-
const segmentIds = toStringArray(rawSegments)
15+
const segmentIds = querySegments.length > 0 ? querySegments : bodySegments
1816

1917
if (segmentIds.length > 0) {
2018
options.currentSegments = await segmentRepository.findInIds(segmentIds)
2119
} else {
22-
// No segmentIds in the request — use the first subproject as the default
2320
const { rows } = await segmentRepository.querySubprojects({ limit: 1, offset: 0 })
2421
options.currentSegments = rows
2522
}

backend/src/services/activityService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ export default class ActivityService extends LoggerBase {
124124

125125
const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)
126126

127+
if (subprojectIds.length === 0) {
128+
return {
129+
count: 0,
130+
rows: [],
131+
limit,
132+
offset,
133+
}
134+
}
135+
127136
const activitiyTypes = SegmentRepository.getActivityTypes(this.options)
128137

129138
const page = await queryActivities(

backend/src/services/segmentService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,12 @@ export default class SegmentService extends LoggerBase {
554554
return getSegmentSubprojects(qx, segments)
555555
}
556556

557-
static getTenantActivityTypes(subprojects: any): ActivityTypeSettings {
557+
static getTenantActivityTypes(
558+
subprojects: Array<SegmentData | SegmentRawData>,
559+
): ActivityTypeSettings {
558560
return subprojects.reduce(
559561
(acc: ActivityTypeSettings, subproject) => {
560-
const activityTypes = buildSegmentActivityTypes(subproject)
562+
const activityTypes = buildSegmentActivityTypes(subproject as SegmentRawData)
561563

562564
return {
563565
custom: {

services/libs/data-access-layer/src/segments/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ export async function getSegmentSubprojects(
198198
join segment_level sl on (sl.level = 'child' and s.id = sl.id)
199199
or (sl.level = 'parent' and s."parentSlug" = sl.slug and s."grandparentSlug" is not null)
200200
or (sl.level = 'grandparent' and s."grandparentSlug" = sl.slug)
201-
where status = 'active';
201+
where status = 'active'
202+
and s."tenantId" = $(tenantId);
202203
`,
203204
{
204205
tenantId: DEFAULT_TENANT_ID,

0 commit comments

Comments
 (0)