fix(time-tracking) : return empty collection instead of 404 for active timer endpoint
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,8 +24,9 @@ export function useTimeEntryService() {
|
|||||||
|
|
||||||
async function getActive(): Promise<TimeEntry | null> {
|
async function getActive(): Promise<TimeEntry | null> {
|
||||||
try {
|
try {
|
||||||
const result = await api.get<TimeEntry | null>('/time_entries/active', {}, { toast: false })
|
const data = await api.get<HydraCollection<TimeEntry>>('/time_entries/active', {}, { toast: false })
|
||||||
return result ?? null
|
const members = extractHydraMembers(data)
|
||||||
|
return members[0] ?? null
|
||||||
} catch {
|
} catch {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
new GetCollection(),
|
new GetCollection(),
|
||||||
new Get(
|
new GetCollection(
|
||||||
name: 'active_time_entry',
|
name: 'active_time_entry',
|
||||||
uriTemplate: '/time_entries/active',
|
uriTemplate: '/time_entries/active',
|
||||||
provider: ActiveTimeEntryProvider::class,
|
provider: ActiveTimeEntryProvider::class,
|
||||||
description: 'Get the active timer for the current user',
|
description: 'Get the active timer for the current user',
|
||||||
|
paginationEnabled: false,
|
||||||
),
|
),
|
||||||
new Get(),
|
new Get(),
|
||||||
new Post(security: "is_granted('ROLE_USER')"),
|
new Post(security: "is_granted('ROLE_USER')"),
|
||||||
|
|||||||
@@ -20,14 +20,16 @@ final readonly class ActiveTimeEntryProvider implements ProviderInterface
|
|||||||
private TimeEntryRepository $timeEntryRepository,
|
private TimeEntryRepository $timeEntryRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?TimeEntry
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||||
{
|
{
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->timeEntryRepository->findActiveByUser($user);
|
$entry = $this->timeEntryRepository->findActiveByUser($user);
|
||||||
|
|
||||||
|
return $entry ? [$entry] : [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user