Add admin user management API and frontend UI
Backend: - /api/admin/users: GET list, POST create, PUT update, DELETE - Admin users can be added with email, display name, and password - Self-deletion and last-admin deletion are blocked - Admin role auto-assigned on creation Frontend: - AdminUsersTabComponent: list + add/delete admin users - AdminUserService: HTTP client for admin user CRUD - AdminUser interface - 'Admins' tab added to admin dashboard Tests: - 10 new tests for admin user management endpoints - 140 total tests pass (130 original + 10 new)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { AdminUser } from '../interfaces/admin-user';
|
||||
import { getAppConfig } from './app-config.service';
|
||||
|
||||
export interface CreateAdminPayload {
|
||||
email: string;
|
||||
display_name: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UpdateAdminPayload {
|
||||
display_name?: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AdminUserService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${getAppConfig().apiBaseUrl}/api/admin/users`;
|
||||
|
||||
getAdminUsers(): Observable<AdminUser[]> {
|
||||
return this.http.get<AdminUser[]>(this.baseUrl);
|
||||
}
|
||||
|
||||
createAdminUser(payload: CreateAdminPayload): Observable<AdminUser> {
|
||||
return this.http.post<AdminUser>(this.baseUrl, payload);
|
||||
}
|
||||
|
||||
updateAdminUser(id: number, payload: UpdateAdminPayload): Observable<AdminUser> {
|
||||
return this.http.put<AdminUser>(`${this.baseUrl}/${id}`, payload);
|
||||
}
|
||||
|
||||
deleteAdminUser(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user