website refactor
This commit is contained in:
45
apps/website/app/admin/actions.ts
Normal file
45
apps/website/app/admin/actions.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
'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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user