add mass delete time entries frontend, closes ST-450

This commit is contained in:
Gregor Vostrak
2024-10-08 00:25:33 +02:00
parent 071895791c
commit 9f2ac70549
4 changed files with 72 additions and 4 deletions

View File

@@ -57,9 +57,7 @@ async function startTimeEntry(
}
function deleteTimeEntries(timeEntries: TimeEntry[]) {
timeEntries.forEach((entry) => {
useTimeEntriesStore().deleteTimeEntry(entry.id);
});
useTimeEntriesStore().deleteTimeEntries(timeEntries);
fetchTimeEntries();
}

View File

@@ -2325,6 +2325,54 @@ Users with the permission `time-entries:view:own` can only use this en
},
],
},
{
method: 'delete',
path: '/v1/organizations/:organization/time-entries',
alias: 'deleteTimeEntries',
requestFormat: 'json',
parameters: [
{
name: 'organization',
type: 'Path',
schema: z.string(),
},
{
name: 'ids',
type: 'Query',
schema: z.array(z.string().uuid()),
},
],
response: z
.object({ success: z.string(), error: z.string() })
.passthrough(),
errors: [
{
status: 401,
description: `Unauthenticated`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 403,
description: `Authorization error`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 404,
description: `Not found`,
schema: z.object({ message: z.string() }).passthrough(),
},
{
status: 422,
description: `Validation error`,
schema: z
.object({
message: z.string(),
errors: z.record(z.array(z.string())),
})
.passthrough(),
},
],
},
{
method: 'put',
path: '/v1/organizations/:organization/time-entries/:timeEntry',

View File

@@ -142,7 +142,7 @@ const expanded = ref(false);
class="opacity-20 hidden sm:flex group-hover:opacity-100"></TimeTrackerStartStop>
<TimeEntryMoreOptionsDropdown
@delete="
deleteTimeEntries(timeEntry.timeEntries)
deleteTimeEntries(timeEntry?.timeEntries ?? [])
"></TimeEntryMoreOptionsDropdown>
</div>
</div>

View File

@@ -168,6 +168,27 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => {
}
}
async function deleteTimeEntries(timeEntries: TimeEntry[]) {
const organizationId = getCurrentOrganizationId();
const timeEntryIds = timeEntries.map((entry) => entry.id);
if (organizationId) {
await handleApiRequestNotifications(
() =>
api.deleteTimeEntries(undefined, {
queries: {
ids: timeEntryIds,
},
params: {
organization: organizationId,
},
}),
'Time entries deleted successfully',
'Failed to delete time entries'
);
await fetchTimeEntries();
}
}
return {
timeEntries,
fetchTimeEntries,
@@ -177,5 +198,6 @@ export const useTimeEntriesStore = defineStore('timeEntries', () => {
fetchMoreTimeEntries,
allTimeEntriesLoaded,
updateTimeEntries,
deleteTimeEntries,
};
});