delete backup.

This commit is contained in:
charles-gauthereau
2024-12-31 12:15:18 +01:00
parent ced953467f
commit c5b1437114
2 changed files with 70 additions and 14 deletions
@@ -4,7 +4,47 @@ import {userAction} from "@/safe-actions";
import {z} from "zod";
import {prisma} from "@/prisma";
import {ServerActionResult} from "@/types/action-type";
import {Restoration} from "@prisma/client";
import {Backup, Restoration} from "@prisma/client";
export const deleteBackupAction = userAction
.schema(z.object({
backupId: z.string(),
databaseId: z.string(),
}))
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Backup>> => {
try {
const backupDeleted = await prisma.backup.delete({
where:{
databaseId: parsedInput.databaseId,
id: parsedInput.backupId
}
});
return {
success: true,
value: backupDeleted,
actionSuccess: {
message: "Backup has been successfully deleted.",
messageParams: {message: "success"},
},
};
} catch (error) {
console.error("Error deleting backup:", error);
return {
success: false,
actionError: {
message: "Failed to delete backup.",
status: 500,
cause: error instanceof Error ? error.message : "Unknown error",
messageParams: {message: "Error deleting the backup"},
},
};
}
});
export const createRestorationAction = userAction
@@ -28,7 +68,7 @@ export const createRestorationAction = userAction
value: restoration,
actionSuccess: {
message: "Restoration has been successfully created.",
messageParams: { restorationId: restoration.id },
messageParams: {restorationId: restoration.id},
},
};
} catch (error) {
@@ -39,11 +79,10 @@ export const createRestorationAction = userAction
message: "Failed to create backup.",
status: 500,
cause: error instanceof Error ? error.message : "Unknown error",
messageParams: { message: "Error creating the restoration" },
messageParams: {message: "Error creating the restoration"},
},
};
}
});