From 391ea6d9f65b7705b2ab52ccf7b95e0322a4de9b Mon Sep 17 00:00:00 2001 From: Hikari Date: Fri, 20 Feb 2026 00:04:35 -0800 Subject: [PATCH] fix: use ActivityType enum values instead of string literals Changed all activity type assignments to use ActivityType enum members (ActivityType.suggestion, ActivityType.like, etc.) instead of string literals ('SUGGESTION', 'LIKE', etc.) to ensure proper type discrimination in the union type. Frontend: - Import ActivityType as value (not just type) - Update switch cases to use enum members - Expose ActivityType in component for template access Backend: - Import ActivityType as value - Use enum members in all activity mappings This ensures TypeScript can properly discriminate the union type and provides type safety throughout the activity feed. --- api/src/app/services/activity.service.ts | 11 +++++------ .../components/activity/activity-feed.component.ts | 14 +++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/api/src/app/services/activity.service.ts b/api/src/app/services/activity.service.ts index 28a9941..b1a8178 100644 --- a/api/src/app/services/activity.service.ts +++ b/api/src/app/services/activity.service.ts @@ -7,10 +7,9 @@ import type { Activity, ActivityFeedResponse, - ActivityType, ActivityUser, } from "@library/shared-types"; -import { ACHIEVEMENTS } from "@library/shared-types"; +import { ACHIEVEMENTS, ActivityType } from "@library/shared-types"; import { prisma } from "../lib/prisma"; export class ActivityService { @@ -89,7 +88,7 @@ export class ActivityService { return suggestions.map((suggestion) => ({ id: `suggestion-${suggestion.id}`, - type: "SUGGESTION" as const, + type: ActivityType.suggestion, user: suggestion.user as ActivityUser, entityType: suggestion.entityType, suggestionTitle: suggestion.title, @@ -139,7 +138,7 @@ export class ActivityService { ); return { id: `like-${like.id}`, - type: "LIKE" as const, + type: ActivityType.like, user: like.user as ActivityUser, entityType: like.entityType, entityId: like.entityId, @@ -229,7 +228,7 @@ export class ActivityService { return { id: `comment-${comment.id}`, - type: "COMMENT" as const, + type: ActivityType.comment, user: comment.user as ActivityUser, entityType, entityId, @@ -282,7 +281,7 @@ export class ActivityService { const achievement = ACHIEVEMENTS[ua.achievementKey]; return { id: `achievement-${ua.id}`, - type: "ACHIEVEMENT" as const, + type: ActivityType.achievement, user: ua.user as ActivityUser, achievementKey: ua.achievementKey, achievementName: achievement.title, diff --git a/apps/frontend/src/app/components/activity/activity-feed.component.ts b/apps/frontend/src/app/components/activity/activity-feed.component.ts index c2a61c3..3b07983 100644 --- a/apps/frontend/src/app/components/activity/activity-feed.component.ts +++ b/apps/frontend/src/app/components/activity/activity-feed.component.ts @@ -7,7 +7,8 @@ import { Component, OnInit, inject, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterLink } from '@angular/router'; -import type { Activity, ActivityType } from '@library/shared-types'; +import type { Activity } from '@library/shared-types'; +import { ActivityType } from '@library/shared-types'; import { ActivityService } from '../../services/activity.service'; @Component({ @@ -64,7 +65,7 @@ import { ActivityService } from '../../services/activity.service';
@switch (activity.type) { - @case ('SUGGESTION') { + @case (ActivityType.suggestion) {
💡 @@ -76,7 +77,7 @@ import { ActivityService } from '../../services/activity.service';
} - @case ('LIKE') { + @case (ActivityType.like) {
❤️ @@ -87,7 +88,7 @@ import { ActivityService } from '../../services/activity.service';
} - @case ('COMMENT') { + @case (ActivityType.comment) {
💬 @@ -99,7 +100,7 @@ import { ActivityService } from '../../services/activity.service';

"{{ activity.commentPreview }}"

} - @case ('ACHIEVEMENT') { + @case (ActivityType.achievement) {
{{ activity.achievementIcon }} @@ -360,6 +361,9 @@ import { ActivityService } from '../../services/activity.service'; export class ActivityFeedComponent implements OnInit { private activityService = inject(ActivityService); + // Make ActivityType accessible in template + ActivityType = ActivityType; + activities = signal([]); loading = signal(true); loadingMore = signal(false);