feat: implement user profiles with achievements and primary badge system #58

Merged
naomi merged 17 commits from feat/user-profiles into main 2026-02-19 22:21:18 -08:00
6 changed files with 150 additions and 11 deletions
Showing only changes of commit 6e884b9ae8 - Show all commits
+1 -1
View File
@@ -376,7 +376,7 @@ model ProfileReport {
model CommentReport {
id String @id @default(auto()) @map("_id") @db.ObjectId
reportedCommentId String @db.ObjectId
reportedComment Comment @relation(fields: [reportedCommentId], references: [id])
reportedComment Comment @relation(fields: [reportedCommentId], references: [id], onDelete: Cascade)
reporterId String @db.ObjectId
reporter User @relation("CommentReporter", fields: [reporterId], references: [id])
reason ReportReason
+72
View File
@@ -0,0 +1,72 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { FastifyPluginAsync } from "fastify";
import { Comment, AuditAction, AuditCategory } from "@library/shared-types";
import { CommentService } from "../../services/comment.service";
import { AuditService } from "../../services/audit.service";
import { adminGuard } from "../../middleware/admin-guard";
interface UpdateCommentBody {
content: string;
}
const commentsRoutes: FastifyPluginAsync = async (app) => {
const commentService = new CommentService();
// Admin: Update any comment by ID
app.put<{ Params: { id: string }; Body: UpdateCommentBody; Reply: Comment | { error: string } }>(
"/:id",
{
preValidation: [app.authenticate, adminGuard],
preHandler: [app.csrfProtection],
},
async (request, reply) => {
const { id } = request.params;
const { content } = request.body;
const existingComment = await commentService.getCommentById(id);
if (!existingComment) {
return reply.code(404).send({ error: "Comment not found" });
}
const comment = await commentService.updateComment(id, content);
await AuditService.logFromRequest(request, {
action: AuditAction.commentUpdate,
category: AuditCategory.admin,
details: `Admin updated comment ${id}`,
});
return comment;
}
);
// Admin: Delete any comment by ID
app.delete<{ Params: { id: string }; Reply: { success: boolean } | { error: string } }>(
"/:id",
{
preValidation: [app.authenticate, adminGuard],
preHandler: [app.csrfProtection],
},
async (request, reply) => {
const { id } = request.params;
const existingComment = await commentService.getCommentById(id);
if (!existingComment) {
return reply.code(404).send({ error: "Comment not found" });
}
await commentService.deleteComment(id);
await AuditService.logFromRequest(request, {
action: AuditAction.commentDelete,
category: AuditCategory.admin,
details: `Admin deleted comment ${id}`,
});
return { success: true };
}
);
};
export default commentsRoutes;
+24
View File
@@ -231,6 +231,30 @@ const usersRoutes: FastifyPluginAsync = async (app) => {
return user;
}
);
app.post<{ Params: { id: string }; Reply: User | { error: string } }>(
"/:id/make-private",
{
preValidation: [app.authenticate, adminGuard],
preHandler: [app.csrfProtection],
},
async (request, reply) => {
const { id } = request.params;
const user = await userService.updateUserSettings(id, { profilePublic: false });
if (!user) {
return reply.code(404).send({ error: "User not found" });
}
await AuditService.logFromRequest(request, {
action: AuditAction.entryUpdate,
category: AuditCategory.admin,
targetUserId: id,
details: `Admin made profile private for user: ${user.username}`,
});
return user;
}
);
};
export default usersRoutes;
@@ -10,6 +10,8 @@ import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { ReportService } from '../../services/report.service';
import { CommentReportService } from '../../services/comment-report.service';
import { CommentsService } from '../../services/comments.service';
import { UserService } from '../../services/user.service';
import { AuthService } from '../../services/auth.service';
import { ToastService } from '../../services/toast.service';
import { ProfileReportWithUsers, CommentReportWithDetails, ReportStatus, ReportReason } from '@library/shared-types';
@@ -1236,6 +1238,8 @@ import { ProfileReportWithUsers, CommentReportWithDetails, ReportStatus, ReportR
export class AdminReportsComponent implements OnInit {
private reportService = inject(ReportService);
private commentReportService = inject(CommentReportService);
private commentsService = inject(CommentsService);
private userService = inject(UserService);
private authService = inject(AuthService);
private toastService = inject(ToastService);
private router = inject(Router);
@@ -1487,40 +1491,66 @@ export class AdminReportsComponent implements OnInit {
editComment(report: CommentReportWithDetails): void {
const commentId = report.reportedComment.id;
const newContent = prompt('Edit comment content:', report.reportedComment.content);
const currentContent = report.reportedComment.rawContent || report.reportedComment.content;
const newContent = prompt('Edit comment content:', currentContent);
if (newContent !== null && newContent.trim() !== '') {
// TODO: Implement comment editing API call
this.toastService.success('Comment edit functionality coming soon');
this.commentsService.adminUpdateComment(commentId, newContent).subscribe({
next: () => {
this.toastService.success('Comment updated successfully');
this.loadReports();
this.closeCommentReviewModal();
},
error: (err) => {
this.toastService.error(err.message ?? 'Failed to update comment');
}
});
}
}
deleteComment(report: CommentReportWithDetails): void {
const commentId = report.reportedComment.id;
const commentAuthor = report.reportedComment.user.username;
const confirmed = confirm(`Are you sure you want to delete this comment by ${commentAuthor}?`);
if (confirmed) {
// TODO: Implement comment deletion API call
this.toastService.success('Comment delete functionality coming soon');
this.commentsService.adminDeleteComment(commentId).subscribe({
next: () => {
this.toastService.success('Comment deleted successfully');
this.loadReports();
this.closeCommentReviewModal();
},
error: (err) => {
this.toastService.error(err.message ?? 'Failed to delete comment');
}
});
}
}
editProfile(report: ProfileReportWithUsers): void {
const userId = report.reportedUser.id;
const username = report.reportedUser.username;
// Navigate to profile edit page or open edit modal
this.router.navigate(['/profile', username]);
// Navigate to profile page using ObjectId
this.router.navigate(['/profile', userId]);
this.toastService.success('Navigate to profile to edit');
}
makeProfilePrivate(report: ProfileReportWithUsers): void {
const userId = report.reportedUser.id;
const username = report.reportedUser.username;
const confirmed = confirm(`Are you sure you want to make ${username}'s profile private?`);
if (confirmed) {
// TODO: Implement make profile private API call
this.toastService.success('Profile privacy functionality coming soon');
this.userService.makeProfilePrivate(userId).subscribe({
next: () => {
this.toastService.success(`${username}'s profile has been made private`);
this.loadReports();
this.closeProfileReviewModal();
},
error: (err) => {
this.toastService.error(err.message ?? 'Failed to update profile privacy');
}
});
}
}
}
@@ -111,4 +111,13 @@ export class CommentsService {
updateCommentOnManga(mangaId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/manga/${mangaId}/comments/${commentId}`, { content });
}
// Admin methods - work with comment ID directly
adminUpdateComment(commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/comments/${commentId}`, { content });
}
adminDeleteComment(commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/comments/${commentId}`);
}
}
@@ -81,4 +81,8 @@ export class UserService {
getProfile(identifier: string): Observable<UserProfileResponse> {
return this.api.get<UserProfileResponse>(`/users/profile/${identifier}`);
}
makeProfilePrivate(userId: string): Observable<User> {
return this.api.post<User>(`/users/${userId}/make-private`, {});
}
}