Files
gridpilot.gg/apps/website/app/admin/actions.ts
2026-01-12 19:24:59 +01:00

45 lines
1.2 KiB
TypeScript

'use server';
import { UpdateUserStatusMutation } from '@/lib/mutations/admin/UpdateUserStatusMutation';
import { DeleteUserMutation } from '@/lib/mutations/admin/DeleteUserMutation';
import { revalidatePath } from 'next/cache';
/**
* Server actions for admin operations
*
* All write operations must enter through server actions.
* Actions are thin wrappers that handle framework concerns (revalidation).
* Business logic is handled by Mutations.
*/
/**
* Update user status
*/
export async function updateUserStatus(userId: string, status: string): Promise<void> {
try {
const mutation = new UpdateUserStatusMutation();
await mutation.execute({ userId, status });
// Revalidate the users page
revalidatePath('/admin/users');
} catch (error) {
console.error('updateUserStatus failed:', error);
throw new Error('Failed to update user status');
}
}
/**
* Delete user
*/
export async function deleteUser(userId: string): Promise<void> {
try {
const mutation = new DeleteUserMutation();
await mutation.execute({ userId });
// Revalidate the users page
revalidatePath('/admin/users');
} catch (error) {
console.error('deleteUser failed:', error);
throw new Error('Failed to delete user');
}
}