maintenances: add new actions

This commit is contained in:
Maximilien Carbonne
2024-09-22 15:58:29 +02:00
parent cabaa07384
commit 17ecfa2c66
4 changed files with 53 additions and 3 deletions

View File

@@ -135,5 +135,34 @@
emit("changed");
}
defineExpose({ openCreateModal, openUpdateModal, deleteEntry });
async function complete(maintenanceEntry: MaintenanceEntry) {
const { error } = await api.maintenances.update(maintenanceEntry.id, {
name: maintenanceEntry.name,
completedDate: new Date(Date.now()),
scheduledDate: maintenanceEntry.scheduledDate ?? "null",
description: maintenanceEntry.description,
cost: maintenanceEntry.cost,
});
if (error) {
toast.error(t("maintenances.toast.failed_to_update"));
}
emit("changed");
}
async function completeAndDuplicate(
maintenanceEntry: MaintenanceEntry | MaintenanceEntryWithDetails,
itemId: string
) {
await complete(maintenanceEntry);
entry.id = null;
entry.name = maintenanceEntry.name;
entry.completedDate = null;
entry.scheduledDate = null;
entry.description = maintenanceEntry.description;
entry.cost = maintenanceEntry.cost;
entry.itemId = itemId;
visible.value = true;
}
defineExpose({ openCreateModal, openUpdateModal, deleteEntry, complete, completeAndDuplicate });
</script>