Files
gridpilot.gg/apps/website/lib/mutations/admin/UpdateUserStatusMutation.ts
2026-01-14 16:28:39 +01:00

34 lines
1.2 KiB
TypeScript

import { AdminService } from '@/lib/services/admin/AdminService';
import { Result } from '@/lib/contracts/Result';
import { MutationError, mapToMutationError } from '@/lib/contracts/mutations/MutationError';
import { Mutation } from '@/lib/contracts/mutations/Mutation';
/**
* UpdateUserStatusMutation
*
* Framework-agnostic mutation for updating user status.
* Called from Server Actions.
*
* Input: { userId: string; status: string }
* Output: Result<void, MutationError>
*
* Pattern: Server Action → Mutation → Service → API Client
*/
export class UpdateUserStatusMutation implements Mutation<{ userId: string; status: string }, void, MutationError> {
async execute(input: { userId: string; status: string }): Promise<Result<void, MutationError>> {
try {
// Manual construction: Service creates its own dependencies
const service = new AdminService();
const result = await service.updateUserStatus(input.userId, input.status);
if (result.isErr()) {
return Result.err(mapToMutationError(result.getError()));
}
return Result.ok(undefined);
} catch (err) {
return Result.err('updateFailed');
}
}
}