43 lines
1.2 KiB
TypeScript
43 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) {
|
|
const mutation = new UpdateUserStatusMutation();
|
|
const result = await mutation.execute({ userId, status });
|
|
|
|
if (result.isErr()) {
|
|
console.error('updateUserStatus failed:', result.getError());
|
|
throw new Error('Failed to update user status');
|
|
}
|
|
|
|
revalidatePath('/admin/users');
|
|
}
|
|
|
|
/**
|
|
* Delete user
|
|
*/
|
|
export async function deleteUser(userId: string) {
|
|
const mutation = new DeleteUserMutation();
|
|
const result = await mutation.execute({ userId });
|
|
|
|
if (result.isErr()) {
|
|
console.error('deleteUser failed:', result.getError());
|
|
throw new Error('Failed to delete user');
|
|
}
|
|
|
|
revalidatePath('/admin/users');
|
|
} |