Skip to content

Commit a84ae1e

Browse files
committed
changes to custom event type in analytics to return array of custom event types instead of one
1 parent 8410f69 commit a84ae1e

7 files changed

Lines changed: 1740 additions & 4786 deletions

File tree

‎packages/analytics-service/src/modules/analytics/analytics.controller.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AnalyticsController
3535

3636
async getCustomEventTypes(
3737
request: AnalyticsProto.CustomEventTypeRequest,
38-
): Promise<AnalyticsProto.CustomEventTypeResponse> {
38+
): Promise<AnalyticsProto.GetAllCustomEventTypeResponse> {
3939
return await this.analyticsService.getCustomEventTypes(request);
4040
}
4141

‎packages/analytics-service/src/modules/analytics/analytics.service.ts‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class AnalyticsService implements OnModuleInit {
320320

321321
async getCustomEventTypes(
322322
request: AnalyticsProto.CustomEventTypeRequest,
323-
): Promise<AnalyticsProto.CustomEventTypeResponse> {
323+
): Promise<AnalyticsProto.GetAllCustomEventTypeResponse> {
324324
// TODO: environments
325325
const viewer = await this.getAnalyticsViewer(
326326
this.EventEnvironment.DEVELOPMENT,
@@ -339,23 +339,18 @@ export class AnalyticsService implements OnModuleInit {
339339

340340
if (!response || response.length === 0) {
341341
return {
342-
id: '',
343-
category: '',
344-
subcategory: '',
345-
properties: [],
346-
projectId: '',
342+
eventTypes: [],
347343
};
348344
}
349345

350-
// TODO: This should not return only the first type
351-
// Return the first custom event type for now
352-
const eventType = response[0];
353346
return {
354-
id: eventType._id || '',
355-
category: eventType.category,
356-
subcategory: eventType.subcategory,
357-
properties: eventType.properties,
358-
projectId: eventType.projectId,
347+
eventTypes: response.map((eventType) => ({
348+
id: eventType._id,
349+
category: eventType.category,
350+
subcategory: eventType.subcategory,
351+
properties: [...eventType.properties],
352+
projectId: eventType.projectId,
353+
})),
359354
};
360355
}
361356

‎packages/api-gateway/src/models/analytics.dto.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ export class CustomEventTypeResponse {
454454
}
455455
}
456456

457+
export class GetAllCustomEventTypeResponse {
458+
@ApiProperty({
459+
type: [CustomEventTypeResponse],
460+
description: 'All custom event types',
461+
})
462+
eventTypes: CustomEventTypeResponse[];
463+
464+
constructor(response: AnalyticsProto.GetAllCustomEventTypeResponse) {
465+
if (!response || !response.eventTypes) {
466+
return;
467+
}
468+
469+
this.eventTypes = response.eventTypes.map(
470+
(eventType) => new CustomEventTypeResponse(eventType),
471+
);
472+
}
473+
}
474+
457475
export class CustomGraphType {
458476
@ApiProperty({ type: 'string', description: 'Graph ID' })
459477
id: string;

‎packages/api-gateway/src/modules/analytics/analytics.controller.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
VisitEventResponse,
3939
InputEventResponse,
4040
CustomEventResponse,
41-
CustomEventTypeResponse,
4241
CustomGraphTypeResponse,
4342
GetClickEventsResponse,
4443
GetVisitEventsResponse,
@@ -48,6 +47,7 @@ import {
4847
GetAllVisitEventsResponse,
4948
GetAllInputEventsResponse,
5049
GetAllCustomEventsResponse,
50+
GetAllCustomEventTypeResponse,
5151
} from 'src/models/analytics.dto';
5252

5353
const { ANALYTICS_SERVICE_NAME } = AnalyticsProto;
@@ -183,15 +183,15 @@ export class AnalyticsController implements OnModuleInit {
183183
@ApiOperation({ summary: 'Get custom event types for a project' })
184184
@ApiOkResponse({
185185
description: 'Custom event types retrieved successfully',
186-
type: CustomEventTypeResponse,
186+
type: GetAllCustomEventTypeResponse,
187187
})
188188
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
189189
@ApiBadRequestResponse({ description: 'Bad Request' })
190190
@ApiQuery({ name: 'projectName', type: String, description: 'Project name' })
191191
async getCustomEventTypes(
192192
@ApiKey() apiKey: AuthCommonProto.ApiKey,
193193
@Query() query: GetCustomEventTypesQuery,
194-
): Promise<CustomEventTypeResponse> {
194+
): Promise<GetAllCustomEventTypeResponse> {
195195
await validateOrReject(query);
196196

197197
const response = await lastValueFrom(
@@ -202,7 +202,7 @@ export class AnalyticsController implements OnModuleInit {
202202
}),
203203
);
204204

205-
return new CustomEventTypeResponse(response);
205+
return new GetAllCustomEventTypeResponse(response);
206206
}
207207

208208
@Get('custom-graph-types')

‎packages/proto/definitions/analytics.proto‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ service AnalyticsService {
1010
rpc logCustomEvent(CustomEventRequest) returns (CustomEventResponse);
1111

1212
// AnalyticsViewer methods
13-
rpc getCustomEventTypes(CustomEventTypeRequest) returns (CustomEventTypeResponse);
13+
rpc getCustomEventTypes(CustomEventTypeRequest) returns (GetAllCustomEventTypeResponse);
1414
rpc getCustomGraphTypesById(CustomGraphTypeRequest) returns (CustomGraphTypeResponse);
1515
rpc getClickEventsPaginated(GetClickEventsRequest) returns (GetClickEventsResponse);
1616
rpc getAllClickEvents(GetAllClickEventsRequest) returns (GetAllClickEventsResponse);
@@ -245,6 +245,10 @@ message CustomEventTypeResponse {
245245
string project_id = 5;
246246
}
247247

248+
message GetAllCustomEventTypeResponse {
249+
repeated CustomEventTypeResponse eventTypes = 1;
250+
}
251+
248252
message CustomGraphTypeResponse {
249253
repeated CustomGraphType graphs = 1;
250254
}

‎packages/proto/src/gen/analytics.ts‎

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)